Simplify use of keyword symbols
This commit is contained in:
parent
37ff5d388f
commit
59a382122f
58 changed files with 502 additions and 534 deletions
|
@ -64,7 +64,7 @@ use syntax::ptr::P;
|
||||||
use syntax::source_map::{respan, CompilerDesugaringKind, Spanned};
|
use syntax::source_map::{respan, CompilerDesugaringKind, Spanned};
|
||||||
use syntax::source_map::CompilerDesugaringKind::IfTemporary;
|
use syntax::source_map::CompilerDesugaringKind::IfTemporary;
|
||||||
use syntax::std_inject;
|
use syntax::std_inject;
|
||||||
use syntax::symbol::{keywords, Symbol, sym};
|
use syntax::symbol::{kw, sym, Symbol};
|
||||||
use syntax::tokenstream::{TokenStream, TokenTree};
|
use syntax::tokenstream::{TokenStream, TokenTree};
|
||||||
use syntax::parse::token::Token;
|
use syntax::parse::token::Token;
|
||||||
use syntax::visit::{self, Visitor};
|
use syntax::visit::{self, Visitor};
|
||||||
|
@ -927,11 +927,11 @@ impl<'a> LoweringContext<'a> {
|
||||||
hir::LifetimeParamKind::InBand,
|
hir::LifetimeParamKind::InBand,
|
||||||
),
|
),
|
||||||
ParamName::Fresh(_) => (
|
ParamName::Fresh(_) => (
|
||||||
keywords::UnderscoreLifetime.name().as_interned_str(),
|
kw::UnderscoreLifetime.as_interned_str(),
|
||||||
hir::LifetimeParamKind::Elided,
|
hir::LifetimeParamKind::Elided,
|
||||||
),
|
),
|
||||||
ParamName::Error => (
|
ParamName::Error => (
|
||||||
keywords::UnderscoreLifetime.name().as_interned_str(),
|
kw::UnderscoreLifetime.as_interned_str(),
|
||||||
hir::LifetimeParamKind::Error,
|
hir::LifetimeParamKind::Error,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
@ -1415,7 +1415,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
P(hir::Path {
|
P(hir::Path {
|
||||||
res,
|
res,
|
||||||
segments: hir_vec![hir::PathSegment::from_ident(
|
segments: hir_vec![hir::PathSegment::from_ident(
|
||||||
keywords::SelfUpper.ident()
|
Ident::with_empty_ctxt(kw::SelfUpper)
|
||||||
)],
|
)],
|
||||||
span: t.span,
|
span: t.span,
|
||||||
}),
|
}),
|
||||||
|
@ -1614,7 +1614,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
trace!("registering existential type with id {:#?}", exist_ty_id);
|
trace!("registering existential type with id {:#?}", exist_ty_id);
|
||||||
let exist_ty_item = hir::Item {
|
let exist_ty_item = hir::Item {
|
||||||
hir_id: exist_ty_id,
|
hir_id: exist_ty_id,
|
||||||
ident: keywords::Invalid.ident(),
|
ident: Ident::with_empty_ctxt(kw::Invalid),
|
||||||
attrs: Default::default(),
|
attrs: Default::default(),
|
||||||
node: exist_ty_item_kind,
|
node: exist_ty_item_kind,
|
||||||
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
|
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
|
||||||
|
@ -1747,7 +1747,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
|
|
||||||
let (name, kind) = match name {
|
let (name, kind) = match name {
|
||||||
hir::LifetimeName::Underscore => (
|
hir::LifetimeName::Underscore => (
|
||||||
hir::ParamName::Plain(keywords::UnderscoreLifetime.ident()),
|
hir::ParamName::Plain(Ident::with_empty_ctxt(kw::UnderscoreLifetime)),
|
||||||
hir::LifetimeParamKind::Elided,
|
hir::LifetimeParamKind::Elided,
|
||||||
),
|
),
|
||||||
hir::LifetimeName::Param(param_name) => (
|
hir::LifetimeName::Param(param_name) => (
|
||||||
|
@ -2296,7 +2296,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|arg| match arg.pat.node {
|
.map(|arg| match arg.pat.node {
|
||||||
PatKind::Ident(_, ident, _) => ident,
|
PatKind::Ident(_, ident, _) => ident,
|
||||||
_ => Ident::new(keywords::Invalid.name(), arg.pat.span),
|
_ => Ident::new(kw::Invalid, arg.pat.span),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -2585,9 +2585,9 @@ impl<'a> LoweringContext<'a> {
|
||||||
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
|
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
|
||||||
let span = l.ident.span;
|
let span = l.ident.span;
|
||||||
match l.ident {
|
match l.ident {
|
||||||
ident if ident.name == keywords::StaticLifetime.name() =>
|
ident if ident.name == kw::StaticLifetime =>
|
||||||
self.new_named_lifetime(l.id, span, hir::LifetimeName::Static),
|
self.new_named_lifetime(l.id, span, hir::LifetimeName::Static),
|
||||||
ident if ident.name == keywords::UnderscoreLifetime.name() =>
|
ident if ident.name == kw::UnderscoreLifetime =>
|
||||||
match self.anonymous_lifetime_mode {
|
match self.anonymous_lifetime_mode {
|
||||||
AnonymousLifetimeMode::CreateParameter => {
|
AnonymousLifetimeMode::CreateParameter => {
|
||||||
let fresh_name = self.collect_fresh_in_band_lifetime(span);
|
let fresh_name = self.collect_fresh_in_band_lifetime(span);
|
||||||
|
@ -2709,7 +2709,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
// Don't expose `Self` (recovered "keyword used as ident" parse error).
|
// Don't expose `Self` (recovered "keyword used as ident" parse error).
|
||||||
// `rustc::ty` expects `Self` to be only used for a trait's `Self`.
|
// `rustc::ty` expects `Self` to be only used for a trait's `Self`.
|
||||||
// Instead, use `gensym("Self")` to create a distinct name that looks the same.
|
// Instead, use `gensym("Self")` to create a distinct name that looks the same.
|
||||||
let ident = if param.ident.name == keywords::SelfUpper.name() {
|
let ident = if param.ident.name == kw::SelfUpper {
|
||||||
param.ident.gensym()
|
param.ident.gensym()
|
||||||
} else {
|
} else {
|
||||||
param.ident
|
param.ident
|
||||||
|
@ -3325,7 +3325,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
|
|
||||||
// Correctly resolve `self` imports.
|
// Correctly resolve `self` imports.
|
||||||
if path.segments.len() > 1
|
if path.segments.len() > 1
|
||||||
&& path.segments.last().unwrap().ident.name == keywords::SelfLower.name()
|
&& path.segments.last().unwrap().ident.name == kw::SelfLower
|
||||||
{
|
{
|
||||||
let _ = path.segments.pop();
|
let _ = path.segments.pop();
|
||||||
if rename.is_none() {
|
if rename.is_none() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::session::CrateDisambiguator;
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::Mark;
|
||||||
use syntax::visit;
|
use syntax::visit;
|
||||||
use syntax::symbol::keywords;
|
use syntax::symbol::kw;
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
use syntax::parse::token::{self, Token};
|
use syntax::parse::token::{self, Token};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
@ -138,7 +138,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
||||||
// information we encapsulate into, the better
|
// information we encapsulate into, the better
|
||||||
let def_data = match i.node {
|
let def_data = match i.node {
|
||||||
ItemKind::Impl(..) => DefPathData::Impl,
|
ItemKind::Impl(..) => DefPathData::Impl,
|
||||||
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
|
ItemKind::Mod(..) if i.ident == Ident::with_empty_ctxt(kw::Invalid) => {
|
||||||
return visit::walk_item(self, i);
|
return visit::walk_item(self, i);
|
||||||
}
|
}
|
||||||
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
|
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
|
||||||
|
|
|
@ -519,7 +519,7 @@ impl<'hir> Map<'hir> {
|
||||||
pub fn ty_param_name(&self, id: HirId) -> Name {
|
pub fn ty_param_name(&self, id: HirId) -> Name {
|
||||||
match self.get_by_hir_id(id) {
|
match self.get_by_hir_id(id) {
|
||||||
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
|
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
|
||||||
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => keywords::SelfUpper.name(),
|
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => kw::SelfUpper,
|
||||||
Node::GenericParam(param) => param.name.ident().name,
|
Node::GenericParam(param) => param.name.ident().name,
|
||||||
_ => bug!("ty_param_name: {} not a type parameter", self.hir_to_string(id)),
|
_ => bug!("ty_param_name: {} not a type parameter", self.hir_to_string(id)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
|
||||||
use syntax::attr::{InlineAttr, OptimizeAttr};
|
use syntax::attr::{InlineAttr, OptimizeAttr};
|
||||||
use syntax::ext::hygiene::SyntaxContext;
|
use syntax::ext::hygiene::SyntaxContext;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::{Symbol, keywords};
|
use syntax::symbol::{Symbol, kw};
|
||||||
use syntax::tokenstream::TokenStream;
|
use syntax::tokenstream::TokenStream;
|
||||||
use syntax::util::parser::ExprPrecedence;
|
use syntax::util::parser::ExprPrecedence;
|
||||||
use crate::ty::AdtKind;
|
use crate::ty::AdtKind;
|
||||||
|
@ -160,7 +160,7 @@ pub struct Lifetime {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
|
||||||
/// Either "`'a`", referring to a named lifetime definition,
|
/// Either "`'a`", referring to a named lifetime definition,
|
||||||
/// or "``" (i.e., `keywords::Invalid`), for elision placeholders.
|
/// or "``" (i.e., `kw::Invalid`), for elision placeholders.
|
||||||
///
|
///
|
||||||
/// HIR lowering inserts these placeholders in type paths that
|
/// HIR lowering inserts these placeholders in type paths that
|
||||||
/// refer to type definitions needing lifetime parameters,
|
/// refer to type definitions needing lifetime parameters,
|
||||||
|
@ -199,7 +199,8 @@ impl ParamName {
|
||||||
pub fn ident(&self) -> Ident {
|
pub fn ident(&self) -> Ident {
|
||||||
match *self {
|
match *self {
|
||||||
ParamName::Plain(ident) => ident,
|
ParamName::Plain(ident) => ident,
|
||||||
ParamName::Error | ParamName::Fresh(_) => keywords::UnderscoreLifetime.ident(),
|
ParamName::Fresh(_) |
|
||||||
|
ParamName::Error => Ident::with_empty_ctxt(kw::UnderscoreLifetime),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,10 +234,10 @@ pub enum LifetimeName {
|
||||||
impl LifetimeName {
|
impl LifetimeName {
|
||||||
pub fn ident(&self) -> Ident {
|
pub fn ident(&self) -> Ident {
|
||||||
match *self {
|
match *self {
|
||||||
LifetimeName::Implicit => keywords::Invalid.ident(),
|
LifetimeName::Implicit => Ident::with_empty_ctxt(kw::Invalid),
|
||||||
LifetimeName::Error => keywords::Invalid.ident(),
|
LifetimeName::Error => Ident::with_empty_ctxt(kw::Invalid),
|
||||||
LifetimeName::Underscore => keywords::UnderscoreLifetime.ident(),
|
LifetimeName::Underscore => Ident::with_empty_ctxt(kw::UnderscoreLifetime),
|
||||||
LifetimeName::Static => keywords::StaticLifetime.ident(),
|
LifetimeName::Static => Ident::with_empty_ctxt(kw::StaticLifetime),
|
||||||
LifetimeName::Param(param_name) => param_name.ident(),
|
LifetimeName::Param(param_name) => param_name.ident(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,7 +306,7 @@ pub struct Path {
|
||||||
|
|
||||||
impl Path {
|
impl Path {
|
||||||
pub fn is_global(&self) -> bool {
|
pub fn is_global(&self) -> bool {
|
||||||
!self.segments.is_empty() && self.segments[0].ident.name == keywords::PathRoot.name()
|
!self.segments.is_empty() && self.segments[0].ident.name == kw::PathRoot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use syntax::print::pp::{self, Breaks};
|
||||||
use syntax::print::pp::Breaks::{Consistent, Inconsistent};
|
use syntax::print::pp::Breaks::{Consistent, Inconsistent};
|
||||||
use syntax::print::pprust::{self, PrintState};
|
use syntax::print::pprust::{self, PrintState};
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::keywords;
|
use syntax::symbol::kw;
|
||||||
use syntax::util::parser::{self, AssocOp, Fixity};
|
use syntax::util::parser::{self, AssocOp, Fixity};
|
||||||
use syntax_pos::{self, BytePos, FileName};
|
use syntax_pos::{self, BytePos, FileName};
|
||||||
|
|
||||||
|
@ -798,7 +798,7 @@ impl<'a> State<'a> {
|
||||||
hir::VisibilityKind::Restricted { ref path, .. } => {
|
hir::VisibilityKind::Restricted { ref path, .. } => {
|
||||||
self.s.word("pub(")?;
|
self.s.word("pub(")?;
|
||||||
if path.segments.len() == 1 &&
|
if path.segments.len() == 1 &&
|
||||||
path.segments[0].ident.name == keywords::Super.name() {
|
path.segments[0].ident.name == kw::Super {
|
||||||
// Special case: `super` can print like `pub(super)`.
|
// Special case: `super` can print like `pub(super)`.
|
||||||
self.s.word("super")?;
|
self.s.word("super")?;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1559,7 +1559,7 @@ impl<'a> State<'a> {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
self.s.word("::")?
|
self.s.word("::")?
|
||||||
}
|
}
|
||||||
if segment.ident.name != keywords::PathRoot.name() {
|
if segment.ident.name != kw::PathRoot {
|
||||||
self.print_ident(segment.ident)?;
|
self.print_ident(segment.ident)?;
|
||||||
segment.with_generic_args(|generic_args| {
|
segment.with_generic_args(|generic_args| {
|
||||||
self.print_generic_args(generic_args, segment.infer_types,
|
self.print_generic_args(generic_args, segment.infer_types,
|
||||||
|
@ -1572,7 +1572,7 @@ impl<'a> State<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_path_segment(&mut self, segment: &hir::PathSegment) -> io::Result<()> {
|
pub fn print_path_segment(&mut self, segment: &hir::PathSegment) -> io::Result<()> {
|
||||||
if segment.ident.name != keywords::PathRoot.name() {
|
if segment.ident.name != kw::PathRoot {
|
||||||
self.print_ident(segment.ident)?;
|
self.print_ident(segment.ident)?;
|
||||||
segment.with_generic_args(|generic_args| {
|
segment.with_generic_args(|generic_args| {
|
||||||
self.print_generic_args(generic_args, segment.infer_types, false)
|
self.print_generic_args(generic_args, segment.infer_types, false)
|
||||||
|
@ -1599,7 +1599,7 @@ impl<'a> State<'a> {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
self.s.word("::")?
|
self.s.word("::")?
|
||||||
}
|
}
|
||||||
if segment.ident.name != keywords::PathRoot.name() {
|
if segment.ident.name != kw::PathRoot {
|
||||||
self.print_ident(segment.ident)?;
|
self.print_ident(segment.ident)?;
|
||||||
segment.with_generic_args(|generic_args| {
|
segment.with_generic_args(|generic_args| {
|
||||||
self.print_generic_args(generic_args,
|
self.print_generic_args(generic_args,
|
||||||
|
|
|
@ -112,7 +112,7 @@ use std::io;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use syntax::ast::{self, NodeId};
|
use syntax::ast::{self, NodeId};
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::{keywords, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
use crate::hir;
|
use crate::hir;
|
||||||
|
@ -1552,7 +1552,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
let sp = ident.span;
|
let sp = ident.span;
|
||||||
let var = self.variable(hir_id, sp);
|
let var = self.variable(hir_id, sp);
|
||||||
// Ignore unused self.
|
// Ignore unused self.
|
||||||
if ident.name != keywords::SelfLower.name() {
|
if ident.name != kw::SelfLower {
|
||||||
if !self.warn_about_unused(vec![sp], hir_id, entry_ln, var) {
|
if !self.warn_about_unused(vec![sp], hir_id, entry_ln, var) {
|
||||||
if self.live_on_entry(entry_ln, var).is_none() {
|
if self.live_on_entry(entry_ln, var).is_none() {
|
||||||
self.report_dead_assign(hir_id, sp, var, true);
|
self.report_dead_assign(hir_id, sp, var, true);
|
||||||
|
|
|
@ -23,7 +23,7 @@ use std::mem::replace;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::{keywords, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
|
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||||
|
@ -711,7 +711,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
GenericParamKind::Lifetime { .. } => {
|
GenericParamKind::Lifetime { .. } => {
|
||||||
let (name, reg) = Region::early(&self.tcx.hir(), &mut index, ¶m);
|
let (name, reg) = Region::early(&self.tcx.hir(), &mut index, ¶m);
|
||||||
if let hir::ParamName::Plain(param_name) = name {
|
if let hir::ParamName::Plain(param_name) = name {
|
||||||
if param_name.name == keywords::UnderscoreLifetime.name() {
|
if param_name.name == kw::UnderscoreLifetime {
|
||||||
// Pick the elided lifetime "definition" if one exists
|
// Pick the elided lifetime "definition" if one exists
|
||||||
// and use it to make an elision scope.
|
// and use it to make an elision scope.
|
||||||
elision = Some(reg);
|
elision = Some(reg);
|
||||||
|
@ -1602,7 +1602,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
} {
|
} {
|
||||||
debug!("id = {:?} span = {:?} name = {:?}", id, span, name);
|
debug!("id = {:?} span = {:?} name = {:?}", id, span, name);
|
||||||
|
|
||||||
if name == keywords::UnderscoreLifetime.ident() {
|
if name == ast::Ident::with_empty_ctxt(kw::UnderscoreLifetime) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2525,8 +2525,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
for (i, (lifetime_i, lifetime_i_name)) in lifetimes.iter().enumerate() {
|
for (i, (lifetime_i, lifetime_i_name)) in lifetimes.iter().enumerate() {
|
||||||
if let hir::ParamName::Plain(_) = lifetime_i_name {
|
if let hir::ParamName::Plain(_) = lifetime_i_name {
|
||||||
let name = lifetime_i_name.ident().name;
|
let name = lifetime_i_name.ident().name;
|
||||||
if name == keywords::UnderscoreLifetime.name()
|
if name == kw::UnderscoreLifetime
|
||||||
|| name == keywords::StaticLifetime.name()
|
|| name == kw::StaticLifetime
|
||||||
{
|
{
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self.tcx.sess,
|
self.tcx.sess,
|
||||||
|
|
|
@ -74,7 +74,7 @@ use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::source_map::MultiSpan;
|
use syntax::source_map::MultiSpan;
|
||||||
use syntax::feature_gate;
|
use syntax::feature_gate;
|
||||||
use syntax::symbol::{Symbol, keywords, InternedString, sym};
|
use syntax::symbol::{Symbol, InternedString, kw, sym};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
use crate::hir;
|
use crate::hir;
|
||||||
|
@ -2735,7 +2735,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_self_type(self) -> Ty<'tcx> {
|
pub fn mk_self_type(self) -> Ty<'tcx> {
|
||||||
self.mk_ty_param(0, keywords::SelfUpper.name().as_interned_str())
|
self.mk_ty_param(0, kw::SelfUpper.as_interned_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> Kind<'tcx> {
|
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> Kind<'tcx> {
|
||||||
|
|
|
@ -47,7 +47,7 @@ use std::ops::Range;
|
||||||
use syntax::ast::{self, Name, Ident, NodeId};
|
use syntax::ast::{self, Name, Ident, NodeId};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::Mark;
|
||||||
use syntax::symbol::{keywords, sym, Symbol, LocalInternedString, InternedString};
|
use syntax::symbol::{kw, sym, Symbol, LocalInternedString, InternedString};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
use smallvec;
|
use smallvec;
|
||||||
|
@ -835,7 +835,7 @@ impl ty::EarlyBoundRegion {
|
||||||
/// Does this early bound region have a name? Early bound regions normally
|
/// Does this early bound region have a name? Early bound regions normally
|
||||||
/// always have names except when using anonymous lifetimes (`'_`).
|
/// always have names except when using anonymous lifetimes (`'_`).
|
||||||
pub fn has_name(&self) -> bool {
|
pub fn has_name(&self) -> bool {
|
||||||
self.name != keywords::UnderscoreLifetime.name().as_interned_str()
|
self.name != kw::UnderscoreLifetime.as_interned_str()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -980,7 +980,7 @@ impl<F: fmt::Write> Printer<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F> {
|
||||||
if self.tcx.sess.rust_2018() {
|
if self.tcx.sess.rust_2018() {
|
||||||
// We add the `crate::` keyword on Rust 2018, only when desired.
|
// We add the `crate::` keyword on Rust 2018, only when desired.
|
||||||
if SHOULD_PREFIX_WITH_CRATE.with(|flag| flag.get()) {
|
if SHOULD_PREFIX_WITH_CRATE.with(|flag| flag.get()) {
|
||||||
write!(self, "{}", keywords::Crate.name())?;
|
write!(self, "{}", kw::Crate)?;
|
||||||
self.empty_path = false;
|
self.empty_path = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ use std::marker::PhantomData;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use rustc_target::spec::abi;
|
use rustc_target::spec::abi;
|
||||||
use syntax::ast::{self, Ident};
|
use syntax::ast::{self, Ident};
|
||||||
use syntax::symbol::{keywords, InternedString};
|
use syntax::symbol::{kw, InternedString};
|
||||||
|
|
||||||
use serialize;
|
use serialize;
|
||||||
use self::InferTy::*;
|
use self::InferTy::*;
|
||||||
|
@ -1121,7 +1121,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn for_self() -> ParamTy {
|
pub fn for_self() -> ParamTy {
|
||||||
ParamTy::new(0, keywords::SelfUpper.name().as_interned_str())
|
ParamTy::new(0, kw::SelfUpper.as_interned_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn for_def(def: &ty::GenericParamDef) -> ParamTy {
|
pub fn for_def(def: &ty::GenericParamDef) -> ParamTy {
|
||||||
|
@ -1136,7 +1136,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
|
||||||
// FIXME(#50125): Ignoring `Self` with `index != 0` might lead to weird behavior elsewhere,
|
// FIXME(#50125): Ignoring `Self` with `index != 0` might lead to weird behavior elsewhere,
|
||||||
// but this should only be possible when using `-Z continue-parse-after-error` like
|
// but this should only be possible when using `-Z continue-parse-after-error` like
|
||||||
// `compile-fail/issue-36638.rs`.
|
// `compile-fail/issue-36638.rs`.
|
||||||
self.name.as_symbol() == keywords::SelfUpper.name() && self.index == 0
|
self.name.as_symbol() == kw::SelfUpper && self.index == 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::debuginfo::{self, VariableAccess, VariableKind, FunctionDebugContext}
|
||||||
use crate::traits::*;
|
use crate::traits::*;
|
||||||
|
|
||||||
use syntax_pos::{DUMMY_SP, NO_EXPANSION, BytePos, Span};
|
use syntax_pos::{DUMMY_SP, NO_EXPANSION, BytePos, Span};
|
||||||
use syntax::symbol::keywords;
|
use syntax::symbol::kw;
|
||||||
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
|
||||||
};
|
};
|
||||||
bx.declare_local(
|
bx.declare_local(
|
||||||
&fx.debug_context,
|
&fx.debug_context,
|
||||||
arg_decl.name.unwrap_or(keywords::Invalid.name()),
|
arg_decl.name.unwrap_or(kw::Invalid),
|
||||||
arg_ty, scope,
|
arg_ty, scope,
|
||||||
variable_access,
|
variable_access,
|
||||||
VariableKind::ArgumentVariable(arg_index + 1),
|
VariableKind::ArgumentVariable(arg_index + 1),
|
||||||
|
@ -613,7 +613,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
|
||||||
|
|
||||||
bx.declare_local(
|
bx.declare_local(
|
||||||
&fx.debug_context,
|
&fx.debug_context,
|
||||||
arg_decl.name.unwrap_or(keywords::Invalid.name()),
|
arg_decl.name.unwrap_or(kw::Invalid),
|
||||||
arg.layout.ty,
|
arg.layout.ty,
|
||||||
scope,
|
scope,
|
||||||
variable_access,
|
variable_access,
|
||||||
|
|
|
@ -42,7 +42,7 @@ use syntax::edition::Edition;
|
||||||
use syntax::feature_gate::{AttributeGate, AttributeTemplate, AttributeType};
|
use syntax::feature_gate::{AttributeGate, AttributeTemplate, AttributeType};
|
||||||
use syntax::feature_gate::{Stability, deprecated_attributes};
|
use syntax::feature_gate::{Stability, deprecated_attributes};
|
||||||
use syntax_pos::{BytePos, Span, SyntaxContext};
|
use syntax_pos::{BytePos, Span, SyntaxContext};
|
||||||
use syntax::symbol::{Symbol, keywords, sym};
|
use syntax::symbol::{Symbol, kw, sym};
|
||||||
use syntax::errors::{Applicability, DiagnosticBuilder};
|
use syntax::errors::{Applicability, DiagnosticBuilder};
|
||||||
use syntax::print::pprust::expr_to_string;
|
use syntax::print::pprust::expr_to_string;
|
||||||
use syntax::visit::FnKind;
|
use syntax::visit::FnKind;
|
||||||
|
@ -607,7 +607,7 @@ impl EarlyLintPass for AnonymousParameters {
|
||||||
for arg in sig.decl.inputs.iter() {
|
for arg in sig.decl.inputs.iter() {
|
||||||
match arg.pat.node {
|
match arg.pat.node {
|
||||||
ast::PatKind::Ident(_, ident, None) => {
|
ast::PatKind::Ident(_, ident, None) => {
|
||||||
if ident.name == keywords::Invalid.name() {
|
if ident.name == kw::Invalid {
|
||||||
let ty_snip = cx
|
let ty_snip = cx
|
||||||
.sess
|
.sess
|
||||||
.source_map()
|
.source_map()
|
||||||
|
|
|
@ -12,7 +12,7 @@ use syntax::attr;
|
||||||
use syntax::errors::Applicability;
|
use syntax::errors::Applicability;
|
||||||
use syntax::feature_gate::{AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
|
use syntax::feature_gate::{AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
|
||||||
use syntax::print::pprust;
|
use syntax::print::pprust;
|
||||||
use syntax::symbol::{keywords, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
use syntax::util::parser;
|
use syntax::util::parser;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
@ -455,7 +455,7 @@ impl UnusedImportBraces {
|
||||||
match items[0].0.kind {
|
match items[0].0.kind {
|
||||||
ast::UseTreeKind::Simple(rename, ..) => {
|
ast::UseTreeKind::Simple(rename, ..) => {
|
||||||
let orig_ident = items[0].0.prefix.segments.last().unwrap().ident;
|
let orig_ident = items[0].0.prefix.segments.last().unwrap().ident;
|
||||||
if orig_ident.name == keywords::SelfLower.name() {
|
if orig_ident.name == kw::SelfLower {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
node_ident = rename.unwrap_or(orig_ident);
|
node_ident = rename.unwrap_or(orig_ident);
|
||||||
|
|
|
@ -97,7 +97,6 @@ pub fn symbols(input: TokenStream) -> TokenStream {
|
||||||
let mut keyword_stream = quote! {};
|
let mut keyword_stream = quote! {};
|
||||||
let mut symbols_stream = quote! {};
|
let mut symbols_stream = quote! {};
|
||||||
let mut prefill_stream = quote! {};
|
let mut prefill_stream = quote! {};
|
||||||
let mut from_str_stream = quote! {};
|
|
||||||
let mut counter = 0u32;
|
let mut counter = 0u32;
|
||||||
let mut keys = HashSet::<String>::new();
|
let mut keys = HashSet::<String>::new();
|
||||||
|
|
||||||
|
@ -115,12 +114,7 @@ pub fn symbols(input: TokenStream) -> TokenStream {
|
||||||
#value,
|
#value,
|
||||||
});
|
});
|
||||||
keyword_stream.extend(quote! {
|
keyword_stream.extend(quote! {
|
||||||
pub const #name: Keyword = Keyword {
|
pub const #name: Symbol = Symbol::new(#counter);
|
||||||
ident: Ident::with_empty_ctxt(super::Symbol::new(#counter))
|
|
||||||
};
|
|
||||||
});
|
|
||||||
from_str_stream.extend(quote! {
|
|
||||||
#value => Ok(#name),
|
|
||||||
});
|
});
|
||||||
counter += 1;
|
counter += 1;
|
||||||
}
|
}
|
||||||
|
@ -145,17 +139,6 @@ pub fn symbols(input: TokenStream) -> TokenStream {
|
||||||
macro_rules! keywords {
|
macro_rules! keywords {
|
||||||
() => {
|
() => {
|
||||||
#keyword_stream
|
#keyword_stream
|
||||||
|
|
||||||
impl std::str::FromStr for Keyword {
|
|
||||||
type Err = ();
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
|
||||||
match s {
|
|
||||||
#from_str_stream
|
|
||||||
_ => Err(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ use std::u32;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::source_map::Spanned;
|
use syntax::source_map::Spanned;
|
||||||
use syntax::symbol::{keywords, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax_pos::{self, FileName, SourceFile, Span};
|
use syntax_pos::{self, FileName, SourceFile, Span};
|
||||||
use log::{debug, trace};
|
use log::{debug, trace};
|
||||||
|
|
||||||
|
@ -1042,7 +1042,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
||||||
self.lazy_seq(body.arguments.iter().map(|arg| {
|
self.lazy_seq(body.arguments.iter().map(|arg| {
|
||||||
match arg.pat.node {
|
match arg.pat.node {
|
||||||
PatKind::Binding(_, _, ident, _) => ident.name,
|
PatKind::Binding(_, _, ident, _) => ident.name,
|
||||||
_ => keywords::Invalid.name(),
|
_ => kw::Invalid,
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,7 +8,7 @@ use rustc::mir::{Terminator, TerminatorKind};
|
||||||
use rustc::ty::{self, Const, DefIdTree, Ty, TyS, TyCtxt};
|
use rustc::ty::{self, Const, DefIdTree, Ty, TyS, TyCtxt};
|
||||||
use rustc_data_structures::indexed_vec::Idx;
|
use rustc_data_structures::indexed_vec::Idx;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use syntax_pos::symbol::keywords;
|
use syntax_pos::symbol::kw;
|
||||||
|
|
||||||
use crate::dataflow::move_paths::InitLocation;
|
use crate::dataflow::move_paths::InitLocation;
|
||||||
use crate::borrow_check::MirBorrowckCtxt;
|
use crate::borrow_check::MirBorrowckCtxt;
|
||||||
|
@ -256,7 +256,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
|
||||||
// Deliberately fall into this case for all implicit self types,
|
// Deliberately fall into this case for all implicit self types,
|
||||||
// so that we don't fall in to the next case with them.
|
// so that we don't fall in to the next case with them.
|
||||||
*kind == mir::ImplicitSelfKind::MutRef
|
*kind == mir::ImplicitSelfKind::MutRef
|
||||||
} else if Some(keywords::SelfLower.name()) == local_decl.name {
|
} else if Some(kw::SelfLower) == local_decl.name {
|
||||||
// Otherwise, check if the name is the self kewyord - in which case
|
// Otherwise, check if the name is the self kewyord - in which case
|
||||||
// we have an explicit self. Do the same thing in this case and check
|
// we have an explicit self. Do the same thing in this case and check
|
||||||
// for a `self: &mut Self` to suggest removing the `&mut`.
|
// for a `self: &mut Self` to suggest removing the `&mut`.
|
||||||
|
|
|
@ -15,7 +15,7 @@ use rustc_data_structures::indexed_vec::IndexVec;
|
||||||
use rustc_errors::{Diagnostic, DiagnosticBuilder};
|
use rustc_errors::{Diagnostic, DiagnosticBuilder};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use syntax::errors::Applicability;
|
use syntax::errors::Applicability;
|
||||||
use syntax::symbol::keywords;
|
use syntax::symbol::kw;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
mod region_name;
|
mod region_name;
|
||||||
|
@ -631,7 +631,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
"add_static_impl_trait_suggestion: has_static_predicate={:?}",
|
"add_static_impl_trait_suggestion: has_static_predicate={:?}",
|
||||||
has_static_predicate
|
has_static_predicate
|
||||||
);
|
);
|
||||||
let static_str = keywords::StaticLifetime.name();
|
let static_str = kw::StaticLifetime;
|
||||||
// If there is a static predicate, then the only sensible suggestion is to replace
|
// If there is a static predicate, then the only sensible suggestion is to replace
|
||||||
// fr with `'static`.
|
// fr with `'static`.
|
||||||
if has_static_predicate {
|
if has_static_predicate {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use rustc::ty::subst::{SubstsRef, UnpackedKind};
|
||||||
use rustc::ty::{self, RegionKind, RegionVid, Ty, TyCtxt};
|
use rustc::ty::{self, RegionKind, RegionVid, Ty, TyCtxt};
|
||||||
use rustc::ty::print::RegionHighlightMode;
|
use rustc::ty::print::RegionHighlightMode;
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::DiagnosticBuilder;
|
||||||
use syntax::symbol::keywords;
|
use syntax::symbol::kw;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use syntax_pos::symbol::InternedString;
|
use syntax_pos::symbol::InternedString;
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::ReStatic => Some(RegionName {
|
ty::ReStatic => Some(RegionName {
|
||||||
name: keywords::StaticLifetime.name().as_interned_str(),
|
name: kw::StaticLifetime.as_interned_str(),
|
||||||
source: RegionNameSource::Static
|
source: RegionNameSource::Static
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ use std::mem;
|
||||||
use std::u32;
|
use std::u32;
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use syntax::attr::{self, UnwindAttr};
|
use syntax::attr::{self, UnwindAttr};
|
||||||
use syntax::symbol::keywords;
|
use syntax::symbol::kw;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
use super::lints;
|
use super::lints;
|
||||||
|
@ -660,7 +660,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
|
||||||
ty::UpvarCapture::ByRef(..) => true,
|
ty::UpvarCapture::ByRef(..) => true,
|
||||||
};
|
};
|
||||||
let mut debuginfo = UpvarDebuginfo {
|
let mut debuginfo = UpvarDebuginfo {
|
||||||
debug_name: keywords::Invalid.name(),
|
debug_name: kw::Invalid,
|
||||||
by_ref,
|
by_ref,
|
||||||
};
|
};
|
||||||
let mut mutability = Mutability::Not;
|
let mut mutability = Mutability::Not;
|
||||||
|
|
|
@ -15,7 +15,7 @@ use rustc_data_structures::fx::FxHashMap;
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::source_map::Spanned;
|
use syntax::source_map::Spanned;
|
||||||
use syntax::symbol::{keywords, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::visit::{self, Visitor};
|
use syntax::visit::{self, Visitor};
|
||||||
use syntax::{span_err, struct_span_err, walk_list};
|
use syntax::{span_err, struct_span_err, walk_list};
|
||||||
|
@ -177,9 +177,9 @@ impl<'a> AstValidator<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_lifetime(&self, ident: Ident) {
|
fn check_lifetime(&self, ident: Ident) {
|
||||||
let valid_names = [keywords::UnderscoreLifetime.name(),
|
let valid_names = [kw::UnderscoreLifetime,
|
||||||
keywords::StaticLifetime.name(),
|
kw::StaticLifetime,
|
||||||
keywords::Invalid.name()];
|
kw::Invalid];
|
||||||
if !valid_names.contains(&ident.name) && ident.without_first_quote().is_reserved() {
|
if !valid_names.contains(&ident.name) && ident.without_first_quote().is_reserved() {
|
||||||
self.err_handler().span_err(ident.span, "lifetimes cannot use keyword names");
|
self.err_handler().span_err(ident.span, "lifetimes cannot use keyword names");
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use syntax::ast::Ident;
|
use syntax::ast::Ident;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::symbol::{keywords, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
use std::{cmp, fmt, mem};
|
use std::{cmp, fmt, mem};
|
||||||
|
@ -844,7 +844,7 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> {
|
||||||
span: Span, // span of the field pattern, e.g., `x: 0`
|
span: Span, // span of the field pattern, e.g., `x: 0`
|
||||||
def: &'tcx ty::AdtDef, // definition of the struct or enum
|
def: &'tcx ty::AdtDef, // definition of the struct or enum
|
||||||
field: &'tcx ty::FieldDef) { // definition of the field
|
field: &'tcx ty::FieldDef) { // definition of the field
|
||||||
let ident = Ident::new(keywords::Invalid.name(), use_ctxt);
|
let ident = Ident::new(kw::Invalid, use_ctxt);
|
||||||
let current_hir = self.current_item;
|
let current_hir = self.current_item;
|
||||||
let def_id = self.tcx.adjust_ident(ident, def.did, current_hir).1;
|
let def_id = self.tcx.adjust_ident(ident, def.did, current_hir).1;
|
||||||
if !def.is_enum() && !field.vis.is_accessible_from(def_id, self.tcx) {
|
if !def.is_enum() && !field.vis.is_accessible_from(def_id, self.tcx) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ use syntax::feature_gate::is_builtin_attr;
|
||||||
use syntax::parse::token::{self, Token};
|
use syntax::parse::token::{self, Token};
|
||||||
use syntax::span_err;
|
use syntax::span_err;
|
||||||
use syntax::std_inject::injected_crate_name;
|
use syntax::std_inject::injected_crate_name;
|
||||||
use syntax::symbol::{keywords, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax::visit::{self, Visitor};
|
use syntax::visit::{self, Visitor};
|
||||||
|
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
|
@ -143,7 +143,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}.map(|ctxt| Segment::from_ident(Ident::new(
|
}.map(|ctxt| Segment::from_ident(Ident::new(
|
||||||
keywords::PathRoot.name(), use_tree.prefix.span.shrink_to_lo().with_ctxt(ctxt)
|
kw::PathRoot, use_tree.prefix.span.shrink_to_lo().with_ctxt(ctxt)
|
||||||
)));
|
)));
|
||||||
|
|
||||||
let prefix = crate_root.into_iter().chain(prefix_iter).collect::<Vec<_>>();
|
let prefix = crate_root.into_iter().chain(prefix_iter).collect::<Vec<_>>();
|
||||||
|
@ -151,7 +151,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
let empty_for_self = |prefix: &[Segment]| {
|
let empty_for_self = |prefix: &[Segment]| {
|
||||||
prefix.is_empty() ||
|
prefix.is_empty() ||
|
||||||
prefix.len() == 1 && prefix[0].ident.name == keywords::PathRoot.name()
|
prefix.len() == 1 && prefix[0].ident.name == kw::PathRoot
|
||||||
};
|
};
|
||||||
match use_tree.kind {
|
match use_tree.kind {
|
||||||
ast::UseTreeKind::Simple(rename, ..) => {
|
ast::UseTreeKind::Simple(rename, ..) => {
|
||||||
|
@ -162,7 +162,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
if nested {
|
if nested {
|
||||||
// Correctly handle `self`
|
// Correctly handle `self`
|
||||||
if source.ident.name == keywords::SelfLower.name() {
|
if source.ident.name == kw::SelfLower {
|
||||||
type_ns_only = true;
|
type_ns_only = true;
|
||||||
|
|
||||||
if empty_for_self(&module_path) {
|
if empty_for_self(&module_path) {
|
||||||
|
@ -183,14 +183,14 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Disallow `self`
|
// Disallow `self`
|
||||||
if source.ident.name == keywords::SelfLower.name() {
|
if source.ident.name == kw::SelfLower {
|
||||||
resolve_error(self,
|
resolve_error(self,
|
||||||
use_tree.span,
|
use_tree.span,
|
||||||
ResolutionError::SelfImportsOnlyAllowedWithin);
|
ResolutionError::SelfImportsOnlyAllowedWithin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disallow `use $crate;`
|
// Disallow `use $crate;`
|
||||||
if source.ident.name == keywords::DollarCrate.name() && module_path.is_empty() {
|
if source.ident.name == kw::DollarCrate && module_path.is_empty() {
|
||||||
let crate_root = self.resolve_crate_root(source.ident);
|
let crate_root = self.resolve_crate_root(source.ident);
|
||||||
let crate_name = match crate_root.kind {
|
let crate_name = match crate_root.kind {
|
||||||
ModuleKind::Def(.., name) => name,
|
ModuleKind::Def(.., name) => name,
|
||||||
|
@ -199,11 +199,11 @@ impl<'a> Resolver<'a> {
|
||||||
// HACK(eddyb) unclear how good this is, but keeping `$crate`
|
// HACK(eddyb) unclear how good this is, but keeping `$crate`
|
||||||
// in `source` breaks `src/test/compile-fail/import-crate-var.rs`,
|
// in `source` breaks `src/test/compile-fail/import-crate-var.rs`,
|
||||||
// while the current crate doesn't have a valid `crate_name`.
|
// while the current crate doesn't have a valid `crate_name`.
|
||||||
if crate_name != keywords::Invalid.name() {
|
if crate_name != kw::Invalid {
|
||||||
// `crate_name` should not be interpreted as relative.
|
// `crate_name` should not be interpreted as relative.
|
||||||
module_path.push(Segment {
|
module_path.push(Segment {
|
||||||
ident: Ident {
|
ident: Ident {
|
||||||
name: keywords::PathRoot.name(),
|
name: kw::PathRoot,
|
||||||
span: source.ident.span,
|
span: source.ident.span,
|
||||||
},
|
},
|
||||||
id: Some(self.session.next_node_id()),
|
id: Some(self.session.next_node_id()),
|
||||||
|
@ -221,7 +221,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ident.name == keywords::Crate.name() {
|
if ident.name == kw::Crate {
|
||||||
self.session.span_err(ident.span,
|
self.session.span_err(ident.span,
|
||||||
"crate root imports need to be explicitly named: \
|
"crate root imports need to be explicitly named: \
|
||||||
`use crate as name;`");
|
`use crate as name;`");
|
||||||
|
@ -276,7 +276,7 @@ impl<'a> Resolver<'a> {
|
||||||
// Ensure there is at most one `self` in the list
|
// Ensure there is at most one `self` in the list
|
||||||
let self_spans = items.iter().filter_map(|&(ref use_tree, _)| {
|
let self_spans = items.iter().filter_map(|&(ref use_tree, _)| {
|
||||||
if let ast::UseTreeKind::Simple(..) = use_tree.kind {
|
if let ast::UseTreeKind::Simple(..) = use_tree.kind {
|
||||||
if use_tree.ident().name == keywords::SelfLower.name() {
|
if use_tree.ident().name == kw::SelfLower {
|
||||||
return Some(use_tree.span);
|
return Some(use_tree.span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,7 +311,7 @@ impl<'a> Resolver<'a> {
|
||||||
let new_span = prefix[prefix.len() - 1].ident.span;
|
let new_span = prefix[prefix.len() - 1].ident.span;
|
||||||
let tree = ast::UseTree {
|
let tree = ast::UseTree {
|
||||||
prefix: ast::Path::from_ident(
|
prefix: ast::Path::from_ident(
|
||||||
Ident::new(keywords::SelfLower.name(), new_span)
|
Ident::new(kw::SelfLower, new_span)
|
||||||
),
|
),
|
||||||
kind: ast::UseTreeKind::Simple(
|
kind: ast::UseTreeKind::Simple(
|
||||||
Some(Ident::from_str_and_span("__dummy", new_span).gensym()),
|
Some(Ident::from_str_and_span("__dummy", new_span).gensym()),
|
||||||
|
@ -350,7 +350,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemKind::ExternCrate(orig_name) => {
|
ItemKind::ExternCrate(orig_name) => {
|
||||||
let module = if orig_name.is_none() && ident.name == keywords::SelfLower.name() {
|
let module = if orig_name.is_none() && ident.name == kw::SelfLower {
|
||||||
self.session
|
self.session
|
||||||
.struct_span_err(item.span, "`extern crate self;` requires renaming")
|
.struct_span_err(item.span, "`extern crate self;` requires renaming")
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
|
@ -361,7 +361,7 @@ impl<'a> Resolver<'a> {
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
return;
|
return;
|
||||||
} else if orig_name == Some(keywords::SelfLower.name()) {
|
} else if orig_name == Some(kw::SelfLower) {
|
||||||
self.graph_root
|
self.graph_root
|
||||||
} else {
|
} else {
|
||||||
let crate_id = self.crate_loader.process_extern_crate(item, &self.definitions);
|
let crate_id = self.crate_loader.process_extern_crate(item, &self.definitions);
|
||||||
|
@ -420,7 +420,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
ItemKind::GlobalAsm(..) => {}
|
ItemKind::GlobalAsm(..) => {}
|
||||||
|
|
||||||
ItemKind::Mod(..) if ident == keywords::Invalid.ident() => {} // Crate root
|
ItemKind::Mod(..) if ident == Ident::with_empty_ctxt(kw::Invalid) => {} // Crate root
|
||||||
|
|
||||||
ItemKind::Mod(..) => {
|
ItemKind::Mod(..) => {
|
||||||
let def_id = self.definitions.local_def_id(item.id);
|
let def_id = self.definitions.local_def_id(item.id);
|
||||||
|
@ -831,7 +831,7 @@ impl<'a> Resolver<'a> {
|
||||||
"an `extern crate` loading macros must be at the crate root");
|
"an `extern crate` loading macros must be at the crate root");
|
||||||
}
|
}
|
||||||
if let ItemKind::ExternCrate(Some(orig_name)) = item.node {
|
if let ItemKind::ExternCrate(Some(orig_name)) = item.node {
|
||||||
if orig_name == keywords::SelfLower.name() {
|
if orig_name == kw::SelfLower {
|
||||||
self.session.span_err(attr.span,
|
self.session.span_err(attr.span,
|
||||||
"`macro_use` is not supported on `extern crate self`");
|
"`macro_use` is not supported on `extern crate self`");
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
|
||||||
use rustc::session::{Session, config::nightly_options};
|
use rustc::session::{Session, config::nightly_options};
|
||||||
use syntax::ast::{self, Expr, ExprKind, Ident};
|
use syntax::ast::{self, Expr, ExprKind, Ident};
|
||||||
use syntax::ext::base::MacroKind;
|
use syntax::ext::base::MacroKind;
|
||||||
use syntax::symbol::{Symbol, keywords};
|
use syntax::symbol::{Symbol, kw};
|
||||||
use syntax_pos::{BytePos, Span};
|
use syntax_pos::{BytePos, Span};
|
||||||
|
|
||||||
type Res = def::Res<ast::NodeId>;
|
type Res = def::Res<ast::NodeId>;
|
||||||
|
@ -48,7 +48,7 @@ impl<'a> Resolver<'a> {
|
||||||
let item_span = path.last().unwrap().ident.span;
|
let item_span = path.last().unwrap().ident.span;
|
||||||
let (mod_prefix, mod_str) = if path.len() == 1 {
|
let (mod_prefix, mod_str) = if path.len() == 1 {
|
||||||
(String::new(), "this scope".to_string())
|
(String::new(), "this scope".to_string())
|
||||||
} else if path.len() == 2 && path[0].ident.name == keywords::PathRoot.name() {
|
} else if path.len() == 2 && path[0].ident.name == kw::PathRoot {
|
||||||
(String::new(), "the crate root".to_string())
|
(String::new(), "the crate root".to_string())
|
||||||
} else {
|
} else {
|
||||||
let mod_path = &path[..path.len() - 1];
|
let mod_path = &path[..path.len() - 1];
|
||||||
|
@ -454,13 +454,13 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||||
match (path.get(0), path.get(1)) {
|
match (path.get(0), path.get(1)) {
|
||||||
// `{{root}}::ident::...` on both editions.
|
// `{{root}}::ident::...` on both editions.
|
||||||
// On 2015 `{{root}}` is usually added implicitly.
|
// On 2015 `{{root}}` is usually added implicitly.
|
||||||
(Some(fst), Some(snd)) if fst.ident.name == keywords::PathRoot.name() &&
|
(Some(fst), Some(snd)) if fst.ident.name == kw::PathRoot &&
|
||||||
!snd.ident.is_path_segment_keyword() => {}
|
!snd.ident.is_path_segment_keyword() => {}
|
||||||
// `ident::...` on 2018.
|
// `ident::...` on 2018.
|
||||||
(Some(fst), _) if fst.ident.span.rust_2018() &&
|
(Some(fst), _) if fst.ident.span.rust_2018() &&
|
||||||
!fst.ident.is_path_segment_keyword() => {
|
!fst.ident.is_path_segment_keyword() => {
|
||||||
// Insert a placeholder that's later replaced by `self`/`super`/etc.
|
// Insert a placeholder that's later replaced by `self`/`super`/etc.
|
||||||
path.insert(0, Segment::from_ident(keywords::Invalid.ident()));
|
path.insert(0, Segment::from_ident(Ident::with_empty_ctxt(kw::Invalid)));
|
||||||
}
|
}
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||||
parent_scope: &ParentScope<'b>,
|
parent_scope: &ParentScope<'b>,
|
||||||
) -> Option<(Vec<Segment>, Vec<String>)> {
|
) -> Option<(Vec<Segment>, Vec<String>)> {
|
||||||
// Replace first ident with `self` and check if that is valid.
|
// Replace first ident with `self` and check if that is valid.
|
||||||
path[0].ident.name = keywords::SelfLower.name();
|
path[0].ident.name = kw::SelfLower;
|
||||||
let result = self.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
|
let result = self.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
|
||||||
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
|
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
|
||||||
if let PathResult::Module(..) = result {
|
if let PathResult::Module(..) = result {
|
||||||
|
@ -509,7 +509,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||||
parent_scope: &ParentScope<'b>,
|
parent_scope: &ParentScope<'b>,
|
||||||
) -> Option<(Vec<Segment>, Vec<String>)> {
|
) -> Option<(Vec<Segment>, Vec<String>)> {
|
||||||
// Replace first ident with `crate` and check if that is valid.
|
// Replace first ident with `crate` and check if that is valid.
|
||||||
path[0].ident.name = keywords::Crate.name();
|
path[0].ident.name = kw::Crate;
|
||||||
let result = self.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
|
let result = self.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
|
||||||
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
|
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
|
||||||
if let PathResult::Module(..) = result {
|
if let PathResult::Module(..) = result {
|
||||||
|
@ -540,7 +540,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||||
parent_scope: &ParentScope<'b>,
|
parent_scope: &ParentScope<'b>,
|
||||||
) -> Option<(Vec<Segment>, Vec<String>)> {
|
) -> Option<(Vec<Segment>, Vec<String>)> {
|
||||||
// Replace first ident with `crate` and check if that is valid.
|
// Replace first ident with `crate` and check if that is valid.
|
||||||
path[0].ident.name = keywords::Super.name();
|
path[0].ident.name = kw::Super;
|
||||||
let result = self.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
|
let result = self.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
|
||||||
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
|
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
|
||||||
if let PathResult::Module(..) = result {
|
if let PathResult::Module(..) = result {
|
||||||
|
|
|
@ -43,7 +43,7 @@ use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
|
||||||
use syntax::ext::base::SyntaxExtension;
|
use syntax::ext::base::SyntaxExtension;
|
||||||
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
|
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
|
||||||
use syntax::ext::base::MacroKind;
|
use syntax::ext::base::MacroKind;
|
||||||
use syntax::symbol::{Symbol, keywords, sym};
|
use syntax::symbol::{Symbol, kw, sym};
|
||||||
use syntax::util::lev_distance::find_best_match_for_name;
|
use syntax::util::lev_distance::find_best_match_for_name;
|
||||||
|
|
||||||
use syntax::visit::{self, FnKind, Visitor};
|
use syntax::visit::{self, FnKind, Visitor};
|
||||||
|
@ -820,7 +820,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
|
||||||
self.smart_resolve_path(ty.id, qself.as_ref(), path, PathSource::Type);
|
self.smart_resolve_path(ty.id, qself.as_ref(), path, PathSource::Type);
|
||||||
}
|
}
|
||||||
TyKind::ImplicitSelf => {
|
TyKind::ImplicitSelf => {
|
||||||
let self_ty = keywords::SelfUpper.ident();
|
let self_ty = Ident::with_empty_ctxt(kw::SelfUpper);
|
||||||
let res = self.resolve_ident_in_lexical_scope(self_ty, TypeNS, Some(ty.id), ty.span)
|
let res = self.resolve_ident_in_lexical_scope(self_ty, TypeNS, Some(ty.id), ty.span)
|
||||||
.map_or(Res::Err, |d| d.res());
|
.map_or(Res::Err, |d| d.res());
|
||||||
self.record_partial_res(ty.id, PartialRes::new(res));
|
self.record_partial_res(ty.id, PartialRes::new(res));
|
||||||
|
@ -1817,18 +1817,17 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
|
||||||
is_value: bool
|
is_value: bool
|
||||||
) -> hir::Path {
|
) -> hir::Path {
|
||||||
let root = if crate_root.is_some() {
|
let root = if crate_root.is_some() {
|
||||||
keywords::PathRoot
|
kw::PathRoot
|
||||||
} else {
|
} else {
|
||||||
keywords::Crate
|
kw::Crate
|
||||||
};
|
};
|
||||||
let segments = iter::once(root.ident())
|
let segments = iter::once(Ident::with_empty_ctxt(root))
|
||||||
.chain(
|
.chain(
|
||||||
crate_root.into_iter()
|
crate_root.into_iter()
|
||||||
.chain(components.iter().cloned())
|
.chain(components.iter().cloned())
|
||||||
.map(Ident::with_empty_ctxt)
|
.map(Ident::with_empty_ctxt)
|
||||||
).map(|i| self.new_ast_path_segment(i)).collect::<Vec<_>>();
|
).map(|i| self.new_ast_path_segment(i)).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
|
||||||
let path = ast::Path {
|
let path = ast::Path {
|
||||||
span,
|
span,
|
||||||
segments,
|
segments,
|
||||||
|
@ -1866,7 +1865,7 @@ impl<'a> Resolver<'a> {
|
||||||
let path = if path_str.starts_with("::") {
|
let path = if path_str.starts_with("::") {
|
||||||
ast::Path {
|
ast::Path {
|
||||||
span,
|
span,
|
||||||
segments: iter::once(keywords::PathRoot.ident())
|
segments: iter::once(Ident::with_empty_ctxt(kw::PathRoot))
|
||||||
.chain({
|
.chain({
|
||||||
path_str.split("::").skip(1).map(Ident::from_str)
|
path_str.split("::").skip(1).map(Ident::from_str)
|
||||||
})
|
})
|
||||||
|
@ -1961,7 +1960,7 @@ impl<'a> Resolver<'a> {
|
||||||
let root_module_kind = ModuleKind::Def(
|
let root_module_kind = ModuleKind::Def(
|
||||||
DefKind::Mod,
|
DefKind::Mod,
|
||||||
root_def_id,
|
root_def_id,
|
||||||
keywords::Invalid.name(),
|
kw::Invalid,
|
||||||
);
|
);
|
||||||
let graph_root = arenas.alloc_module(ModuleData {
|
let graph_root = arenas.alloc_module(ModuleData {
|
||||||
no_implicit_prelude: attr::contains_name(&krate.attrs, sym::no_implicit_prelude),
|
no_implicit_prelude: attr::contains_name(&krate.attrs, sym::no_implicit_prelude),
|
||||||
|
@ -2187,10 +2186,10 @@ impl<'a> Resolver<'a> {
|
||||||
path_span: Span)
|
path_span: Span)
|
||||||
-> Option<LexicalScopeBinding<'a>> {
|
-> Option<LexicalScopeBinding<'a>> {
|
||||||
assert!(ns == TypeNS || ns == ValueNS);
|
assert!(ns == TypeNS || ns == ValueNS);
|
||||||
if ident.name == keywords::Invalid.name() {
|
if ident.name == kw::Invalid {
|
||||||
return Some(LexicalScopeBinding::Res(Res::Err));
|
return Some(LexicalScopeBinding::Res(Res::Err));
|
||||||
}
|
}
|
||||||
ident.span = if ident.name == keywords::SelfUpper.name() {
|
ident.span = if ident.name == kw::SelfUpper {
|
||||||
// FIXME(jseyfried) improve `Self` hygiene
|
// FIXME(jseyfried) improve `Self` hygiene
|
||||||
ident.span.with_ctxt(SyntaxContext::empty())
|
ident.span.with_ctxt(SyntaxContext::empty())
|
||||||
} else if ns == TypeNS {
|
} else if ns == TypeNS {
|
||||||
|
@ -2405,7 +2404,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
fn resolve_crate_root(&mut self, ident: Ident) -> Module<'a> {
|
fn resolve_crate_root(&mut self, ident: Ident) -> Module<'a> {
|
||||||
let mut ctxt = ident.span.ctxt();
|
let mut ctxt = ident.span.ctxt();
|
||||||
let mark = if ident.name == keywords::DollarCrate.name() {
|
let mark = if ident.name == kw::DollarCrate {
|
||||||
// When resolving `$crate` from a `macro_rules!` invoked in a `macro`,
|
// When resolving `$crate` from a `macro_rules!` invoked in a `macro`,
|
||||||
// we don't want to pretend that the `macro_rules!` definition is in the `macro`
|
// we don't want to pretend that the `macro_rules!` definition is in the `macro`
|
||||||
// as described in `SyntaxContext::apply_mark`, so we ignore prepended modern marks.
|
// as described in `SyntaxContext::apply_mark`, so we ignore prepended modern marks.
|
||||||
|
@ -2851,7 +2850,7 @@ impl<'a> Resolver<'a> {
|
||||||
let mut self_type_rib = Rib::new(NormalRibKind);
|
let mut self_type_rib = Rib::new(NormalRibKind);
|
||||||
|
|
||||||
// Plain insert (no renaming, since types are not currently hygienic)
|
// Plain insert (no renaming, since types are not currently hygienic)
|
||||||
self_type_rib.bindings.insert(keywords::SelfUpper.ident(), self_res);
|
self_type_rib.bindings.insert(Ident::with_empty_ctxt(kw::SelfUpper), self_res);
|
||||||
self.ribs[TypeNS].push(self_type_rib);
|
self.ribs[TypeNS].push(self_type_rib);
|
||||||
f(self);
|
f(self);
|
||||||
self.ribs[TypeNS].pop();
|
self.ribs[TypeNS].pop();
|
||||||
|
@ -2862,7 +2861,7 @@ impl<'a> Resolver<'a> {
|
||||||
{
|
{
|
||||||
let self_res = Res::SelfCtor(impl_id);
|
let self_res = Res::SelfCtor(impl_id);
|
||||||
let mut self_type_rib = Rib::new(NormalRibKind);
|
let mut self_type_rib = Rib::new(NormalRibKind);
|
||||||
self_type_rib.bindings.insert(keywords::SelfUpper.ident(), self_res);
|
self_type_rib.bindings.insert(Ident::with_empty_ctxt(kw::SelfUpper), self_res);
|
||||||
self.ribs[ValueNS].push(self_type_rib);
|
self.ribs[ValueNS].push(self_type_rib);
|
||||||
f(self);
|
f(self);
|
||||||
self.ribs[ValueNS].pop();
|
self.ribs[ValueNS].pop();
|
||||||
|
@ -3199,7 +3198,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// A completely fresh binding, add to the lists if it's valid.
|
// A completely fresh binding, add to the lists if it's valid.
|
||||||
if ident.name != keywords::Invalid.name() {
|
if ident.name != kw::Invalid {
|
||||||
bindings.insert(ident, outer_pat_id);
|
bindings.insert(ident, outer_pat_id);
|
||||||
self.ribs[ValueNS].last_mut().unwrap().bindings.insert(ident, res);
|
self.ribs[ValueNS].last_mut().unwrap().bindings.insert(ident, res);
|
||||||
}
|
}
|
||||||
|
@ -3494,13 +3493,13 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn self_type_is_available(&mut self, span: Span) -> bool {
|
fn self_type_is_available(&mut self, span: Span) -> bool {
|
||||||
let binding = self.resolve_ident_in_lexical_scope(keywords::SelfUpper.ident(),
|
let binding = self.resolve_ident_in_lexical_scope(Ident::with_empty_ctxt(kw::SelfUpper),
|
||||||
TypeNS, None, span);
|
TypeNS, None, span);
|
||||||
if let Some(LexicalScopeBinding::Res(res)) = binding { res != Res::Err } else { false }
|
if let Some(LexicalScopeBinding::Res(res)) = binding { res != Res::Err } else { false }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn self_value_is_available(&mut self, self_span: Span, path_span: Span) -> bool {
|
fn self_value_is_available(&mut self, self_span: Span, path_span: Span) -> bool {
|
||||||
let ident = Ident::new(keywords::SelfLower.name(), self_span);
|
let ident = Ident::new(kw::SelfLower, self_span);
|
||||||
let binding = self.resolve_ident_in_lexical_scope(ident, ValueNS, None, path_span);
|
let binding = self.resolve_ident_in_lexical_scope(ident, ValueNS, None, path_span);
|
||||||
if let Some(LexicalScopeBinding::Res(res)) = binding { res != Res::Err } else { false }
|
if let Some(LexicalScopeBinding::Res(res)) = binding { res != Res::Err } else { false }
|
||||||
}
|
}
|
||||||
|
@ -3657,8 +3656,8 @@ impl<'a> Resolver<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if path.len() > 1 && !global_by_default && result.base_res() != Res::Err &&
|
if path.len() > 1 && !global_by_default && result.base_res() != Res::Err &&
|
||||||
path[0].ident.name != keywords::PathRoot.name() &&
|
path[0].ident.name != kw::PathRoot &&
|
||||||
path[0].ident.name != keywords::DollarCrate.name() {
|
path[0].ident.name != kw::DollarCrate {
|
||||||
let unqualified_result = {
|
let unqualified_result = {
|
||||||
match self.resolve_path_without_parent_scope(
|
match self.resolve_path_without_parent_scope(
|
||||||
&[*path.last().unwrap()],
|
&[*path.last().unwrap()],
|
||||||
|
@ -3739,11 +3738,11 @@ impl<'a> Resolver<'a> {
|
||||||
let name = ident.name;
|
let name = ident.name;
|
||||||
|
|
||||||
allow_super &= ns == TypeNS &&
|
allow_super &= ns == TypeNS &&
|
||||||
(name == keywords::SelfLower.name() ||
|
(name == kw::SelfLower ||
|
||||||
name == keywords::Super.name());
|
name == kw::Super);
|
||||||
|
|
||||||
if ns == TypeNS {
|
if ns == TypeNS {
|
||||||
if allow_super && name == keywords::Super.name() {
|
if allow_super && name == kw::Super {
|
||||||
let mut ctxt = ident.span.ctxt().modern();
|
let mut ctxt = ident.span.ctxt().modern();
|
||||||
let self_module = match i {
|
let self_module = match i {
|
||||||
0 => Some(self.resolve_self(&mut ctxt, self.current_module)),
|
0 => Some(self.resolve_self(&mut ctxt, self.current_module)),
|
||||||
|
@ -3768,25 +3767,25 @@ impl<'a> Resolver<'a> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if name == keywords::SelfLower.name() {
|
if name == kw::SelfLower {
|
||||||
let mut ctxt = ident.span.ctxt().modern();
|
let mut ctxt = ident.span.ctxt().modern();
|
||||||
module = Some(ModuleOrUniformRoot::Module(
|
module = Some(ModuleOrUniformRoot::Module(
|
||||||
self.resolve_self(&mut ctxt, self.current_module)));
|
self.resolve_self(&mut ctxt, self.current_module)));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if name == keywords::PathRoot.name() && ident.span.rust_2018() {
|
if name == kw::PathRoot && ident.span.rust_2018() {
|
||||||
module = Some(ModuleOrUniformRoot::ExternPrelude);
|
module = Some(ModuleOrUniformRoot::ExternPrelude);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if name == keywords::PathRoot.name() &&
|
if name == kw::PathRoot &&
|
||||||
ident.span.rust_2015() && self.session.rust_2018() {
|
ident.span.rust_2015() && self.session.rust_2018() {
|
||||||
// `::a::b` from 2015 macro on 2018 global edition
|
// `::a::b` from 2015 macro on 2018 global edition
|
||||||
module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude);
|
module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if name == keywords::PathRoot.name() ||
|
if name == kw::PathRoot ||
|
||||||
name == keywords::Crate.name() ||
|
name == kw::Crate ||
|
||||||
name == keywords::DollarCrate.name() {
|
name == kw::DollarCrate {
|
||||||
// `::a::b`, `crate::a::b` or `$crate::a::b`
|
// `::a::b`, `crate::a::b` or `$crate::a::b`
|
||||||
module = Some(ModuleOrUniformRoot::Module(
|
module = Some(ModuleOrUniformRoot::Module(
|
||||||
self.resolve_crate_root(ident)));
|
self.resolve_crate_root(ident)));
|
||||||
|
@ -3797,12 +3796,12 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
// Report special messages for path segment keywords in wrong positions.
|
// Report special messages for path segment keywords in wrong positions.
|
||||||
if ident.is_path_segment_keyword() && i != 0 {
|
if ident.is_path_segment_keyword() && i != 0 {
|
||||||
let name_str = if name == keywords::PathRoot.name() {
|
let name_str = if name == kw::PathRoot {
|
||||||
"crate root".to_string()
|
"crate root".to_string()
|
||||||
} else {
|
} else {
|
||||||
format!("`{}`", name)
|
format!("`{}`", name)
|
||||||
};
|
};
|
||||||
let label = if i == 1 && path[0].ident.name == keywords::PathRoot.name() {
|
let label = if i == 1 && path[0].ident.name == kw::PathRoot {
|
||||||
format!("global paths cannot start with {}", name_str)
|
format!("global paths cannot start with {}", name_str)
|
||||||
} else {
|
} else {
|
||||||
format!("{} in paths can only be used in start position", name_str)
|
format!("{} in paths can only be used in start position", name_str)
|
||||||
|
@ -3971,13 +3970,13 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
// We're only interested in `use` paths which should start with
|
// We're only interested in `use` paths which should start with
|
||||||
// `{{root}}` currently.
|
// `{{root}}` currently.
|
||||||
if first_name != keywords::PathRoot.name() {
|
if first_name != kw::PathRoot {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
match path.get(1) {
|
match path.get(1) {
|
||||||
// If this import looks like `crate::...` it's already good
|
// If this import looks like `crate::...` it's already good
|
||||||
Some(Segment { ident, .. }) if ident.name == keywords::Crate.name() => return,
|
Some(Segment { ident, .. }) if ident.name == kw::Crate => return,
|
||||||
// Otherwise go below to see if it's an extern crate
|
// Otherwise go below to see if it's an extern crate
|
||||||
Some(_) => {}
|
Some(_) => {}
|
||||||
// If the path has length one (and it's `PathRoot` most likely)
|
// If the path has length one (and it's `PathRoot` most likely)
|
||||||
|
@ -4670,7 +4669,7 @@ impl<'a> Resolver<'a> {
|
||||||
{
|
{
|
||||||
let mut candidates = Vec::new();
|
let mut candidates = Vec::new();
|
||||||
let mut seen_modules = FxHashSet::default();
|
let mut seen_modules = FxHashSet::default();
|
||||||
let not_local_module = crate_name != keywords::Crate.ident();
|
let not_local_module = crate_name != Ident::with_empty_ctxt(kw::Crate);
|
||||||
let mut worklist = vec![(start_module, Vec::<ast::PathSegment>::new(), not_local_module)];
|
let mut worklist = vec![(start_module, Vec::<ast::PathSegment>::new(), not_local_module)];
|
||||||
|
|
||||||
while let Some((in_module,
|
while let Some((in_module,
|
||||||
|
@ -4764,7 +4763,8 @@ impl<'a> Resolver<'a> {
|
||||||
where FilterFn: Fn(Res) -> bool
|
where FilterFn: Fn(Res) -> bool
|
||||||
{
|
{
|
||||||
let mut suggestions = self.lookup_import_candidates_from_module(
|
let mut suggestions = self.lookup_import_candidates_from_module(
|
||||||
lookup_ident, namespace, self.graph_root, keywords::Crate.ident(), &filter_fn);
|
lookup_ident, namespace, self.graph_root, Ident::with_empty_ctxt(kw::Crate), &filter_fn
|
||||||
|
);
|
||||||
|
|
||||||
if lookup_ident.span.rust_2018() {
|
if lookup_ident.span.rust_2018() {
|
||||||
let extern_prelude_names = self.extern_prelude.clone();
|
let extern_prelude_names = self.extern_prelude.clone();
|
||||||
|
@ -4883,7 +4883,7 @@ impl<'a> Resolver<'a> {
|
||||||
} else {
|
} else {
|
||||||
let ctxt = ident.span.ctxt();
|
let ctxt = ident.span.ctxt();
|
||||||
Some(Segment::from_ident(Ident::new(
|
Some(Segment::from_ident(Ident::new(
|
||||||
keywords::PathRoot.name(), path.span.shrink_to_lo().with_ctxt(ctxt)
|
kw::PathRoot, path.span.shrink_to_lo().with_ctxt(ctxt)
|
||||||
)))
|
)))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5352,17 +5352,17 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_self_type(path: &[Segment], namespace: Namespace) -> bool {
|
fn is_self_type(path: &[Segment], namespace: Namespace) -> bool {
|
||||||
namespace == TypeNS && path.len() == 1 && path[0].ident.name == keywords::SelfUpper.name()
|
namespace == TypeNS && path.len() == 1 && path[0].ident.name == kw::SelfUpper
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_self_value(path: &[Segment], namespace: Namespace) -> bool {
|
fn is_self_value(path: &[Segment], namespace: Namespace) -> bool {
|
||||||
namespace == ValueNS && path.len() == 1 && path[0].ident.name == keywords::SelfLower.name()
|
namespace == ValueNS && path.len() == 1 && path[0].ident.name == kw::SelfLower
|
||||||
}
|
}
|
||||||
|
|
||||||
fn names_to_string(idents: &[Ident]) -> String {
|
fn names_to_string(idents: &[Ident]) -> String {
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
for (i, ident) in idents.iter()
|
for (i, ident) in idents.iter()
|
||||||
.filter(|ident| ident.name != keywords::PathRoot.name())
|
.filter(|ident| ident.name != kw::PathRoot)
|
||||||
.enumerate() {
|
.enumerate() {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
result.push_str("::");
|
result.push_str("::");
|
||||||
|
|
|
@ -22,7 +22,7 @@ use syntax::ext::tt::macro_rules;
|
||||||
use syntax::feature_gate::{
|
use syntax::feature_gate::{
|
||||||
feature_err, is_builtin_attr_name, AttributeGate, GateIssue, Stability, BUILTIN_ATTRIBUTES,
|
feature_err, is_builtin_attr_name, AttributeGate, GateIssue, Stability, BUILTIN_ATTRIBUTES,
|
||||||
};
|
};
|
||||||
use syntax::symbol::{Symbol, keywords, sym};
|
use syntax::symbol::{Symbol, kw, sym};
|
||||||
use syntax::visit::Visitor;
|
use syntax::visit::Visitor;
|
||||||
use syntax::util::lev_distance::find_best_match_for_name;
|
use syntax::util::lev_distance::find_best_match_for_name;
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
|
@ -137,10 +137,10 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||||
}
|
}
|
||||||
impl<'a> Visitor<'a> for ResolveDollarCrates<'a, '_> {
|
impl<'a> Visitor<'a> for ResolveDollarCrates<'a, '_> {
|
||||||
fn visit_ident(&mut self, ident: Ident) {
|
fn visit_ident(&mut self, ident: Ident) {
|
||||||
if ident.name == keywords::DollarCrate.name() {
|
if ident.name == kw::DollarCrate {
|
||||||
let name = match self.resolver.resolve_crate_root(ident).kind {
|
let name = match self.resolver.resolve_crate_root(ident).kind {
|
||||||
ModuleKind::Def(.., name) if name != keywords::Invalid.name() => name,
|
ModuleKind::Def(.., name) if name != kw::Invalid => name,
|
||||||
_ => keywords::Crate.name(),
|
_ => kw::Crate,
|
||||||
};
|
};
|
||||||
ident.span.ctxt().set_dollar_crate_name(name);
|
ident.span.ctxt().set_dollar_crate_name(name);
|
||||||
}
|
}
|
||||||
|
@ -415,7 +415,7 @@ impl<'a> Resolver<'a> {
|
||||||
if kind == MacroKind::Bang && path.len() == 1 &&
|
if kind == MacroKind::Bang && path.len() == 1 &&
|
||||||
path[0].ident.span.ctxt().outer().expn_info()
|
path[0].ident.span.ctxt().outer().expn_info()
|
||||||
.map_or(false, |info| info.local_inner_macros) {
|
.map_or(false, |info| info.local_inner_macros) {
|
||||||
let root = Ident::new(keywords::DollarCrate.name(), path[0].ident.span);
|
let root = Ident::new(kw::DollarCrate, path[0].ident.span);
|
||||||
path.insert(0, Segment::from_ident(root));
|
path.insert(0, Segment::from_ident(root));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,7 +613,7 @@ impl<'a> Resolver<'a> {
|
||||||
_ => Err(Determinacy::Determined),
|
_ => Err(Determinacy::Determined),
|
||||||
}
|
}
|
||||||
WhereToResolve::CrateRoot => {
|
WhereToResolve::CrateRoot => {
|
||||||
let root_ident = Ident::new(keywords::PathRoot.name(), orig_ident.span);
|
let root_ident = Ident::new(kw::PathRoot, orig_ident.span);
|
||||||
let root_module = self.resolve_crate_root(root_ident);
|
let root_module = self.resolve_crate_root(root_ident);
|
||||||
let binding = self.resolve_ident_in_module_ext(
|
let binding = self.resolve_ident_in_module_ext(
|
||||||
ModuleOrUniformRoot::Module(root_module),
|
ModuleOrUniformRoot::Module(root_module),
|
||||||
|
|
|
@ -29,7 +29,7 @@ use rustc::{bug, span_bug};
|
||||||
use syntax::ast::{self, Ident, Name, NodeId, CRATE_NODE_ID};
|
use syntax::ast::{self, Ident, Name, NodeId, CRATE_NODE_ID};
|
||||||
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
|
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
|
||||||
use syntax::ext::hygiene::Mark;
|
use syntax::ext::hygiene::Mark;
|
||||||
use syntax::symbol::{keywords, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax::util::lev_distance::find_best_match_for_name;
|
use syntax::util::lev_distance::find_best_match_for_name;
|
||||||
use syntax::{struct_span_err, unwrap_or};
|
use syntax::{struct_span_err, unwrap_or};
|
||||||
use syntax_pos::{MultiSpan, Span};
|
use syntax_pos::{MultiSpan, Span};
|
||||||
|
@ -217,15 +217,15 @@ impl<'a> Resolver<'a> {
|
||||||
parent_scope.expect("no parent scope for a single-segment import");
|
parent_scope.expect("no parent scope for a single-segment import");
|
||||||
|
|
||||||
if ns == TypeNS {
|
if ns == TypeNS {
|
||||||
if ident.name == keywords::Crate.name() ||
|
if ident.name == kw::Crate ||
|
||||||
ident.name == keywords::DollarCrate.name() {
|
ident.name == kw::DollarCrate {
|
||||||
let module = self.resolve_crate_root(ident);
|
let module = self.resolve_crate_root(ident);
|
||||||
let binding = (module, ty::Visibility::Public,
|
let binding = (module, ty::Visibility::Public,
|
||||||
module.span, Mark::root())
|
module.span, Mark::root())
|
||||||
.to_name_binding(self.arenas);
|
.to_name_binding(self.arenas);
|
||||||
return Ok(binding);
|
return Ok(binding);
|
||||||
} else if ident.name == keywords::Super.name() ||
|
} else if ident.name == kw::Super ||
|
||||||
ident.name == keywords::SelfLower.name() {
|
ident.name == kw::SelfLower {
|
||||||
// FIXME: Implement these with renaming requirements so that e.g.
|
// FIXME: Implement these with renaming requirements so that e.g.
|
||||||
// `use super;` doesn't work, but `use super as name;` does.
|
// `use super;` doesn't work, but `use super as name;` does.
|
||||||
// Fall through here to get an error from `early_resolve_...`.
|
// Fall through here to get an error from `early_resolve_...`.
|
||||||
|
@ -992,7 +992,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||||
// HACK(eddyb) `lint_if_path_starts_with_module` needs at least
|
// HACK(eddyb) `lint_if_path_starts_with_module` needs at least
|
||||||
// 2 segments, so the `resolve_path` above won't trigger it.
|
// 2 segments, so the `resolve_path` above won't trigger it.
|
||||||
let mut full_path = directive.module_path.clone();
|
let mut full_path = directive.module_path.clone();
|
||||||
full_path.push(Segment::from_ident(keywords::Invalid.ident()));
|
full_path.push(Segment::from_ident(Ident::with_empty_ctxt(kw::Invalid)));
|
||||||
self.lint_if_path_starts_with_module(
|
self.lint_if_path_starts_with_module(
|
||||||
directive.crate_lint(),
|
directive.crate_lint(),
|
||||||
&full_path,
|
&full_path,
|
||||||
|
@ -1484,8 +1484,8 @@ fn import_path_to_string(names: &[Ident],
|
||||||
subclass: &ImportDirectiveSubclass<'_>,
|
subclass: &ImportDirectiveSubclass<'_>,
|
||||||
span: Span) -> String {
|
span: Span) -> String {
|
||||||
let pos = names.iter()
|
let pos = names.iter()
|
||||||
.position(|p| span == p.span && p.name != keywords::PathRoot.name());
|
.position(|p| span == p.span && p.name != kw::PathRoot);
|
||||||
let global = !names.is_empty() && names[0].name == keywords::PathRoot.name();
|
let global = !names.is_empty() && names[0].name == kw::PathRoot;
|
||||||
if let Some(pos) = pos {
|
if let Some(pos) = pos {
|
||||||
let names = if global { &names[1..pos + 1] } else { &names[..pos + 1] };
|
let names = if global { &names[1..pos + 1] } else { &names[..pos + 1] };
|
||||||
names_to_string(names)
|
names_to_string(names)
|
||||||
|
|
|
@ -123,7 +123,7 @@ use syntax::attr;
|
||||||
use syntax::feature_gate::{GateIssue, emit_feature_err};
|
use syntax::feature_gate::{GateIssue, emit_feature_err};
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::source_map::{DUMMY_SP, original_sp};
|
use syntax::source_map::{DUMMY_SP, original_sp};
|
||||||
use syntax::symbol::{Symbol, LocalInternedString, keywords, sym};
|
use syntax::symbol::{Symbol, LocalInternedString, kw, sym};
|
||||||
use syntax::util::lev_distance::find_best_match_for_name;
|
use syntax::util::lev_distance::find_best_match_for_name;
|
||||||
|
|
||||||
use std::cell::{Cell, RefCell, Ref, RefMut};
|
use std::cell::{Cell, RefCell, Ref, RefMut};
|
||||||
|
@ -3290,7 +3290,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
Ok(method)
|
Ok(method)
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
if segment.ident.name != keywords::Invalid.name() {
|
if segment.ident.name != kw::Invalid {
|
||||||
self.report_method_error(span,
|
self.report_method_error(span,
|
||||||
rcvr_t,
|
rcvr_t,
|
||||||
segment.ident,
|
segment.ident,
|
||||||
|
@ -3402,7 +3402,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
err.emit();
|
err.emit();
|
||||||
field_ty
|
field_ty
|
||||||
} else if field.name == keywords::Invalid.name() {
|
} else if field.name == kw::Invalid {
|
||||||
self.tcx().types.err
|
self.tcx().types.err
|
||||||
} else if self.method_exists(field, expr_t, expr.hir_id, true) {
|
} else if self.method_exists(field, expr_t, expr.hir_id, true) {
|
||||||
let mut err = type_error_struct!(self.tcx().sess, field.span, expr_t, E0615,
|
let mut err = type_error_struct!(self.tcx().sess, field.span, expr_t, E0615,
|
||||||
|
@ -4672,7 +4672,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
method::MethodError::PrivateMatch(kind, def_id, _) => Ok((kind, def_id)),
|
method::MethodError::PrivateMatch(kind, def_id, _) => Ok((kind, def_id)),
|
||||||
_ => Err(ErrorReported),
|
_ => Err(ErrorReported),
|
||||||
};
|
};
|
||||||
if item_name.name != keywords::Invalid.name() {
|
if item_name.name != kw::Invalid {
|
||||||
self.report_method_error(
|
self.report_method_error(
|
||||||
span,
|
span,
|
||||||
ty,
|
ty,
|
||||||
|
|
|
@ -39,7 +39,7 @@ use syntax::ast::{Ident, MetaItemKind};
|
||||||
use syntax::attr::{InlineAttr, OptimizeAttr, list_contains_name, mark_used};
|
use syntax::attr::{InlineAttr, OptimizeAttr, list_contains_name, mark_used};
|
||||||
use syntax::source_map::Spanned;
|
use syntax::source_map::Spanned;
|
||||||
use syntax::feature_gate;
|
use syntax::feature_gate;
|
||||||
use syntax::symbol::{InternedString, keywords, Symbol, sym};
|
use syntax::symbol::{InternedString, kw, Symbol, sym};
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
|
|
||||||
use rustc::hir::def::{CtorKind, Res, DefKind};
|
use rustc::hir::def::{CtorKind, Res, DefKind};
|
||||||
|
@ -939,7 +939,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
|
||||||
|
|
||||||
opt_self = Some(ty::GenericParamDef {
|
opt_self = Some(ty::GenericParamDef {
|
||||||
index: 0,
|
index: 0,
|
||||||
name: keywords::SelfUpper.name().as_interned_str(),
|
name: kw::SelfUpper.as_interned_str(),
|
||||||
def_id: tcx.hir().local_def_id_from_hir_id(param_id),
|
def_id: tcx.hir().local_def_id_from_hir_id(param_id),
|
||||||
pure_wrt_drop: false,
|
pure_wrt_drop: false,
|
||||||
kind: ty::GenericParamDefKind::Type {
|
kind: ty::GenericParamDefKind::Type {
|
||||||
|
@ -1008,7 +1008,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
|
||||||
synthetic,
|
synthetic,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
if param.name.ident().name == keywords::SelfUpper.name() {
|
if param.name.ident().name == kw::SelfUpper {
|
||||||
span_bug!(
|
span_bug!(
|
||||||
param.span,
|
param.span,
|
||||||
"`Self` should not be the name of a regular parameter"
|
"`Self` should not be the name of a regular parameter"
|
||||||
|
@ -1038,7 +1038,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GenericParamKind::Const { .. } => {
|
GenericParamKind::Const { .. } => {
|
||||||
if param.name.ident().name == keywords::SelfUpper.name() {
|
if param.name.ident().name == kw::SelfUpper {
|
||||||
span_bug!(
|
span_bug!(
|
||||||
param.span,
|
param.span,
|
||||||
"`Self` should not be the name of a regular parameter",
|
"`Self` should not be the name of a regular parameter",
|
||||||
|
|
|
@ -31,8 +31,7 @@ use syntax::attr;
|
||||||
use syntax::ext::base::MacroKind;
|
use syntax::ext::base::MacroKind;
|
||||||
use syntax::source_map::{dummy_spanned, Spanned};
|
use syntax::source_map::{dummy_spanned, Spanned};
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::keywords::{self, Keyword};
|
use syntax::symbol::{Symbol, kw, sym};
|
||||||
use syntax::symbol::{Symbol, sym};
|
|
||||||
use syntax::symbol::InternedString;
|
use syntax::symbol::InternedString;
|
||||||
use syntax_pos::{self, Pos, FileName};
|
use syntax_pos::{self, Pos, FileName};
|
||||||
|
|
||||||
|
@ -43,7 +42,6 @@ use std::default::Default;
|
||||||
use std::{mem, slice, vec};
|
use std::{mem, slice, vec};
|
||||||
use std::iter::{FromIterator, once};
|
use std::iter::{FromIterator, once};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::str::FromStr;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::u32;
|
use std::u32;
|
||||||
|
@ -309,10 +307,9 @@ impl Clean<ExternalCrate> for CrateNum {
|
||||||
for attr in attrs.lists(sym::doc) {
|
for attr in attrs.lists(sym::doc) {
|
||||||
if let Some(v) = attr.value_str() {
|
if let Some(v) = attr.value_str() {
|
||||||
if attr.check_name(sym::keyword) {
|
if attr.check_name(sym::keyword) {
|
||||||
keyword = Keyword::from_str(&v.as_str()).ok()
|
if v.is_doc_keyword() {
|
||||||
.map(|x| x.name().to_string());
|
keyword = Some(v.to_string());
|
||||||
if keyword.is_some() {
|
break;
|
||||||
break
|
|
||||||
}
|
}
|
||||||
// FIXME: should warn on unknown keywords?
|
// FIXME: should warn on unknown keywords?
|
||||||
}
|
}
|
||||||
|
@ -1702,7 +1699,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
|
||||||
let stripped_typarams = gens.params.iter().filter_map(|param| match param.kind {
|
let stripped_typarams = gens.params.iter().filter_map(|param| match param.kind {
|
||||||
ty::GenericParamDefKind::Lifetime => None,
|
ty::GenericParamDefKind::Lifetime => None,
|
||||||
ty::GenericParamDefKind::Type { .. } => {
|
ty::GenericParamDefKind::Type { .. } => {
|
||||||
if param.name.as_symbol() == keywords::SelfUpper.name() {
|
if param.name.as_symbol() == kw::SelfUpper {
|
||||||
assert_eq!(param.index, 0);
|
assert_eq!(param.index, 0);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -3596,7 +3593,7 @@ fn qpath_to_string(p: &hir::QPath) -> String {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
s.push_str("::");
|
s.push_str("::");
|
||||||
}
|
}
|
||||||
if seg.ident.name != keywords::PathRoot.name() {
|
if seg.ident.name != kw::PathRoot {
|
||||||
s.push_str(&*seg.ident.as_str());
|
s.push_str(&*seg.ident.as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4176,7 +4173,7 @@ fn resolve_type(cx: &DocContext<'_>,
|
||||||
hir::Float(float_ty) => return Primitive(float_ty.into()),
|
hir::Float(float_ty) => return Primitive(float_ty.into()),
|
||||||
},
|
},
|
||||||
Res::SelfTy(..) if path.segments.len() == 1 => {
|
Res::SelfTy(..) if path.segments.len() == 1 => {
|
||||||
return Generic(keywords::SelfUpper.name().to_string());
|
return Generic(kw::SelfUpper.to_string());
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => {
|
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => {
|
||||||
return Generic(format!("{:#}", path));
|
return Generic(format!("{:#}", path));
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
|
||||||
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\
|
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\
|
||||||
<meta name=\"generator\" content=\"rustdoc\">\
|
<meta name=\"generator\" content=\"rustdoc\">\
|
||||||
<meta name=\"description\" content=\"{description}\">\
|
<meta name=\"description\" content=\"{description}\">\
|
||||||
<meta name=\"keywords\" content=\"{keywords}\">\
|
<meta name=\"keywords\" content=\"{kw}\">\
|
||||||
<title>{title}</title>\
|
<title>{title}</title>\
|
||||||
<link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}normalize{suffix}.css\">\
|
<link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}normalize{suffix}.css\">\
|
||||||
<link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}rustdoc{suffix}.css\" \
|
<link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}rustdoc{suffix}.css\" \
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::parse::token;
|
||||||
use crate::print::pprust;
|
use crate::print::pprust;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::source_map::{dummy_spanned, respan, Spanned};
|
use crate::source_map::{dummy_spanned, respan, Spanned};
|
||||||
use crate::symbol::{keywords, Symbol};
|
use crate::symbol::{kw, Symbol};
|
||||||
use crate::tokenstream::TokenStream;
|
use crate::tokenstream::TokenStream;
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ impl fmt::Debug for Lifetime {
|
||||||
pub struct Path {
|
pub struct Path {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
/// The segments in the path: the things separated by `::`.
|
/// The segments in the path: the things separated by `::`.
|
||||||
/// Global paths begin with `keywords::PathRoot`.
|
/// Global paths begin with `kw::PathRoot`.
|
||||||
pub segments: Vec<PathSegment>,
|
pub segments: Vec<PathSegment>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ impl Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_global(&self) -> bool {
|
pub fn is_global(&self) -> bool {
|
||||||
!self.segments.is_empty() && self.segments[0].ident.name == keywords::PathRoot.name()
|
!self.segments.is_empty() && self.segments[0].ident.name == kw::PathRoot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ impl PathSegment {
|
||||||
PathSegment { ident, id: DUMMY_NODE_ID, args: None }
|
PathSegment { ident, id: DUMMY_NODE_ID, args: None }
|
||||||
}
|
}
|
||||||
pub fn path_root(span: Span) -> Self {
|
pub fn path_root(span: Span) -> Self {
|
||||||
PathSegment::from_ident(Ident::new(keywords::PathRoot.name(), span))
|
PathSegment::from_ident(Ident::new(kw::PathRoot, span))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1782,7 +1782,7 @@ pub type ExplicitSelf = Spanned<SelfKind>;
|
||||||
impl Arg {
|
impl Arg {
|
||||||
pub fn to_self(&self) -> Option<ExplicitSelf> {
|
pub fn to_self(&self) -> Option<ExplicitSelf> {
|
||||||
if let PatKind::Ident(BindingMode::ByValue(mutbl), ident, _) = self.pat.node {
|
if let PatKind::Ident(BindingMode::ByValue(mutbl), ident, _) = self.pat.node {
|
||||||
if ident.name == keywords::SelfLower.name() {
|
if ident.name == kw::SelfLower {
|
||||||
return match self.ty.node {
|
return match self.ty.node {
|
||||||
TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
|
TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
|
||||||
TyKind::Rptr(lt, MutTy { ref ty, mutbl }) if ty.node.is_implicit_self() => {
|
TyKind::Rptr(lt, MutTy { ref ty, mutbl }) if ty.node.is_implicit_self() => {
|
||||||
|
@ -1800,7 +1800,7 @@ impl Arg {
|
||||||
|
|
||||||
pub fn is_self(&self) -> bool {
|
pub fn is_self(&self) -> bool {
|
||||||
if let PatKind::Ident(_, ident, _) = self.pat.node {
|
if let PatKind::Ident(_, ident, _) = self.pat.node {
|
||||||
ident.name == keywords::SelfLower.name()
|
ident.name == kw::SelfLower
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ use crate::parse::parser::Parser;
|
||||||
use crate::parse::{self, ParseSess, PResult};
|
use crate::parse::{self, ParseSess, PResult};
|
||||||
use crate::parse::token::{self, Token};
|
use crate::parse::token::{self, Token};
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::{keywords, Symbol, sym};
|
use crate::symbol::{kw, sym, Symbol};
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};
|
use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};
|
||||||
use crate::GLOBALS;
|
use crate::GLOBALS;
|
||||||
|
@ -90,7 +90,7 @@ impl NestedMetaItem {
|
||||||
self.meta_item().and_then(|meta_item| meta_item.ident())
|
self.meta_item().and_then(|meta_item| meta_item.ident())
|
||||||
}
|
}
|
||||||
pub fn name_or_empty(&self) -> Symbol {
|
pub fn name_or_empty(&self) -> Symbol {
|
||||||
self.ident().unwrap_or(keywords::Invalid.ident()).name
|
self.ident().unwrap_or(Ident::invalid()).name
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the string value if self is a MetaItem and the MetaItem is a
|
/// Gets the string value if self is a MetaItem and the MetaItem is a
|
||||||
|
@ -168,7 +168,7 @@ impl Attribute {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn name_or_empty(&self) -> Symbol {
|
pub fn name_or_empty(&self) -> Symbol {
|
||||||
self.ident().unwrap_or(keywords::Invalid.ident()).name
|
self.ident().unwrap_or(Ident::invalid()).name
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn value_str(&self) -> Option<Symbol> {
|
pub fn value_str(&self) -> Option<Symbol> {
|
||||||
|
@ -206,7 +206,7 @@ impl MetaItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn name_or_empty(&self) -> Symbol {
|
pub fn name_or_empty(&self) -> Symbol {
|
||||||
self.ident().unwrap_or(keywords::Invalid.ident()).name
|
self.ident().unwrap_or(Ident.invalid()).name
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[attribute(name = "value")]
|
// #[attribute(name = "value")]
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::ext::base::{ExtCtxt, MacEager, MacResult};
|
||||||
use crate::ext::build::AstBuilder;
|
use crate::ext::build::AstBuilder;
|
||||||
use crate::parse::token;
|
use crate::parse::token;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::keywords;
|
use crate::symbol::kw;
|
||||||
use crate::tokenstream::{TokenTree};
|
use crate::tokenstream::{TokenTree};
|
||||||
|
|
||||||
use smallvec::smallvec;
|
use smallvec::smallvec;
|
||||||
|
@ -185,7 +185,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt<'_>,
|
||||||
(descriptions.len(), ecx.expr_vec(span, descriptions))
|
(descriptions.len(), ecx.expr_vec(span, descriptions))
|
||||||
});
|
});
|
||||||
|
|
||||||
let static_ = ecx.lifetime(span, keywords::StaticLifetime.ident());
|
let static_ = ecx.lifetime(span, Ident::with_empty_ctxt(kw::StaticLifetime));
|
||||||
let ty_str = ecx.ty_rptr(
|
let ty_str = ecx.ty_rptr(
|
||||||
span,
|
span,
|
||||||
ecx.ty_ident(span, ecx.ident_of("str")),
|
ecx.ty_ident(span, ecx.ident_of("str")),
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::mut_visit::{self, MutVisitor};
|
||||||
use crate::parse::{self, parser, DirectoryOwnership};
|
use crate::parse::{self, parser, DirectoryOwnership};
|
||||||
use crate::parse::token;
|
use crate::parse::token;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::{keywords, Ident, Symbol, sym};
|
use crate::symbol::{kw, sym, Ident, Symbol};
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
use crate::tokenstream::{self, TokenStream};
|
use crate::tokenstream::{self, TokenStream};
|
||||||
|
|
||||||
|
@ -971,7 +971,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
}
|
}
|
||||||
pub fn std_path(&self, components: &[&str]) -> Vec<ast::Ident> {
|
pub fn std_path(&self, components: &[&str]) -> Vec<ast::Ident> {
|
||||||
let def_site = DUMMY_SP.apply_mark(self.current_expansion.mark);
|
let def_site = DUMMY_SP.apply_mark(self.current_expansion.mark);
|
||||||
iter::once(Ident::new(keywords::DollarCrate.name(), def_site))
|
iter::once(Ident::new(kw::DollarCrate, def_site))
|
||||||
.chain(components.iter().map(|s| self.ident_of(s)))
|
.chain(components.iter().map(|s| self.ident_of(s)))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::attr;
|
||||||
use crate::source_map::{dummy_spanned, respan, Spanned};
|
use crate::source_map::{dummy_spanned, respan, Spanned};
|
||||||
use crate::ext::base::ExtCtxt;
|
use crate::ext::base::ExtCtxt;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::{Symbol, keywords};
|
use crate::symbol::{Symbol, kw};
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
|
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
|
@ -628,7 +628,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.expr_path(self.path_ident(span, id))
|
self.expr_path(self.path_ident(span, id))
|
||||||
}
|
}
|
||||||
fn expr_self(&self, span: Span) -> P<ast::Expr> {
|
fn expr_self(&self, span: Span) -> P<ast::Expr> {
|
||||||
self.expr_ident(span, keywords::SelfLower.ident())
|
self.expr_ident(span, Ident::with_empty_ctxt(kw::SelfLower))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_binary(&self, sp: Span, op: ast::BinOpKind,
|
fn expr_binary(&self, sp: Span, op: ast::BinOpKind,
|
||||||
|
@ -1175,7 +1175,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
vis: ast::Visibility, vp: P<ast::UseTree>) -> P<ast::Item> {
|
vis: ast::Visibility, vp: P<ast::UseTree>) -> P<ast::Item> {
|
||||||
P(ast::Item {
|
P(ast::Item {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
ident: keywords::Invalid.ident(),
|
ident: Ident::with_empty_ctxt(kw::Invalid),
|
||||||
attrs: vec![],
|
attrs: vec![],
|
||||||
node: ast::ItemKind::Use(vp),
|
node: ast::ItemKind::Use(vp),
|
||||||
vis,
|
vis,
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::parse::token::{self, Token};
|
||||||
use crate::parse::parser::Parser;
|
use crate::parse::parser::Parser;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::Symbol;
|
use crate::symbol::Symbol;
|
||||||
use crate::symbol::{keywords, sym};
|
use crate::symbol::{kw, sym};
|
||||||
use crate::tokenstream::{TokenStream, TokenTree};
|
use crate::tokenstream::{TokenStream, TokenTree};
|
||||||
use crate::visit::{self, Visitor};
|
use crate::visit::{self, Visitor};
|
||||||
use crate::util::map_in_place::MapInPlace;
|
use crate::util::map_in_place::MapInPlace;
|
||||||
|
@ -198,7 +198,7 @@ fn macro_bang_format(path: &ast::Path) -> ExpnFormat {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
path_str.push_str("::");
|
path_str.push_str("::");
|
||||||
}
|
}
|
||||||
if segment.ident.name != keywords::PathRoot.name() {
|
if segment.ident.name != kw::PathRoot {
|
||||||
path_str.push_str(&segment.ident.as_str())
|
path_str.push_str(&segment.ident.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
attrs: krate.attrs,
|
attrs: krate.attrs,
|
||||||
span: krate.span,
|
span: krate.span,
|
||||||
node: ast::ItemKind::Mod(krate.module),
|
node: ast::ItemKind::Mod(krate.module),
|
||||||
ident: keywords::Invalid.ident(),
|
ident: Ident::with_empty_ctxt(kw::Invalid),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
|
vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
|
||||||
tokens: None,
|
tokens: None,
|
||||||
|
@ -708,7 +708,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
};
|
};
|
||||||
let path = &mac.node.path;
|
let path = &mac.node.path;
|
||||||
|
|
||||||
let ident = ident.unwrap_or_else(|| keywords::Invalid.ident());
|
let ident = ident.unwrap_or_else(|| Ident::with_empty_ctxt(kw::Invalid));
|
||||||
let validate_and_set_expn_info = |this: &mut Self, // arg instead of capture
|
let validate_and_set_expn_info = |this: &mut Self, // arg instead of capture
|
||||||
def_site_span: Option<Span>,
|
def_site_span: Option<Span>,
|
||||||
allow_internal_unstable,
|
allow_internal_unstable,
|
||||||
|
@ -736,7 +736,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ident.name != keywords::Invalid.name() {
|
if ident.name != kw::Invalid {
|
||||||
let msg = format!("macro {}! expects no ident argument, given '{}'", path, ident);
|
let msg = format!("macro {}! expects no ident argument, given '{}'", path, ident);
|
||||||
this.cx.span_err(path.span, &msg);
|
this.cx.span_err(path.span, &msg);
|
||||||
this.cx.trace_macros_diag();
|
this.cx.trace_macros_diag();
|
||||||
|
@ -792,7 +792,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentTT { ref expander, span: tt_span, ref allow_internal_unstable } => {
|
IdentTT { ref expander, span: tt_span, ref allow_internal_unstable } => {
|
||||||
if ident.name == keywords::Invalid.name() {
|
if ident.name == kw::Invalid {
|
||||||
self.cx.span_err(path.span,
|
self.cx.span_err(path.span,
|
||||||
&format!("macro {}! expects an ident argument", path));
|
&format!("macro {}! expects an ident argument", path));
|
||||||
self.cx.trace_macros_diag();
|
self.cx.trace_macros_diag();
|
||||||
|
@ -828,7 +828,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
SyntaxExtension::ProcMacro { ref expander, ref allow_internal_unstable, edition } => {
|
SyntaxExtension::ProcMacro { ref expander, ref allow_internal_unstable, edition } => {
|
||||||
if ident.name != keywords::Invalid.name() {
|
if ident.name != kw::Invalid {
|
||||||
let msg =
|
let msg =
|
||||||
format!("macro {}! expects no ident argument, given '{}'", path, ident);
|
format!("macro {}! expects no ident argument, given '{}'", path, ident);
|
||||||
self.cx.span_err(path.span, &msg);
|
self.cx.span_err(path.span, &msg);
|
||||||
|
@ -929,7 +929,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
invoc.expansion_data.mark.set_expn_info(expn_info);
|
invoc.expansion_data.mark.set_expn_info(expn_info);
|
||||||
let span = span.with_ctxt(self.cx.backtrace());
|
let span = span.with_ctxt(self.cx.backtrace());
|
||||||
let dummy = ast::MetaItem { // FIXME(jseyfried) avoid this
|
let dummy = ast::MetaItem { // FIXME(jseyfried) avoid this
|
||||||
path: Path::from_ident(keywords::Invalid.ident()),
|
path: Path::from_ident(Ident::with_empty_ctxt(kw::Invalid)),
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
node: ast::MetaItemKind::Word,
|
node: ast::MetaItemKind::Word,
|
||||||
};
|
};
|
||||||
|
@ -1338,7 +1338,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ast::ItemKind::Mod(ast::Mod { inner, .. }) => {
|
ast::ItemKind::Mod(ast::Mod { inner, .. }) => {
|
||||||
if item.ident == keywords::Invalid.ident() {
|
if item.ident == Ident::with_empty_ctxt(kw::Invalid) {
|
||||||
return noop_flat_map_item(item, self);
|
return noop_flat_map_item(item, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::ext::hygiene::Mark;
|
||||||
use crate::tokenstream::TokenStream;
|
use crate::tokenstream::TokenStream;
|
||||||
use crate::mut_visit::*;
|
use crate::mut_visit::*;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::keywords;
|
use crate::symbol::kw;
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
@ -22,7 +22,7 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let ident = keywords::Invalid.ident();
|
let ident = ast::Ident::with_empty_ctxt(kw::Invalid);
|
||||||
let attrs = Vec::new();
|
let attrs = Vec::new();
|
||||||
let generics = ast::Generics::default();
|
let generics = ast::Generics::default();
|
||||||
let vis = dummy_spanned(ast::VisibilityKind::Inherited);
|
let vis = dummy_spanned(ast::VisibilityKind::Inherited);
|
||||||
|
|
|
@ -80,7 +80,7 @@ use crate::parse::{Directory, ParseSess};
|
||||||
use crate::parse::parser::{Parser, PathStyle};
|
use crate::parse::parser::{Parser, PathStyle};
|
||||||
use crate::parse::token::{self, DocComment, Nonterminal, Token};
|
use crate::parse::token::{self, DocComment, Nonterminal, Token};
|
||||||
use crate::print::pprust;
|
use crate::print::pprust;
|
||||||
use crate::symbol::keywords;
|
use crate::symbol::kw;
|
||||||
use crate::tokenstream::{DelimSpan, TokenStream};
|
use crate::tokenstream::{DelimSpan, TokenStream};
|
||||||
|
|
||||||
use errors::FatalError;
|
use errors::FatalError;
|
||||||
|
@ -382,7 +382,7 @@ fn nameize<I: Iterator<Item = NamedMatch>>(
|
||||||
TokenTree::Delimited(_, ref delim) => for next_m in &delim.tts {
|
TokenTree::Delimited(_, ref delim) => for next_m in &delim.tts {
|
||||||
n_rec(sess, next_m, res.by_ref(), ret_val)?;
|
n_rec(sess, next_m, res.by_ref(), ret_val)?;
|
||||||
},
|
},
|
||||||
TokenTree::MetaVarDecl(span, _, id) if id.name == keywords::Invalid.name() => {
|
TokenTree::MetaVarDecl(span, _, id) if id.name == kw::Invalid => {
|
||||||
if sess.missing_fragment_specifiers.borrow_mut().remove(&span) {
|
if sess.missing_fragment_specifiers.borrow_mut().remove(&span) {
|
||||||
return Err((span, "missing fragment specifier".to_string()));
|
return Err((span, "missing fragment specifier".to_string()));
|
||||||
}
|
}
|
||||||
|
@ -587,7 +587,7 @@ fn inner_parse_loop<'root, 'tt>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to match a metavar (but the identifier is invalid)... this is an error
|
// We need to match a metavar (but the identifier is invalid)... this is an error
|
||||||
TokenTree::MetaVarDecl(span, _, id) if id.name == keywords::Invalid.name() => {
|
TokenTree::MetaVarDecl(span, _, id) if id.name == kw::Invalid => {
|
||||||
if sess.missing_fragment_specifiers.borrow_mut().remove(&span) {
|
if sess.missing_fragment_specifiers.borrow_mut().remove(&span) {
|
||||||
return Error(span, "missing fragment specifier".to_string());
|
return Error(span, "missing fragment specifier".to_string());
|
||||||
}
|
}
|
||||||
|
@ -802,7 +802,7 @@ pub fn parse(
|
||||||
/// We prohibit passing `_` to macros expecting `ident` for now.
|
/// We prohibit passing `_` to macros expecting `ident` for now.
|
||||||
fn get_macro_ident(token: &Token) -> Option<(Ident, bool)> {
|
fn get_macro_ident(token: &Token) -> Option<(Ident, bool)> {
|
||||||
match *token {
|
match *token {
|
||||||
token::Ident(ident, is_raw) if ident.name != keywords::Underscore.name() =>
|
token::Ident(ident, is_raw) if ident.name != kw::Underscore =>
|
||||||
Some((ident, is_raw)),
|
Some((ident, is_raw)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1107,7 +1107,7 @@ fn is_in_follow(tok: "ed::TokenTree, frag: &str) -> IsInFollow {
|
||||||
_ => IsInFollow::No(tokens),
|
_ => IsInFollow::No(tokens),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"" => IsInFollow::Yes, // keywords::Invalid
|
"" => IsInFollow::Yes, // kw::Invalid
|
||||||
_ => IsInFollow::Invalid(format!("invalid fragment specifier `{}`", frag),
|
_ => IsInFollow::Invalid(format!("invalid fragment specifier `{}`", frag),
|
||||||
VALID_FRAGMENT_NAMES_MSG),
|
VALID_FRAGMENT_NAMES_MSG),
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::parse::{token, ParseSess};
|
||||||
use crate::print::pprust;
|
use crate::print::pprust;
|
||||||
use crate::tokenstream::{self, DelimSpan};
|
use crate::tokenstream::{self, DelimSpan};
|
||||||
use crate::ast;
|
use crate::ast;
|
||||||
use crate::symbol::keywords;
|
use crate::symbol::kw;
|
||||||
|
|
||||||
use syntax_pos::{edition::Edition, BytePos, Span};
|
use syntax_pos::{edition::Edition, BytePos, Span};
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ pub fn parse(
|
||||||
result.push(TokenTree::MetaVarDecl(
|
result.push(TokenTree::MetaVarDecl(
|
||||||
span,
|
span,
|
||||||
ident,
|
ident,
|
||||||
keywords::Invalid.ident(),
|
ast::Ident::with_empty_ctxt(kw::Invalid),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,8 +319,8 @@ where
|
||||||
Some(tokenstream::TokenTree::Token(ident_span, ref token)) if token.is_ident() => {
|
Some(tokenstream::TokenTree::Token(ident_span, ref token)) if token.is_ident() => {
|
||||||
let (ident, is_raw) = token.ident().unwrap();
|
let (ident, is_raw) = token.ident().unwrap();
|
||||||
let span = ident_span.with_lo(span.lo());
|
let span = ident_span.with_lo(span.lo());
|
||||||
if ident.name == keywords::Crate.name() && !is_raw {
|
if ident.name == kw::Crate && !is_raw {
|
||||||
let ident = ast::Ident::new(keywords::DollarCrate.name(), ident.span);
|
let ident = ast::Ident::new(kw::DollarCrate, ident.span);
|
||||||
TokenTree::Token(span, token::Ident(ident, is_raw))
|
TokenTree::Token(span, token::Ident(ident, is_raw))
|
||||||
} else {
|
} else {
|
||||||
TokenTree::MetaVar(span, ident)
|
TokenTree::MetaVar(span, ident)
|
||||||
|
@ -334,7 +334,7 @@ where
|
||||||
pprust::token_to_string(&tok)
|
pprust::token_to_string(&tok)
|
||||||
);
|
);
|
||||||
sess.span_diagnostic.span_err(span, &msg);
|
sess.span_diagnostic.span_err(span, &msg);
|
||||||
TokenTree::MetaVar(span, keywords::Invalid.ident())
|
TokenTree::MetaVar(span, ast::Ident::with_empty_ctxt(kw::Invalid))
|
||||||
}
|
}
|
||||||
|
|
||||||
// There are no more tokens. Just return the `$` we already have.
|
// There are no more tokens. Just return the `$` we already have.
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::ast::*;
|
||||||
use crate::source_map::{Spanned, respan};
|
use crate::source_map::{Spanned, respan};
|
||||||
use crate::parse::token::{self, Token};
|
use crate::parse::token::{self, Token};
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::keywords;
|
use crate::symbol::kw;
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
use crate::tokenstream::*;
|
use crate::tokenstream::*;
|
||||||
use crate::util::map_in_place::MapInPlace;
|
use crate::util::map_in_place::MapInPlace;
|
||||||
|
@ -977,7 +977,7 @@ pub fn noop_visit_mod<T: MutVisitor>(Mod { inner, items, inline: _ }: &mut Mod,
|
||||||
pub fn noop_visit_crate<T: MutVisitor>(krate: &mut Crate, vis: &mut T) {
|
pub fn noop_visit_crate<T: MutVisitor>(krate: &mut Crate, vis: &mut T) {
|
||||||
visit_clobber(krate, |Crate { module, attrs, span }| {
|
visit_clobber(krate, |Crate { module, attrs, span }| {
|
||||||
let item = P(Item {
|
let item = P(Item {
|
||||||
ident: keywords::Invalid.ident(),
|
ident: Ident::with_empty_ctxt(kw::Invalid),
|
||||||
attrs,
|
attrs,
|
||||||
id: DUMMY_NODE_ID,
|
id: DUMMY_NODE_ID,
|
||||||
vis: respan(span.shrink_to_lo(), VisibilityKind::Public),
|
vis: respan(span.shrink_to_lo(), VisibilityKind::Public),
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::parse::PResult;
|
||||||
use crate::parse::token::{self, Token};
|
use crate::parse::token::{self, Token};
|
||||||
use crate::parse::unescape::{unescape_str, unescape_char, unescape_byte_str, unescape_byte};
|
use crate::parse::unescape::{unescape_str, unescape_char, unescape_byte_str, unescape_byte};
|
||||||
use crate::print::pprust;
|
use crate::print::pprust;
|
||||||
use crate::symbol::{keywords, Symbol};
|
use crate::symbol::{kw, Symbol};
|
||||||
use crate::tokenstream::{TokenStream, TokenTree};
|
use crate::tokenstream::{TokenStream, TokenTree};
|
||||||
|
|
||||||
use errors::{Applicability, Handler};
|
use errors::{Applicability, Handler};
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -8,7 +8,7 @@ use crate::ast::{self};
|
||||||
use crate::parse::ParseSess;
|
use crate::parse::ParseSess;
|
||||||
use crate::print::pprust;
|
use crate::print::pprust;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::keywords;
|
use crate::symbol::kw;
|
||||||
use crate::syntax::parse::parse_stream_from_source_str;
|
use crate::syntax::parse::parse_stream_from_source_str;
|
||||||
use crate::tokenstream::{self, DelimSpan, TokenStream, TokenTree};
|
use crate::tokenstream::{self, DelimSpan, TokenStream, TokenTree};
|
||||||
|
|
||||||
|
@ -110,28 +110,28 @@ pub(crate) fn ident_can_begin_expr(ident: ast::Ident, is_raw: bool) -> bool {
|
||||||
!ident_token.is_reserved_ident() ||
|
!ident_token.is_reserved_ident() ||
|
||||||
ident_token.is_path_segment_keyword() ||
|
ident_token.is_path_segment_keyword() ||
|
||||||
[
|
[
|
||||||
keywords::Async.name(),
|
kw::Async,
|
||||||
|
|
||||||
// FIXME: remove when `await!(..)` syntax is removed
|
// FIXME: remove when `await!(..)` syntax is removed
|
||||||
// https://github.com/rust-lang/rust/issues/60610
|
// https://github.com/rust-lang/rust/issues/60610
|
||||||
keywords::Await.name(),
|
kw::Await,
|
||||||
|
|
||||||
keywords::Do.name(),
|
kw::Do,
|
||||||
keywords::Box.name(),
|
kw::Box,
|
||||||
keywords::Break.name(),
|
kw::Break,
|
||||||
keywords::Continue.name(),
|
kw::Continue,
|
||||||
keywords::False.name(),
|
kw::False,
|
||||||
keywords::For.name(),
|
kw::For,
|
||||||
keywords::If.name(),
|
kw::If,
|
||||||
keywords::Loop.name(),
|
kw::Loop,
|
||||||
keywords::Match.name(),
|
kw::Match,
|
||||||
keywords::Move.name(),
|
kw::Move,
|
||||||
keywords::Return.name(),
|
kw::Return,
|
||||||
keywords::True.name(),
|
kw::True,
|
||||||
keywords::Unsafe.name(),
|
kw::Unsafe,
|
||||||
keywords::While.name(),
|
kw::While,
|
||||||
keywords::Yield.name(),
|
kw::Yield,
|
||||||
keywords::Static.name(),
|
kw::Static,
|
||||||
].contains(&ident.name)
|
].contains(&ident.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,14 +141,14 @@ fn ident_can_begin_type(ident: ast::Ident, is_raw: bool) -> bool {
|
||||||
!ident_token.is_reserved_ident() ||
|
!ident_token.is_reserved_ident() ||
|
||||||
ident_token.is_path_segment_keyword() ||
|
ident_token.is_path_segment_keyword() ||
|
||||||
[
|
[
|
||||||
keywords::Underscore.name(),
|
kw::Underscore,
|
||||||
keywords::For.name(),
|
kw::For,
|
||||||
keywords::Impl.name(),
|
kw::Impl,
|
||||||
keywords::Fn.name(),
|
kw::Fn,
|
||||||
keywords::Unsafe.name(),
|
kw::Unsafe,
|
||||||
keywords::Extern.name(),
|
kw::Extern,
|
||||||
keywords::Typeof.name(),
|
kw::Typeof,
|
||||||
keywords::Dyn.name(),
|
kw::Dyn,
|
||||||
].contains(&ident.name)
|
].contains(&ident.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,7 +306,7 @@ impl Token {
|
||||||
|
|
||||||
/// Returns `true` if the token can appear at the start of a generic bound.
|
/// Returns `true` if the token can appear at the start of a generic bound.
|
||||||
crate fn can_begin_bound(&self) -> bool {
|
crate fn can_begin_bound(&self) -> bool {
|
||||||
self.is_path_start() || self.is_lifetime() || self.is_keyword(keywords::For) ||
|
self.is_path_start() || self.is_lifetime() || self.is_keyword(kw::For) ||
|
||||||
self == &Question || self == &OpenDelim(Paren)
|
self == &Question || self == &OpenDelim(Paren)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,8 +324,8 @@ impl Token {
|
||||||
match *self {
|
match *self {
|
||||||
Literal(..) => true,
|
Literal(..) => true,
|
||||||
BinOp(Minus) => true,
|
BinOp(Minus) => true,
|
||||||
Ident(ident, false) if ident.name == keywords::True.name() => true,
|
Ident(ident, false) if ident.name == kw::True => true,
|
||||||
Ident(ident, false) if ident.name == keywords::False.name() => true,
|
Ident(ident, false) if ident.name == kw::False => true,
|
||||||
Interpolated(ref nt) => match **nt {
|
Interpolated(ref nt) => match **nt {
|
||||||
NtLiteral(..) => true,
|
NtLiteral(..) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -386,8 +386,8 @@ impl Token {
|
||||||
|
|
||||||
/// Returns `true` if the token is either the `mut` or `const` keyword.
|
/// Returns `true` if the token is either the `mut` or `const` keyword.
|
||||||
crate fn is_mutability(&self) -> bool {
|
crate fn is_mutability(&self) -> bool {
|
||||||
self.is_keyword(keywords::Mut) ||
|
self.is_keyword(kw::Mut) ||
|
||||||
self.is_keyword(keywords::Const)
|
self.is_keyword(kw::Const)
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn is_qpath_start(&self) -> bool {
|
crate fn is_qpath_start(&self) -> bool {
|
||||||
|
@ -400,8 +400,8 @@ impl Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the token is a given keyword, `kw`.
|
/// Returns `true` if the token is a given keyword, `kw`.
|
||||||
pub fn is_keyword(&self, kw: keywords::Keyword) -> bool {
|
pub fn is_keyword(&self, kw: Symbol) -> bool {
|
||||||
self.ident().map(|(ident, is_raw)| ident.name == kw.name() && !is_raw).unwrap_or(false)
|
self.ident().map(|(ident, is_raw)| ident.name == kw && !is_raw).unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_path_segment_keyword(&self) -> bool {
|
pub fn is_path_segment_keyword(&self) -> bool {
|
||||||
|
@ -566,8 +566,8 @@ impl Token {
|
||||||
|
|
||||||
(&Lifetime(a), &Lifetime(b)) => a.name == b.name,
|
(&Lifetime(a), &Lifetime(b)) => a.name == b.name,
|
||||||
(&Ident(a, b), &Ident(c, d)) => b == d && (a.name == c.name ||
|
(&Ident(a, b), &Ident(c, d)) => b == d && (a.name == c.name ||
|
||||||
a.name == keywords::DollarCrate.name() ||
|
a.name == kw::DollarCrate ||
|
||||||
c.name == keywords::DollarCrate.name()),
|
c.name == kw::DollarCrate),
|
||||||
|
|
||||||
(&Literal(ref a, b), &Literal(ref c, d)) => {
|
(&Literal(ref a, b), &Literal(ref c, d)) => {
|
||||||
b == d && a.probably_equal_for_proc_macro(c)
|
b == d && a.probably_equal_for_proc_macro(c)
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::print::pp::{self, Breaks};
|
||||||
use crate::print::pp::Breaks::{Consistent, Inconsistent};
|
use crate::print::pp::Breaks::{Consistent, Inconsistent};
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::std_inject;
|
use crate::std_inject;
|
||||||
use crate::symbol::{keywords, sym};
|
use crate::symbol::{kw, sym};
|
||||||
use crate::tokenstream::{self, TokenStream, TokenTree};
|
use crate::tokenstream::{self, TokenStream, TokenTree};
|
||||||
|
|
||||||
use rustc_target::spec::abi::{self, Abi};
|
use rustc_target::spec::abi::{self, Abi};
|
||||||
|
@ -641,8 +641,8 @@ pub trait PrintState<'a> {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
self.writer().word("::")?
|
self.writer().word("::")?
|
||||||
}
|
}
|
||||||
if segment.ident.name != keywords::PathRoot.name() {
|
if segment.ident.name != kw::PathRoot {
|
||||||
if segment.ident.name == keywords::DollarCrate.name() {
|
if segment.ident.name == kw::DollarCrate {
|
||||||
self.print_dollar_crate(segment.ident)?;
|
self.print_dollar_crate(segment.ident)?;
|
||||||
} else {
|
} else {
|
||||||
self.writer().word(segment.ident.as_str().to_string())?;
|
self.writer().word(segment.ident.as_str().to_string())?;
|
||||||
|
@ -1340,7 +1340,7 @@ impl<'a> State<'a> {
|
||||||
self.s.word(";")?;
|
self.s.word(";")?;
|
||||||
}
|
}
|
||||||
ast::ItemKind::Mac(ref mac) => {
|
ast::ItemKind::Mac(ref mac) => {
|
||||||
if item.ident.name == keywords::Invalid.name() {
|
if item.ident.name == kw::Invalid {
|
||||||
self.print_mac(mac)?;
|
self.print_mac(mac)?;
|
||||||
match mac.node.delim {
|
match mac.node.delim {
|
||||||
MacDelimiter::Brace => {}
|
MacDelimiter::Brace => {}
|
||||||
|
@ -2400,8 +2400,8 @@ impl<'a> State<'a> {
|
||||||
colons_before_params: bool)
|
colons_before_params: bool)
|
||||||
-> io::Result<()>
|
-> io::Result<()>
|
||||||
{
|
{
|
||||||
if segment.ident.name != keywords::PathRoot.name() {
|
if segment.ident.name != kw::PathRoot {
|
||||||
if segment.ident.name == keywords::DollarCrate.name() {
|
if segment.ident.name == kw::DollarCrate {
|
||||||
self.print_dollar_crate(segment.ident)?;
|
self.print_dollar_crate(segment.ident)?;
|
||||||
} else {
|
} else {
|
||||||
self.print_ident(segment.ident)?;
|
self.print_ident(segment.ident)?;
|
||||||
|
@ -2984,7 +2984,7 @@ impl<'a> State<'a> {
|
||||||
self.print_explicit_self(&eself)?;
|
self.print_explicit_self(&eself)?;
|
||||||
} else {
|
} else {
|
||||||
let invalid = if let PatKind::Ident(_, ident, _) = input.pat.node {
|
let invalid = if let PatKind::Ident(_, ident, _) = input.pat.node {
|
||||||
ident.name == keywords::Invalid.name()
|
ident.name == kw::Invalid
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::ast;
|
||||||
use crate::attr;
|
use crate::attr;
|
||||||
use crate::edition::Edition;
|
use crate::edition::Edition;
|
||||||
use crate::ext::hygiene::{Mark, SyntaxContext};
|
use crate::ext::hygiene::{Mark, SyntaxContext};
|
||||||
use crate::symbol::{Ident, Symbol, keywords, sym};
|
use crate::symbol::{Ident, Symbol, kw, sym};
|
||||||
use crate::source_map::{ExpnInfo, MacroAttribute, dummy_spanned, respan};
|
use crate::source_map::{ExpnInfo, MacroAttribute, dummy_spanned, respan};
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::tokenstream::TokenStream;
|
use crate::tokenstream::TokenStream;
|
||||||
|
@ -107,7 +107,7 @@ pub fn maybe_inject_crates_ref(
|
||||||
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
|
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
|
||||||
node: ast::ItemKind::Use(P(ast::UseTree {
|
node: ast::ItemKind::Use(P(ast::UseTree {
|
||||||
prefix: ast::Path {
|
prefix: ast::Path {
|
||||||
segments: iter::once(keywords::PathRoot.ident())
|
segments: iter::once(ast::Ident::with_empty_ctxt(kw::PathRoot))
|
||||||
.chain(
|
.chain(
|
||||||
[name, "prelude", "v1"].iter().cloned()
|
[name, "prelude", "v1"].iter().cloned()
|
||||||
.map(ast::Ident::from_str)
|
.map(ast::Ident::from_str)
|
||||||
|
@ -118,7 +118,7 @@ pub fn maybe_inject_crates_ref(
|
||||||
span,
|
span,
|
||||||
})),
|
})),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
ident: keywords::Invalid.ident(),
|
ident: ast::Ident::with_empty_ctxt(kw::Invalid),
|
||||||
span,
|
span,
|
||||||
tokens: None,
|
tokens: None,
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -29,7 +29,7 @@ use crate::parse::{token, ParseSess};
|
||||||
use crate::print::pprust;
|
use crate::print::pprust;
|
||||||
use crate::ast::{self, Ident};
|
use crate::ast::{self, Ident};
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::{self, Symbol, keywords, sym};
|
use crate::symbol::{self, Symbol, kw, sym};
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
|
|
||||||
struct Test {
|
struct Test {
|
||||||
|
@ -100,7 +100,7 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
|
||||||
|
|
||||||
fn flat_map_item(&mut self, i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
|
fn flat_map_item(&mut self, i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
|
||||||
let ident = i.ident;
|
let ident = i.ident;
|
||||||
if ident.name != keywords::Invalid.name() {
|
if ident.name != kw::Invalid {
|
||||||
self.cx.path.push(ident);
|
self.cx.path.push(ident);
|
||||||
}
|
}
|
||||||
debug!("current path: {}", path_name_i(&self.cx.path));
|
debug!("current path: {}", path_name_i(&self.cx.path));
|
||||||
|
@ -139,7 +139,7 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
|
||||||
}
|
}
|
||||||
item.node = ast::ItemKind::Mod(module);
|
item.node = ast::ItemKind::Mod(module);
|
||||||
}
|
}
|
||||||
if ident.name != keywords::Invalid.name() {
|
if ident.name != kw::Invalid {
|
||||||
self.cx.path.pop();
|
self.cx.path.pop();
|
||||||
}
|
}
|
||||||
smallvec![P(item)]
|
smallvec![P(item)]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::parse::token::{Token, BinOpToken};
|
use crate::parse::token::{Token, BinOpToken};
|
||||||
use crate::symbol::keywords;
|
use crate::symbol::kw;
|
||||||
use crate::ast::{self, BinOpKind};
|
use crate::ast::{self, BinOpKind};
|
||||||
|
|
||||||
/// Associative operator with precedence.
|
/// Associative operator with precedence.
|
||||||
|
@ -100,7 +100,7 @@ impl AssocOp {
|
||||||
// DotDotDot is no longer supported, but we need some way to display the error
|
// DotDotDot is no longer supported, but we need some way to display the error
|
||||||
Token::DotDotDot => Some(DotDotEq),
|
Token::DotDotDot => Some(DotDotEq),
|
||||||
Token::Colon => Some(Colon),
|
Token::Colon => Some(Colon),
|
||||||
_ if t.is_keyword(keywords::As) => Some(As),
|
_ if t.is_keyword(kw::As) => Some(As),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use syntax::attr;
|
||||||
use syntax::ext::base::{Annotatable, ExtCtxt};
|
use syntax::ext::base::{Annotatable, ExtCtxt};
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::{Symbol, keywords, sym};
|
use syntax::symbol::{Symbol, kw, sym};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
|
||||||
pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
|
pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
|
||||||
|
@ -129,7 +129,8 @@ fn cs_clone_shallow(name: &str,
|
||||||
let mut stmts = Vec::new();
|
let mut stmts = Vec::new();
|
||||||
if is_union {
|
if is_union {
|
||||||
// let _: AssertParamIsCopy<Self>;
|
// let _: AssertParamIsCopy<Self>;
|
||||||
let self_ty = cx.ty_path(cx.path_ident(trait_span, keywords::SelfUpper.ident()));
|
let self_ty =
|
||||||
|
cx.ty_path(cx.path_ident(trait_span, ast::Ident::with_empty_ctxt(kw::SelfUpper)));
|
||||||
assert_ty_bounds(cx, &mut stmts, self_ty, trait_span, "AssertParamIsCopy");
|
assert_ty_bounds(cx, &mut stmts, self_ty, trait_span, "AssertParamIsCopy");
|
||||||
} else {
|
} else {
|
||||||
match *substr.fields {
|
match *substr.fields {
|
||||||
|
|
|
@ -191,7 +191,7 @@ use syntax::ext::build::AstBuilder;
|
||||||
use syntax::source_map::{self, respan};
|
use syntax::source_map::{self, respan};
|
||||||
use syntax::util::map_in_place::MapInPlace;
|
use syntax::util::map_in_place::MapInPlace;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::{Symbol, keywords, sym};
|
use syntax::symbol::{Symbol, kw, sym};
|
||||||
use syntax::parse::ParseSess;
|
use syntax::parse::ParseSess;
|
||||||
use syntax_pos::{DUMMY_SP, Span};
|
use syntax_pos::{DUMMY_SP, Span};
|
||||||
|
|
||||||
|
@ -686,7 +686,7 @@ impl<'a> TraitDef<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
cx.item(self.span,
|
cx.item(self.span,
|
||||||
keywords::Invalid.ident(),
|
Ident::with_empty_ctxt(kw::Invalid),
|
||||||
a,
|
a,
|
||||||
ast::ItemKind::Impl(unsafety,
|
ast::ItemKind::Impl(unsafety,
|
||||||
ast::ImplPolarity::Positive,
|
ast::ImplPolarity::Positive,
|
||||||
|
@ -929,8 +929,8 @@ impl<'a> MethodDef<'a> {
|
||||||
|
|
||||||
let args = {
|
let args = {
|
||||||
let self_args = explicit_self.map(|explicit_self| {
|
let self_args = explicit_self.map(|explicit_self| {
|
||||||
ast::Arg::from_self(explicit_self,
|
let ident = Ident::with_empty_ctxt(kw::SelfLower).with_span_pos(trait_.span);
|
||||||
keywords::SelfLower.ident().with_span_pos(trait_.span))
|
ast::Arg::from_self(explicit_self, ident)
|
||||||
});
|
});
|
||||||
let nonself_args = arg_types.into_iter()
|
let nonself_args = arg_types.into_iter()
|
||||||
.map(|(name, ty)| cx.arg(trait_.span, name, ty));
|
.map(|(name, ty)| cx.arg(trait_.span, name, ty));
|
||||||
|
|
|
@ -10,7 +10,7 @@ use syntax::ext::build::AstBuilder;
|
||||||
use syntax::source_map::{respan, DUMMY_SP};
|
use syntax::source_map::{respan, DUMMY_SP};
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use syntax_pos::symbol::keywords;
|
use syntax_pos::symbol::kw;
|
||||||
|
|
||||||
/// The types of pointers
|
/// The types of pointers
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -86,7 +86,7 @@ impl<'a> Path<'a> {
|
||||||
PathKind::Local => cx.path_all(span, false, idents, params, Vec::new()),
|
PathKind::Local => cx.path_all(span, false, idents, params, Vec::new()),
|
||||||
PathKind::Std => {
|
PathKind::Std => {
|
||||||
let def_site = DUMMY_SP.apply_mark(cx.current_expansion.mark);
|
let def_site = DUMMY_SP.apply_mark(cx.current_expansion.mark);
|
||||||
idents.insert(0, Ident::new(keywords::DollarCrate.name(), def_site));
|
idents.insert(0, Ident::new(kw::DollarCrate, def_site));
|
||||||
cx.path_all(span, false, idents, params, Vec::new())
|
cx.path_all(span, false, idents, params, Vec::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
use syntax::ast::{self, Ident, GenericArg};
|
use syntax::ast::{self, Ident, GenericArg};
|
||||||
use syntax::ext::base::{self, *};
|
use syntax::ext::base::{self, *};
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax::symbol::{keywords, Symbol, sym};
|
use syntax::symbol::{kw, sym, Symbol};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use syntax::tokenstream;
|
use syntax::tokenstream;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
|
||||||
let sp = sp.apply_mark(cx.current_expansion.mark);
|
let sp = sp.apply_mark(cx.current_expansion.mark);
|
||||||
let e = match env::var(&*var.as_str()) {
|
let e = match env::var(&*var.as_str()) {
|
||||||
Err(..) => {
|
Err(..) => {
|
||||||
let lt = cx.lifetime(sp, keywords::StaticLifetime.ident());
|
let lt = cx.lifetime(sp, Ident::with_empty_ctxt(kw::StaticLifetime));
|
||||||
cx.expr_path(cx.path_all(sp,
|
cx.expr_path(cx.path_all(sp,
|
||||||
true,
|
true,
|
||||||
cx.std_path(&["option", "Option", "None"]),
|
cx.std_path(&["option", "Option", "None"]),
|
||||||
|
|
|
@ -13,7 +13,7 @@ use syntax::mut_visit::MutVisitor;
|
||||||
use syntax::parse::ParseSess;
|
use syntax::parse::ParseSess;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
use syntax::symbol::{keywords, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax::visit::{self, Visitor};
|
use syntax::visit::{self, Visitor};
|
||||||
|
|
||||||
use syntax_pos::{Span, DUMMY_SP};
|
use syntax_pos::{Span, DUMMY_SP};
|
||||||
|
@ -378,7 +378,7 @@ fn mk_decls(
|
||||||
let custom_derive = Ident::from_str("custom_derive");
|
let custom_derive = Ident::from_str("custom_derive");
|
||||||
let attr = Ident::from_str("attr");
|
let attr = Ident::from_str("attr");
|
||||||
let bang = Ident::from_str("bang");
|
let bang = Ident::from_str("bang");
|
||||||
let crate_kw = Ident::with_empty_ctxt(keywords::Crate.name());
|
let crate_kw = Ident::with_empty_ctxt(kw::Crate);
|
||||||
|
|
||||||
let decls = {
|
let decls = {
|
||||||
let local_path = |sp: Span, name| {
|
let local_path = |sp: Span, name| {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use syntax::parse::lexer::comments;
|
||||||
use syntax::parse::{self, token, ParseSess};
|
use syntax::parse::{self, token, ParseSess};
|
||||||
use syntax::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
|
use syntax::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
|
||||||
use syntax_pos::hygiene::{SyntaxContext, Transparency};
|
use syntax_pos::hygiene::{SyntaxContext, Transparency};
|
||||||
use syntax_pos::symbol::{keywords, Symbol};
|
use syntax_pos::symbol::{kw, Symbol};
|
||||||
use syntax_pos::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span};
|
use syntax_pos::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span};
|
||||||
|
|
||||||
trait FromInternal<T> {
|
trait FromInternal<T> {
|
||||||
|
@ -142,7 +142,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
|
||||||
Question => op!('?'),
|
Question => op!('?'),
|
||||||
SingleQuote => op!('\''),
|
SingleQuote => op!('\''),
|
||||||
|
|
||||||
Ident(ident, false) if ident.name == keywords::DollarCrate.name() =>
|
Ident(ident, false) if ident.name == kw::DollarCrate =>
|
||||||
tt!(Ident::dollar_crate()),
|
tt!(Ident::dollar_crate()),
|
||||||
Ident(ident, is_raw) => tt!(Ident::new(ident.name, is_raw)),
|
Ident(ident, is_raw) => tt!(Ident::new(ident.name, is_raw)),
|
||||||
Lifetime(ident) => {
|
Lifetime(ident) => {
|
||||||
|
@ -347,7 +347,7 @@ impl Ident {
|
||||||
}
|
}
|
||||||
fn dollar_crate(span: Span) -> Ident {
|
fn dollar_crate(span: Span) -> Ident {
|
||||||
// `$crate` is accepted as an ident only if it comes from the compiler.
|
// `$crate` is accepted as an ident only if it comes from the compiler.
|
||||||
Ident { sym: keywords::DollarCrate.name(), is_raw: false, span }
|
Ident { sym: kw::DollarCrate, is_raw: false, span }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use syntax::ext::base::{self, ExtCtxt};
|
use syntax::ext::base::{self, ExtCtxt};
|
||||||
use syntax::feature_gate;
|
use syntax::feature_gate;
|
||||||
use syntax::symbol::{keywords, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use syntax::tokenstream::TokenTree;
|
use syntax::tokenstream::TokenTree;
|
||||||
|
|
||||||
|
@ -17,10 +17,10 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt<'_>,
|
||||||
}
|
}
|
||||||
|
|
||||||
match (tt.len(), tt.first()) {
|
match (tt.len(), tt.first()) {
|
||||||
(1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(keywords::True) => {
|
(1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(kw::True) => {
|
||||||
cx.set_trace_macros(true);
|
cx.set_trace_macros(true);
|
||||||
}
|
}
|
||||||
(1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(keywords::False) => {
|
(1, Some(&TokenTree::Token(_, ref tok))) if tok.is_keyword(kw::False) => {
|
||||||
cx.set_trace_macros(false);
|
cx.set_trace_macros(false);
|
||||||
}
|
}
|
||||||
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),
|
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
use crate::GLOBALS;
|
use crate::GLOBALS;
|
||||||
use crate::Span;
|
use crate::Span;
|
||||||
use crate::edition::Edition;
|
use crate::edition::Edition;
|
||||||
use crate::symbol::{keywords, Symbol};
|
use crate::symbol::{kw, Symbol};
|
||||||
|
|
||||||
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
|
@ -192,7 +192,7 @@ impl HygieneData {
|
||||||
prev_ctxt: SyntaxContext(0),
|
prev_ctxt: SyntaxContext(0),
|
||||||
opaque: SyntaxContext(0),
|
opaque: SyntaxContext(0),
|
||||||
opaque_and_semitransparent: SyntaxContext(0),
|
opaque_and_semitransparent: SyntaxContext(0),
|
||||||
dollar_crate_name: keywords::DollarCrate.name(),
|
dollar_crate_name: kw::DollarCrate,
|
||||||
}],
|
}],
|
||||||
markings: FxHashMap::default(),
|
markings: FxHashMap::default(),
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ impl SyntaxContext {
|
||||||
prev_ctxt: SyntaxContext::empty(),
|
prev_ctxt: SyntaxContext::empty(),
|
||||||
opaque: SyntaxContext::empty(),
|
opaque: SyntaxContext::empty(),
|
||||||
opaque_and_semitransparent: SyntaxContext::empty(),
|
opaque_and_semitransparent: SyntaxContext::empty(),
|
||||||
dollar_crate_name: keywords::DollarCrate.name(),
|
dollar_crate_name: kw::DollarCrate,
|
||||||
});
|
});
|
||||||
SyntaxContext(data.syntax_contexts.len() as u32 - 1)
|
SyntaxContext(data.syntax_contexts.len() as u32 - 1)
|
||||||
})
|
})
|
||||||
|
@ -312,7 +312,7 @@ impl SyntaxContext {
|
||||||
prev_ctxt,
|
prev_ctxt,
|
||||||
opaque: new_opaque,
|
opaque: new_opaque,
|
||||||
opaque_and_semitransparent: new_opaque,
|
opaque_and_semitransparent: new_opaque,
|
||||||
dollar_crate_name: keywords::DollarCrate.name(),
|
dollar_crate_name: kw::DollarCrate,
|
||||||
});
|
});
|
||||||
new_opaque
|
new_opaque
|
||||||
});
|
});
|
||||||
|
@ -330,7 +330,7 @@ impl SyntaxContext {
|
||||||
prev_ctxt,
|
prev_ctxt,
|
||||||
opaque,
|
opaque,
|
||||||
opaque_and_semitransparent: new_opaque_and_semitransparent,
|
opaque_and_semitransparent: new_opaque_and_semitransparent,
|
||||||
dollar_crate_name: keywords::DollarCrate.name(),
|
dollar_crate_name: kw::DollarCrate,
|
||||||
});
|
});
|
||||||
new_opaque_and_semitransparent
|
new_opaque_and_semitransparent
|
||||||
});
|
});
|
||||||
|
@ -346,7 +346,7 @@ impl SyntaxContext {
|
||||||
prev_ctxt,
|
prev_ctxt,
|
||||||
opaque,
|
opaque,
|
||||||
opaque_and_semitransparent,
|
opaque_and_semitransparent,
|
||||||
dollar_crate_name: keywords::DollarCrate.name(),
|
dollar_crate_name: kw::DollarCrate,
|
||||||
});
|
});
|
||||||
new_opaque_and_semitransparent_and_transparent
|
new_opaque_and_semitransparent_and_transparent
|
||||||
})
|
})
|
||||||
|
@ -512,7 +512,7 @@ impl SyntaxContext {
|
||||||
&mut data.syntax_contexts[self.0 as usize].dollar_crate_name, dollar_crate_name
|
&mut data.syntax_contexts[self.0 as usize].dollar_crate_name, dollar_crate_name
|
||||||
);
|
);
|
||||||
assert!(dollar_crate_name == prev_dollar_crate_name ||
|
assert!(dollar_crate_name == prev_dollar_crate_name ||
|
||||||
prev_dollar_crate_name == keywords::DollarCrate.name(),
|
prev_dollar_crate_name == kw::DollarCrate,
|
||||||
"$crate name is reset for a syntax context");
|
"$crate name is reset for a syntax context");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -692,7 +692,7 @@ impl Ident {
|
||||||
/// Transforms an underscore identifier into one with the same name, but
|
/// Transforms an underscore identifier into one with the same name, but
|
||||||
/// gensymed. Leaves non-underscore identifiers unchanged.
|
/// gensymed. Leaves non-underscore identifiers unchanged.
|
||||||
pub fn gensym_if_underscore(self) -> Ident {
|
pub fn gensym_if_underscore(self) -> Ident {
|
||||||
if self.name == keywords::Underscore.name() { self.gensym() } else { self }
|
if self.name == kw::Underscore { self.gensym() } else { self }
|
||||||
}
|
}
|
||||||
|
|
||||||
// WARNING: this function is deprecated and will be removed in the future.
|
// WARNING: this function is deprecated and will be removed in the future.
|
||||||
|
@ -864,8 +864,8 @@ impl Interner {
|
||||||
this.strings.reserve(init.len());
|
this.strings.reserve(init.len());
|
||||||
|
|
||||||
// We can't allocate empty strings in the arena, so handle this here.
|
// We can't allocate empty strings in the arena, so handle this here.
|
||||||
assert!(keywords::Invalid.name().as_u32() == 0 && init[0].is_empty());
|
assert!(kw::Invalid.as_u32() == 0 && init[0].is_empty());
|
||||||
this.names.insert("", keywords::Invalid.name());
|
this.names.insert("", kw::Invalid);
|
||||||
this.strings.push("");
|
this.strings.push("");
|
||||||
|
|
||||||
for string in &init[1..] {
|
for string in &init[1..] {
|
||||||
|
@ -926,26 +926,9 @@ impl Interner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod keywords {
|
// This module has a very short name because it's used a lot.
|
||||||
use super::{Symbol, Ident};
|
pub mod kw {
|
||||||
|
use super::Symbol;
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub struct Keyword {
|
|
||||||
ident: Ident,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Keyword {
|
|
||||||
#[inline]
|
|
||||||
pub fn ident(self) -> Ident {
|
|
||||||
self.ident
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn name(self) -> Symbol {
|
|
||||||
self.ident.name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keywords!();
|
keywords!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -957,11 +940,11 @@ pub mod sym {
|
||||||
|
|
||||||
impl Symbol {
|
impl Symbol {
|
||||||
fn is_used_keyword_2018(self) -> bool {
|
fn is_used_keyword_2018(self) -> bool {
|
||||||
self == keywords::Dyn.name()
|
self == kw::Dyn
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_unused_keyword_2018(self) -> bool {
|
fn is_unused_keyword_2018(self) -> bool {
|
||||||
self >= keywords::Async.name() && self <= keywords::Try.name()
|
self >= kw::Async && self <= kw::Try
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -969,20 +952,20 @@ impl Ident {
|
||||||
// Returns `true` for reserved identifiers used internally for elided lifetimes,
|
// Returns `true` for reserved identifiers used internally for elided lifetimes,
|
||||||
// unnamed method parameters, crate root module, error recovery etc.
|
// unnamed method parameters, crate root module, error recovery etc.
|
||||||
pub fn is_special(self) -> bool {
|
pub fn is_special(self) -> bool {
|
||||||
self.name <= keywords::Underscore.name()
|
self.name <= kw::Underscore
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the token is a keyword used in the language.
|
/// Returns `true` if the token is a keyword used in the language.
|
||||||
pub fn is_used_keyword(self) -> bool {
|
pub fn is_used_keyword(self) -> bool {
|
||||||
// Note: `span.edition()` is relatively expensive, don't call it unless necessary.
|
// Note: `span.edition()` is relatively expensive, don't call it unless necessary.
|
||||||
self.name >= keywords::As.name() && self.name <= keywords::While.name() ||
|
self.name >= kw::As && self.name <= kw::While ||
|
||||||
self.name.is_used_keyword_2018() && self.span.rust_2018()
|
self.name.is_used_keyword_2018() && self.span.rust_2018()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the token is a keyword reserved for possible future use.
|
/// Returns `true` if the token is a keyword reserved for possible future use.
|
||||||
pub fn is_unused_keyword(self) -> bool {
|
pub fn is_unused_keyword(self) -> bool {
|
||||||
// Note: `span.edition()` is relatively expensive, don't call it unless necessary.
|
// Note: `span.edition()` is relatively expensive, don't call it unless necessary.
|
||||||
self.name >= keywords::Abstract.name() && self.name <= keywords::Yield.name() ||
|
self.name >= kw::Abstract && self.name <= kw::Yield ||
|
||||||
self.name.is_unused_keyword_2018() && self.span.rust_2018()
|
self.name.is_unused_keyword_2018() && self.span.rust_2018()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -993,17 +976,17 @@ impl Ident {
|
||||||
|
|
||||||
/// A keyword or reserved identifier that can be used as a path segment.
|
/// A keyword or reserved identifier that can be used as a path segment.
|
||||||
pub fn is_path_segment_keyword(self) -> bool {
|
pub fn is_path_segment_keyword(self) -> bool {
|
||||||
self.name == keywords::Super.name() ||
|
self.name == kw::Super ||
|
||||||
self.name == keywords::SelfLower.name() ||
|
self.name == kw::SelfLower ||
|
||||||
self.name == keywords::SelfUpper.name() ||
|
self.name == kw::SelfUpper ||
|
||||||
self.name == keywords::Crate.name() ||
|
self.name == kw::Crate ||
|
||||||
self.name == keywords::PathRoot.name() ||
|
self.name == kw::PathRoot ||
|
||||||
self.name == keywords::DollarCrate.name()
|
self.name == kw::DollarCrate
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This identifier can be a raw identifier.
|
/// This identifier can be a raw identifier.
|
||||||
pub fn can_be_raw(self) -> bool {
|
pub fn can_be_raw(self) -> bool {
|
||||||
self.name != keywords::Invalid.name() && self.name != keywords::Underscore.name() &&
|
self.name != kw::Invalid && self.name != kw::Underscore &&
|
||||||
!self.is_path_segment_keyword()
|
!self.is_path_segment_keyword()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1267,7 +1250,7 @@ mod tests {
|
||||||
fn without_first_quote_test() {
|
fn without_first_quote_test() {
|
||||||
GLOBALS.set(&Globals::new(edition::DEFAULT_EDITION), || {
|
GLOBALS.set(&Globals::new(edition::DEFAULT_EDITION), || {
|
||||||
let i = Ident::from_str("'break");
|
let i = Ident::from_str("'break");
|
||||||
assert_eq!(i.without_first_quote().name, keywords::Break.name());
|
assert_eq!(i.without_first_quote().name, kw::Break);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue