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::CompilerDesugaringKind::IfTemporary;
|
||||
use syntax::std_inject;
|
||||
use syntax::symbol::{keywords, Symbol, sym};
|
||||
use syntax::symbol::{kw, sym, Symbol};
|
||||
use syntax::tokenstream::{TokenStream, TokenTree};
|
||||
use syntax::parse::token::Token;
|
||||
use syntax::visit::{self, Visitor};
|
||||
|
@ -927,11 +927,11 @@ impl<'a> LoweringContext<'a> {
|
|||
hir::LifetimeParamKind::InBand,
|
||||
),
|
||||
ParamName::Fresh(_) => (
|
||||
keywords::UnderscoreLifetime.name().as_interned_str(),
|
||||
kw::UnderscoreLifetime.as_interned_str(),
|
||||
hir::LifetimeParamKind::Elided,
|
||||
),
|
||||
ParamName::Error => (
|
||||
keywords::UnderscoreLifetime.name().as_interned_str(),
|
||||
kw::UnderscoreLifetime.as_interned_str(),
|
||||
hir::LifetimeParamKind::Error,
|
||||
),
|
||||
};
|
||||
|
@ -1415,7 +1415,7 @@ impl<'a> LoweringContext<'a> {
|
|||
P(hir::Path {
|
||||
res,
|
||||
segments: hir_vec![hir::PathSegment::from_ident(
|
||||
keywords::SelfUpper.ident()
|
||||
Ident::with_empty_ctxt(kw::SelfUpper)
|
||||
)],
|
||||
span: t.span,
|
||||
}),
|
||||
|
@ -1614,7 +1614,7 @@ impl<'a> LoweringContext<'a> {
|
|||
trace!("registering existential type with id {:#?}", exist_ty_id);
|
||||
let exist_ty_item = hir::Item {
|
||||
hir_id: exist_ty_id,
|
||||
ident: keywords::Invalid.ident(),
|
||||
ident: Ident::with_empty_ctxt(kw::Invalid),
|
||||
attrs: Default::default(),
|
||||
node: exist_ty_item_kind,
|
||||
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
|
||||
|
@ -1747,7 +1747,7 @@ impl<'a> LoweringContext<'a> {
|
|||
|
||||
let (name, kind) = match name {
|
||||
hir::LifetimeName::Underscore => (
|
||||
hir::ParamName::Plain(keywords::UnderscoreLifetime.ident()),
|
||||
hir::ParamName::Plain(Ident::with_empty_ctxt(kw::UnderscoreLifetime)),
|
||||
hir::LifetimeParamKind::Elided,
|
||||
),
|
||||
hir::LifetimeName::Param(param_name) => (
|
||||
|
@ -2296,7 +2296,7 @@ impl<'a> LoweringContext<'a> {
|
|||
.iter()
|
||||
.map(|arg| match arg.pat.node {
|
||||
PatKind::Ident(_, ident, _) => ident,
|
||||
_ => Ident::new(keywords::Invalid.name(), arg.pat.span),
|
||||
_ => Ident::new(kw::Invalid, arg.pat.span),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -2585,9 +2585,9 @@ impl<'a> LoweringContext<'a> {
|
|||
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
|
||||
let span = l.ident.span;
|
||||
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),
|
||||
ident if ident.name == keywords::UnderscoreLifetime.name() =>
|
||||
ident if ident.name == kw::UnderscoreLifetime =>
|
||||
match self.anonymous_lifetime_mode {
|
||||
AnonymousLifetimeMode::CreateParameter => {
|
||||
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).
|
||||
// `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.
|
||||
let ident = if param.ident.name == keywords::SelfUpper.name() {
|
||||
let ident = if param.ident.name == kw::SelfUpper {
|
||||
param.ident.gensym()
|
||||
} else {
|
||||
param.ident
|
||||
|
@ -3325,7 +3325,7 @@ impl<'a> LoweringContext<'a> {
|
|||
|
||||
// Correctly resolve `self` imports.
|
||||
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();
|
||||
if rename.is_none() {
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::session::CrateDisambiguator;
|
|||
use syntax::ast::*;
|
||||
use syntax::ext::hygiene::Mark;
|
||||
use syntax::visit;
|
||||
use syntax::symbol::keywords;
|
||||
use syntax::symbol::kw;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::parse::token::{self, Token};
|
||||
use syntax_pos::Span;
|
||||
|
@ -138,7 +138,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
// information we encapsulate into, the better
|
||||
let def_data = match i.node {
|
||||
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);
|
||||
}
|
||||
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
|
||||
|
|
|
@ -519,7 +519,7 @@ impl<'hir> Map<'hir> {
|
|||
pub fn ty_param_name(&self, id: HirId) -> Name {
|
||||
match self.get_by_hir_id(id) {
|
||||
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,
|
||||
_ => 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::ext::hygiene::SyntaxContext;
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::{Symbol, keywords};
|
||||
use syntax::symbol::{Symbol, kw};
|
||||
use syntax::tokenstream::TokenStream;
|
||||
use syntax::util::parser::ExprPrecedence;
|
||||
use crate::ty::AdtKind;
|
||||
|
@ -160,7 +160,7 @@ pub struct Lifetime {
|
|||
pub span: Span,
|
||||
|
||||
/// 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
|
||||
/// refer to type definitions needing lifetime parameters,
|
||||
|
@ -199,7 +199,8 @@ impl ParamName {
|
|||
pub fn ident(&self) -> Ident {
|
||||
match *self {
|
||||
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 {
|
||||
pub fn ident(&self) -> Ident {
|
||||
match *self {
|
||||
LifetimeName::Implicit => keywords::Invalid.ident(),
|
||||
LifetimeName::Error => keywords::Invalid.ident(),
|
||||
LifetimeName::Underscore => keywords::UnderscoreLifetime.ident(),
|
||||
LifetimeName::Static => keywords::StaticLifetime.ident(),
|
||||
LifetimeName::Implicit => Ident::with_empty_ctxt(kw::Invalid),
|
||||
LifetimeName::Error => Ident::with_empty_ctxt(kw::Invalid),
|
||||
LifetimeName::Underscore => Ident::with_empty_ctxt(kw::UnderscoreLifetime),
|
||||
LifetimeName::Static => Ident::with_empty_ctxt(kw::StaticLifetime),
|
||||
LifetimeName::Param(param_name) => param_name.ident(),
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +306,7 @@ pub struct Path {
|
|||
|
||||
impl Path {
|
||||
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::pprust::{self, PrintState};
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::keywords;
|
||||
use syntax::symbol::kw;
|
||||
use syntax::util::parser::{self, AssocOp, Fixity};
|
||||
use syntax_pos::{self, BytePos, FileName};
|
||||
|
||||
|
@ -798,7 +798,7 @@ impl<'a> State<'a> {
|
|||
hir::VisibilityKind::Restricted { ref path, .. } => {
|
||||
self.s.word("pub(")?;
|
||||
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)`.
|
||||
self.s.word("super")?;
|
||||
} else {
|
||||
|
@ -1559,7 +1559,7 @@ impl<'a> State<'a> {
|
|||
if i > 0 {
|
||||
self.s.word("::")?
|
||||
}
|
||||
if segment.ident.name != keywords::PathRoot.name() {
|
||||
if segment.ident.name != kw::PathRoot {
|
||||
self.print_ident(segment.ident)?;
|
||||
segment.with_generic_args(|generic_args| {
|
||||
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<()> {
|
||||
if segment.ident.name != keywords::PathRoot.name() {
|
||||
if segment.ident.name != kw::PathRoot {
|
||||
self.print_ident(segment.ident)?;
|
||||
segment.with_generic_args(|generic_args| {
|
||||
self.print_generic_args(generic_args, segment.infer_types, false)
|
||||
|
@ -1599,7 +1599,7 @@ impl<'a> State<'a> {
|
|||
if i > 0 {
|
||||
self.s.word("::")?
|
||||
}
|
||||
if segment.ident.name != keywords::PathRoot.name() {
|
||||
if segment.ident.name != kw::PathRoot {
|
||||
self.print_ident(segment.ident)?;
|
||||
segment.with_generic_args(|generic_args| {
|
||||
self.print_generic_args(generic_args,
|
||||
|
|
|
@ -112,7 +112,7 @@ use std::io;
|
|||
use std::rc::Rc;
|
||||
use syntax::ast::{self, NodeId};
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::{keywords, sym};
|
||||
use syntax::symbol::{kw, sym};
|
||||
use syntax_pos::Span;
|
||||
|
||||
use crate::hir;
|
||||
|
@ -1552,7 +1552,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
let sp = ident.span;
|
||||
let var = self.variable(hir_id, sp);
|
||||
// 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.live_on_entry(entry_ln, var).is_none() {
|
||||
self.report_dead_assign(hir_id, sp, var, true);
|
||||
|
|
|
@ -23,7 +23,7 @@ use std::mem::replace;
|
|||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::{keywords, sym};
|
||||
use syntax::symbol::{kw, sym};
|
||||
use syntax_pos::Span;
|
||||
|
||||
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
|
@ -711,7 +711,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
GenericParamKind::Lifetime { .. } => {
|
||||
let (name, reg) = Region::early(&self.tcx.hir(), &mut index, ¶m);
|
||||
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
|
||||
// and use it to make an elision scope.
|
||||
elision = Some(reg);
|
||||
|
@ -1602,7 +1602,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
} {
|
||||
debug!("id = {:?} span = {:?} name = {:?}", id, span, name);
|
||||
|
||||
if name == keywords::UnderscoreLifetime.ident() {
|
||||
if name == ast::Ident::with_empty_ctxt(kw::UnderscoreLifetime) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2525,8 +2525,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
for (i, (lifetime_i, lifetime_i_name)) in lifetimes.iter().enumerate() {
|
||||
if let hir::ParamName::Plain(_) = lifetime_i_name {
|
||||
let name = lifetime_i_name.ident().name;
|
||||
if name == keywords::UnderscoreLifetime.name()
|
||||
|| name == keywords::StaticLifetime.name()
|
||||
if name == kw::UnderscoreLifetime
|
||||
|| name == kw::StaticLifetime
|
||||
{
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx.sess,
|
||||
|
|
|
@ -74,7 +74,7 @@ use syntax::ast;
|
|||
use syntax::attr;
|
||||
use syntax::source_map::MultiSpan;
|
||||
use syntax::feature_gate;
|
||||
use syntax::symbol::{Symbol, keywords, InternedString, sym};
|
||||
use syntax::symbol::{Symbol, InternedString, kw, sym};
|
||||
use syntax_pos::Span;
|
||||
|
||||
use crate::hir;
|
||||
|
@ -2735,7 +2735,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
|
||||
#[inline]
|
||||
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> {
|
||||
|
|
|
@ -47,7 +47,7 @@ use std::ops::Range;
|
|||
use syntax::ast::{self, Name, Ident, NodeId};
|
||||
use syntax::attr;
|
||||
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 smallvec;
|
||||
|
@ -835,7 +835,7 @@ impl ty::EarlyBoundRegion {
|
|||
/// Does this early bound region have a name? Early bound regions normally
|
||||
/// always have names except when using anonymous lifetimes (`'_`).
|
||||
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() {
|
||||
// We add the `crate::` keyword on Rust 2018, only when desired.
|
||||
if SHOULD_PREFIX_WITH_CRATE.with(|flag| flag.get()) {
|
||||
write!(self, "{}", keywords::Crate.name())?;
|
||||
write!(self, "{}", kw::Crate)?;
|
||||
self.empty_path = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use std::marker::PhantomData;
|
|||
use std::ops::Range;
|
||||
use rustc_target::spec::abi;
|
||||
use syntax::ast::{self, Ident};
|
||||
use syntax::symbol::{keywords, InternedString};
|
||||
use syntax::symbol::{kw, InternedString};
|
||||
|
||||
use serialize;
|
||||
use self::InferTy::*;
|
||||
|
@ -1121,7 +1121,7 @@ impl<'a, 'gcx, 'tcx> 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 {
|
||||
|
@ -1136,7 +1136,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
|
|||
// 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
|
||||
// `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 syntax_pos::{DUMMY_SP, NO_EXPANSION, BytePos, Span};
|
||||
use syntax::symbol::keywords;
|
||||
use syntax::symbol::kw;
|
||||
|
||||
use std::iter;
|
||||
|
||||
|
@ -496,7 +496,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
};
|
||||
bx.declare_local(
|
||||
&fx.debug_context,
|
||||
arg_decl.name.unwrap_or(keywords::Invalid.name()),
|
||||
arg_decl.name.unwrap_or(kw::Invalid),
|
||||
arg_ty, scope,
|
||||
variable_access,
|
||||
VariableKind::ArgumentVariable(arg_index + 1),
|
||||
|
@ -613,7 +613,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
|
||||
bx.declare_local(
|
||||
&fx.debug_context,
|
||||
arg_decl.name.unwrap_or(keywords::Invalid.name()),
|
||||
arg_decl.name.unwrap_or(kw::Invalid),
|
||||
arg.layout.ty,
|
||||
scope,
|
||||
variable_access,
|
||||
|
|
|
@ -42,7 +42,7 @@ use syntax::edition::Edition;
|
|||
use syntax::feature_gate::{AttributeGate, AttributeTemplate, AttributeType};
|
||||
use syntax::feature_gate::{Stability, deprecated_attributes};
|
||||
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::print::pprust::expr_to_string;
|
||||
use syntax::visit::FnKind;
|
||||
|
@ -607,7 +607,7 @@ impl EarlyLintPass for AnonymousParameters {
|
|||
for arg in sig.decl.inputs.iter() {
|
||||
match arg.pat.node {
|
||||
ast::PatKind::Ident(_, ident, None) => {
|
||||
if ident.name == keywords::Invalid.name() {
|
||||
if ident.name == kw::Invalid {
|
||||
let ty_snip = cx
|
||||
.sess
|
||||
.source_map()
|
||||
|
|
|
@ -12,7 +12,7 @@ use syntax::attr;
|
|||
use syntax::errors::Applicability;
|
||||
use syntax::feature_gate::{AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
|
||||
use syntax::print::pprust;
|
||||
use syntax::symbol::{keywords, sym};
|
||||
use syntax::symbol::{kw, sym};
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::util::parser;
|
||||
use syntax_pos::Span;
|
||||
|
@ -455,7 +455,7 @@ impl UnusedImportBraces {
|
|||
match items[0].0.kind {
|
||||
ast::UseTreeKind::Simple(rename, ..) => {
|
||||
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;
|
||||
}
|
||||
node_ident = rename.unwrap_or(orig_ident);
|
||||
|
|
|
@ -97,7 +97,6 @@ pub fn symbols(input: TokenStream) -> TokenStream {
|
|||
let mut keyword_stream = quote! {};
|
||||
let mut symbols_stream = quote! {};
|
||||
let mut prefill_stream = quote! {};
|
||||
let mut from_str_stream = quote! {};
|
||||
let mut counter = 0u32;
|
||||
let mut keys = HashSet::<String>::new();
|
||||
|
||||
|
@ -115,12 +114,7 @@ pub fn symbols(input: TokenStream) -> TokenStream {
|
|||
#value,
|
||||
});
|
||||
keyword_stream.extend(quote! {
|
||||
pub const #name: Keyword = Keyword {
|
||||
ident: Ident::with_empty_ctxt(super::Symbol::new(#counter))
|
||||
};
|
||||
});
|
||||
from_str_stream.extend(quote! {
|
||||
#value => Ok(#name),
|
||||
pub const #name: Symbol = Symbol::new(#counter);
|
||||
});
|
||||
counter += 1;
|
||||
}
|
||||
|
@ -145,17 +139,6 @@ pub fn symbols(input: TokenStream) -> TokenStream {
|
|||
macro_rules! keywords {
|
||||
() => {
|
||||
#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::attr;
|
||||
use syntax::source_map::Spanned;
|
||||
use syntax::symbol::{keywords, sym};
|
||||
use syntax::symbol::{kw, sym};
|
||||
use syntax_pos::{self, FileName, SourceFile, Span};
|
||||
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| {
|
||||
match arg.pat.node {
|
||||
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_data_structures::indexed_vec::Idx;
|
||||
use syntax_pos::Span;
|
||||
use syntax_pos::symbol::keywords;
|
||||
use syntax_pos::symbol::kw;
|
||||
|
||||
use crate::dataflow::move_paths::InitLocation;
|
||||
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,
|
||||
// so that we don't fall in to the next case with them.
|
||||
*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
|
||||
// we have an explicit self. Do the same thing in this case and check
|
||||
// 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 std::collections::VecDeque;
|
||||
use syntax::errors::Applicability;
|
||||
use syntax::symbol::keywords;
|
||||
use syntax::symbol::kw;
|
||||
use syntax_pos::Span;
|
||||
|
||||
mod region_name;
|
||||
|
@ -631,7 +631,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
"add_static_impl_trait_suggestion: 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
|
||||
// fr with `'static`.
|
||||
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::print::RegionHighlightMode;
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use syntax::symbol::keywords;
|
||||
use syntax::symbol::kw;
|
||||
use syntax_pos::Span;
|
||||
use syntax_pos::symbol::InternedString;
|
||||
|
||||
|
@ -216,7 +216,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
}
|
||||
|
||||
ty::ReStatic => Some(RegionName {
|
||||
name: keywords::StaticLifetime.name().as_interned_str(),
|
||||
name: kw::StaticLifetime.as_interned_str(),
|
||||
source: RegionNameSource::Static
|
||||
}),
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use std::mem;
|
|||
use std::u32;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use syntax::attr::{self, UnwindAttr};
|
||||
use syntax::symbol::keywords;
|
||||
use syntax::symbol::kw;
|
||||
use syntax_pos::Span;
|
||||
|
||||
use super::lints;
|
||||
|
@ -660,7 +660,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
|
|||
ty::UpvarCapture::ByRef(..) => true,
|
||||
};
|
||||
let mut debuginfo = UpvarDebuginfo {
|
||||
debug_name: keywords::Invalid.name(),
|
||||
debug_name: kw::Invalid,
|
||||
by_ref,
|
||||
};
|
||||
let mut mutability = Mutability::Not;
|
||||
|
|
|
@ -15,7 +15,7 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
use syntax::ast::*;
|
||||
use syntax::attr;
|
||||
use syntax::source_map::Spanned;
|
||||
use syntax::symbol::{keywords, sym};
|
||||
use syntax::symbol::{kw, sym};
|
||||
use syntax::ptr::P;
|
||||
use syntax::visit::{self, Visitor};
|
||||
use syntax::{span_err, struct_span_err, walk_list};
|
||||
|
@ -177,9 +177,9 @@ impl<'a> AstValidator<'a> {
|
|||
}
|
||||
|
||||
fn check_lifetime(&self, ident: Ident) {
|
||||
let valid_names = [keywords::UnderscoreLifetime.name(),
|
||||
keywords::StaticLifetime.name(),
|
||||
keywords::Invalid.name()];
|
||||
let valid_names = [kw::UnderscoreLifetime,
|
||||
kw::StaticLifetime,
|
||||
kw::Invalid];
|
||||
if !valid_names.contains(&ident.name) && ident.without_first_quote().is_reserved() {
|
||||
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 syntax::ast::Ident;
|
||||
use syntax::attr;
|
||||
use syntax::symbol::{keywords, sym};
|
||||
use syntax::symbol::{kw, sym};
|
||||
use syntax_pos::Span;
|
||||
|
||||
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`
|
||||
def: &'tcx ty::AdtDef, // definition of the struct or enum
|
||||
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 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) {
|
||||
|
|
|
@ -37,7 +37,7 @@ use syntax::feature_gate::is_builtin_attr;
|
|||
use syntax::parse::token::{self, Token};
|
||||
use syntax::span_err;
|
||||
use syntax::std_inject::injected_crate_name;
|
||||
use syntax::symbol::{keywords, sym};
|
||||
use syntax::symbol::{kw, sym};
|
||||
use syntax::visit::{self, Visitor};
|
||||
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
|
@ -143,7 +143,7 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
_ => None,
|
||||
}.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<_>>();
|
||||
|
@ -151,7 +151,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
let empty_for_self = |prefix: &[Segment]| {
|
||||
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 {
|
||||
ast::UseTreeKind::Simple(rename, ..) => {
|
||||
|
@ -162,7 +162,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
if nested {
|
||||
// Correctly handle `self`
|
||||
if source.ident.name == keywords::SelfLower.name() {
|
||||
if source.ident.name == kw::SelfLower {
|
||||
type_ns_only = true;
|
||||
|
||||
if empty_for_self(&module_path) {
|
||||
|
@ -183,14 +183,14 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
} else {
|
||||
// Disallow `self`
|
||||
if source.ident.name == keywords::SelfLower.name() {
|
||||
if source.ident.name == kw::SelfLower {
|
||||
resolve_error(self,
|
||||
use_tree.span,
|
||||
ResolutionError::SelfImportsOnlyAllowedWithin);
|
||||
}
|
||||
|
||||
// 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_name = match crate_root.kind {
|
||||
ModuleKind::Def(.., name) => name,
|
||||
|
@ -199,11 +199,11 @@ impl<'a> Resolver<'a> {
|
|||
// HACK(eddyb) unclear how good this is, but keeping `$crate`
|
||||
// in `source` breaks `src/test/compile-fail/import-crate-var.rs`,
|
||||
// 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.
|
||||
module_path.push(Segment {
|
||||
ident: Ident {
|
||||
name: keywords::PathRoot.name(),
|
||||
name: kw::PathRoot,
|
||||
span: source.ident.span,
|
||||
},
|
||||
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,
|
||||
"crate root imports need to be explicitly named: \
|
||||
`use crate as name;`");
|
||||
|
@ -276,7 +276,7 @@ impl<'a> Resolver<'a> {
|
|||
// Ensure there is at most one `self` in the list
|
||||
let self_spans = items.iter().filter_map(|&(ref use_tree, _)| {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ impl<'a> Resolver<'a> {
|
|||
let new_span = prefix[prefix.len() - 1].ident.span;
|
||||
let tree = ast::UseTree {
|
||||
prefix: ast::Path::from_ident(
|
||||
Ident::new(keywords::SelfLower.name(), new_span)
|
||||
Ident::new(kw::SelfLower, new_span)
|
||||
),
|
||||
kind: ast::UseTreeKind::Simple(
|
||||
Some(Ident::from_str_and_span("__dummy", new_span).gensym()),
|
||||
|
@ -350,7 +350,7 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
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
|
||||
.struct_span_err(item.span, "`extern crate self;` requires renaming")
|
||||
.span_suggestion(
|
||||
|
@ -361,7 +361,7 @@ impl<'a> Resolver<'a> {
|
|||
)
|
||||
.emit();
|
||||
return;
|
||||
} else if orig_name == Some(keywords::SelfLower.name()) {
|
||||
} else if orig_name == Some(kw::SelfLower) {
|
||||
self.graph_root
|
||||
} else {
|
||||
let crate_id = self.crate_loader.process_extern_crate(item, &self.definitions);
|
||||
|
@ -420,7 +420,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
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(..) => {
|
||||
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");
|
||||
}
|
||||
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,
|
||||
"`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 syntax::ast::{self, Expr, ExprKind, Ident};
|
||||
use syntax::ext::base::MacroKind;
|
||||
use syntax::symbol::{Symbol, keywords};
|
||||
use syntax::symbol::{Symbol, kw};
|
||||
use syntax_pos::{BytePos, Span};
|
||||
|
||||
type Res = def::Res<ast::NodeId>;
|
||||
|
@ -48,7 +48,7 @@ impl<'a> Resolver<'a> {
|
|||
let item_span = path.last().unwrap().ident.span;
|
||||
let (mod_prefix, mod_str) = if path.len() == 1 {
|
||||
(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())
|
||||
} else {
|
||||
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)) {
|
||||
// `{{root}}::ident::...` on both editions.
|
||||
// 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() => {}
|
||||
// `ident::...` on 2018.
|
||||
(Some(fst), _) if fst.ident.span.rust_2018() &&
|
||||
!fst.ident.is_path_segment_keyword() => {
|
||||
// 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,
|
||||
}
|
||||
|
@ -485,7 +485,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
|||
parent_scope: &ParentScope<'b>,
|
||||
) -> Option<(Vec<Segment>, Vec<String>)> {
|
||||
// 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);
|
||||
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
|
||||
if let PathResult::Module(..) = result {
|
||||
|
@ -509,7 +509,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
|||
parent_scope: &ParentScope<'b>,
|
||||
) -> Option<(Vec<Segment>, Vec<String>)> {
|
||||
// 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);
|
||||
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
|
||||
if let PathResult::Module(..) = result {
|
||||
|
@ -540,7 +540,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
|||
parent_scope: &ParentScope<'b>,
|
||||
) -> Option<(Vec<Segment>, Vec<String>)> {
|
||||
// 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);
|
||||
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, 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::Determinacy::{self, Determined, Undetermined};
|
||||
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::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);
|
||||
}
|
||||
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)
|
||||
.map_or(Res::Err, |d| d.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
|
||||
) -> hir::Path {
|
||||
let root = if crate_root.is_some() {
|
||||
keywords::PathRoot
|
||||
kw::PathRoot
|
||||
} else {
|
||||
keywords::Crate
|
||||
kw::Crate
|
||||
};
|
||||
let segments = iter::once(root.ident())
|
||||
let segments = iter::once(Ident::with_empty_ctxt(root))
|
||||
.chain(
|
||||
crate_root.into_iter()
|
||||
.chain(components.iter().cloned())
|
||||
.map(Ident::with_empty_ctxt)
|
||||
).map(|i| self.new_ast_path_segment(i)).collect::<Vec<_>>();
|
||||
|
||||
|
||||
let path = ast::Path {
|
||||
span,
|
||||
segments,
|
||||
|
@ -1866,7 +1865,7 @@ impl<'a> Resolver<'a> {
|
|||
let path = if path_str.starts_with("::") {
|
||||
ast::Path {
|
||||
span,
|
||||
segments: iter::once(keywords::PathRoot.ident())
|
||||
segments: iter::once(Ident::with_empty_ctxt(kw::PathRoot))
|
||||
.chain({
|
||||
path_str.split("::").skip(1).map(Ident::from_str)
|
||||
})
|
||||
|
@ -1961,7 +1960,7 @@ impl<'a> Resolver<'a> {
|
|||
let root_module_kind = ModuleKind::Def(
|
||||
DefKind::Mod,
|
||||
root_def_id,
|
||||
keywords::Invalid.name(),
|
||||
kw::Invalid,
|
||||
);
|
||||
let graph_root = arenas.alloc_module(ModuleData {
|
||||
no_implicit_prelude: attr::contains_name(&krate.attrs, sym::no_implicit_prelude),
|
||||
|
@ -2187,10 +2186,10 @@ impl<'a> Resolver<'a> {
|
|||
path_span: Span)
|
||||
-> Option<LexicalScopeBinding<'a>> {
|
||||
assert!(ns == TypeNS || ns == ValueNS);
|
||||
if ident.name == keywords::Invalid.name() {
|
||||
if ident.name == kw::Invalid {
|
||||
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
|
||||
ident.span.with_ctxt(SyntaxContext::empty())
|
||||
} else if ns == TypeNS {
|
||||
|
@ -2405,7 +2404,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
fn resolve_crate_root(&mut self, ident: Ident) -> Module<'a> {
|
||||
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`,
|
||||
// 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.
|
||||
|
@ -2851,7 +2850,7 @@ impl<'a> Resolver<'a> {
|
|||
let mut self_type_rib = Rib::new(NormalRibKind);
|
||||
|
||||
// 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);
|
||||
f(self);
|
||||
self.ribs[TypeNS].pop();
|
||||
|
@ -2862,7 +2861,7 @@ impl<'a> Resolver<'a> {
|
|||
{
|
||||
let self_res = Res::SelfCtor(impl_id);
|
||||
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);
|
||||
f(self);
|
||||
self.ribs[ValueNS].pop();
|
||||
|
@ -3199,7 +3198,7 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
None => {
|
||||
// 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);
|
||||
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 {
|
||||
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);
|
||||
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 {
|
||||
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);
|
||||
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 &&
|
||||
path[0].ident.name != keywords::PathRoot.name() &&
|
||||
path[0].ident.name != keywords::DollarCrate.name() {
|
||||
path[0].ident.name != kw::PathRoot &&
|
||||
path[0].ident.name != kw::DollarCrate {
|
||||
let unqualified_result = {
|
||||
match self.resolve_path_without_parent_scope(
|
||||
&[*path.last().unwrap()],
|
||||
|
@ -3739,11 +3738,11 @@ impl<'a> Resolver<'a> {
|
|||
let name = ident.name;
|
||||
|
||||
allow_super &= ns == TypeNS &&
|
||||
(name == keywords::SelfLower.name() ||
|
||||
name == keywords::Super.name());
|
||||
(name == kw::SelfLower ||
|
||||
name == kw::Super);
|
||||
|
||||
if ns == TypeNS {
|
||||
if allow_super && name == keywords::Super.name() {
|
||||
if allow_super && name == kw::Super {
|
||||
let mut ctxt = ident.span.ctxt().modern();
|
||||
let self_module = match i {
|
||||
0 => Some(self.resolve_self(&mut ctxt, self.current_module)),
|
||||
|
@ -3768,25 +3767,25 @@ impl<'a> Resolver<'a> {
|
|||
};
|
||||
}
|
||||
if i == 0 {
|
||||
if name == keywords::SelfLower.name() {
|
||||
if name == kw::SelfLower {
|
||||
let mut ctxt = ident.span.ctxt().modern();
|
||||
module = Some(ModuleOrUniformRoot::Module(
|
||||
self.resolve_self(&mut ctxt, self.current_module)));
|
||||
continue;
|
||||
}
|
||||
if name == keywords::PathRoot.name() && ident.span.rust_2018() {
|
||||
if name == kw::PathRoot && ident.span.rust_2018() {
|
||||
module = Some(ModuleOrUniformRoot::ExternPrelude);
|
||||
continue;
|
||||
}
|
||||
if name == keywords::PathRoot.name() &&
|
||||
if name == kw::PathRoot &&
|
||||
ident.span.rust_2015() && self.session.rust_2018() {
|
||||
// `::a::b` from 2015 macro on 2018 global edition
|
||||
module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude);
|
||||
continue;
|
||||
}
|
||||
if name == keywords::PathRoot.name() ||
|
||||
name == keywords::Crate.name() ||
|
||||
name == keywords::DollarCrate.name() {
|
||||
if name == kw::PathRoot ||
|
||||
name == kw::Crate ||
|
||||
name == kw::DollarCrate {
|
||||
// `::a::b`, `crate::a::b` or `$crate::a::b`
|
||||
module = Some(ModuleOrUniformRoot::Module(
|
||||
self.resolve_crate_root(ident)));
|
||||
|
@ -3797,12 +3796,12 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
// Report special messages for path segment keywords in wrong positions.
|
||||
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()
|
||||
} else {
|
||||
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)
|
||||
} else {
|
||||
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
|
||||
// `{{root}}` currently.
|
||||
if first_name != keywords::PathRoot.name() {
|
||||
if first_name != kw::PathRoot {
|
||||
return
|
||||
}
|
||||
|
||||
match path.get(1) {
|
||||
// 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
|
||||
Some(_) => {}
|
||||
// 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 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)];
|
||||
|
||||
while let Some((in_module,
|
||||
|
@ -4764,7 +4763,8 @@ impl<'a> Resolver<'a> {
|
|||
where FilterFn: Fn(Res) -> bool
|
||||
{
|
||||
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() {
|
||||
let extern_prelude_names = self.extern_prelude.clone();
|
||||
|
@ -4883,7 +4883,7 @@ impl<'a> Resolver<'a> {
|
|||
} else {
|
||||
let ctxt = ident.span.ctxt();
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
let mut result = String::new();
|
||||
for (i, ident) in idents.iter()
|
||||
.filter(|ident| ident.name != keywords::PathRoot.name())
|
||||
.filter(|ident| ident.name != kw::PathRoot)
|
||||
.enumerate() {
|
||||
if i > 0 {
|
||||
result.push_str("::");
|
||||
|
|
|
@ -22,7 +22,7 @@ use syntax::ext::tt::macro_rules;
|
|||
use syntax::feature_gate::{
|
||||
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::util::lev_distance::find_best_match_for_name;
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
|
@ -137,10 +137,10 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
}
|
||||
impl<'a> Visitor<'a> for ResolveDollarCrates<'a, '_> {
|
||||
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 {
|
||||
ModuleKind::Def(.., name) if name != keywords::Invalid.name() => name,
|
||||
_ => keywords::Crate.name(),
|
||||
ModuleKind::Def(.., name) if name != kw::Invalid => name,
|
||||
_ => kw::Crate,
|
||||
};
|
||||
ident.span.ctxt().set_dollar_crate_name(name);
|
||||
}
|
||||
|
@ -415,7 +415,7 @@ impl<'a> Resolver<'a> {
|
|||
if kind == MacroKind::Bang && path.len() == 1 &&
|
||||
path[0].ident.span.ctxt().outer().expn_info()
|
||||
.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));
|
||||
}
|
||||
|
||||
|
@ -613,7 +613,7 @@ impl<'a> Resolver<'a> {
|
|||
_ => Err(Determinacy::Determined),
|
||||
}
|
||||
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 binding = self.resolve_ident_in_module_ext(
|
||||
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::ext::base::Determinacy::{self, Determined, Undetermined};
|
||||
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::{struct_span_err, unwrap_or};
|
||||
use syntax_pos::{MultiSpan, Span};
|
||||
|
@ -217,15 +217,15 @@ impl<'a> Resolver<'a> {
|
|||
parent_scope.expect("no parent scope for a single-segment import");
|
||||
|
||||
if ns == TypeNS {
|
||||
if ident.name == keywords::Crate.name() ||
|
||||
ident.name == keywords::DollarCrate.name() {
|
||||
if ident.name == kw::Crate ||
|
||||
ident.name == kw::DollarCrate {
|
||||
let module = self.resolve_crate_root(ident);
|
||||
let binding = (module, ty::Visibility::Public,
|
||||
module.span, Mark::root())
|
||||
.to_name_binding(self.arenas);
|
||||
return Ok(binding);
|
||||
} else if ident.name == keywords::Super.name() ||
|
||||
ident.name == keywords::SelfLower.name() {
|
||||
} else if ident.name == kw::Super ||
|
||||
ident.name == kw::SelfLower {
|
||||
// FIXME: Implement these with renaming requirements so that e.g.
|
||||
// `use super;` doesn't work, but `use super as name;` does.
|
||||
// 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
|
||||
// 2 segments, so the `resolve_path` above won't trigger it.
|
||||
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(
|
||||
directive.crate_lint(),
|
||||
&full_path,
|
||||
|
@ -1484,8 +1484,8 @@ fn import_path_to_string(names: &[Ident],
|
|||
subclass: &ImportDirectiveSubclass<'_>,
|
||||
span: Span) -> String {
|
||||
let pos = names.iter()
|
||||
.position(|p| span == p.span && p.name != keywords::PathRoot.name());
|
||||
let global = !names.is_empty() && names[0].name == keywords::PathRoot.name();
|
||||
.position(|p| span == p.span && p.name != kw::PathRoot);
|
||||
let global = !names.is_empty() && names[0].name == kw::PathRoot;
|
||||
if let Some(pos) = pos {
|
||||
let names = if global { &names[1..pos + 1] } else { &names[..pos + 1] };
|
||||
names_to_string(names)
|
||||
|
|
|
@ -123,7 +123,7 @@ use syntax::attr;
|
|||
use syntax::feature_gate::{GateIssue, emit_feature_err};
|
||||
use syntax::ptr::P;
|
||||
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 std::cell::{Cell, RefCell, Ref, RefMut};
|
||||
|
@ -3290,7 +3290,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
Ok(method)
|
||||
}
|
||||
Err(error) => {
|
||||
if segment.ident.name != keywords::Invalid.name() {
|
||||
if segment.ident.name != kw::Invalid {
|
||||
self.report_method_error(span,
|
||||
rcvr_t,
|
||||
segment.ident,
|
||||
|
@ -3402,7 +3402,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
err.emit();
|
||||
field_ty
|
||||
} else if field.name == keywords::Invalid.name() {
|
||||
} else if field.name == kw::Invalid {
|
||||
self.tcx().types.err
|
||||
} 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,
|
||||
|
@ -4672,7 +4672,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
method::MethodError::PrivateMatch(kind, def_id, _) => Ok((kind, def_id)),
|
||||
_ => Err(ErrorReported),
|
||||
};
|
||||
if item_name.name != keywords::Invalid.name() {
|
||||
if item_name.name != kw::Invalid {
|
||||
self.report_method_error(
|
||||
span,
|
||||
ty,
|
||||
|
|
|
@ -39,7 +39,7 @@ use syntax::ast::{Ident, MetaItemKind};
|
|||
use syntax::attr::{InlineAttr, OptimizeAttr, list_contains_name, mark_used};
|
||||
use syntax::source_map::Spanned;
|
||||
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 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 {
|
||||
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),
|
||||
pure_wrt_drop: false,
|
||||
kind: ty::GenericParamDefKind::Type {
|
||||
|
@ -1008,7 +1008,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty
|
|||
synthetic,
|
||||
..
|
||||
} => {
|
||||
if param.name.ident().name == keywords::SelfUpper.name() {
|
||||
if param.name.ident().name == kw::SelfUpper {
|
||||
span_bug!(
|
||||
param.span,
|
||||
"`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 { .. } => {
|
||||
if param.name.ident().name == keywords::SelfUpper.name() {
|
||||
if param.name.ident().name == kw::SelfUpper {
|
||||
span_bug!(
|
||||
param.span,
|
||||
"`Self` should not be the name of a regular parameter",
|
||||
|
|
|
@ -31,8 +31,7 @@ use syntax::attr;
|
|||
use syntax::ext::base::MacroKind;
|
||||
use syntax::source_map::{dummy_spanned, Spanned};
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::keywords::{self, Keyword};
|
||||
use syntax::symbol::{Symbol, sym};
|
||||
use syntax::symbol::{Symbol, kw, sym};
|
||||
use syntax::symbol::InternedString;
|
||||
use syntax_pos::{self, Pos, FileName};
|
||||
|
||||
|
@ -43,7 +42,6 @@ use std::default::Default;
|
|||
use std::{mem, slice, vec};
|
||||
use std::iter::{FromIterator, once};
|
||||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
use std::u32;
|
||||
|
@ -309,10 +307,9 @@ impl Clean<ExternalCrate> for CrateNum {
|
|||
for attr in attrs.lists(sym::doc) {
|
||||
if let Some(v) = attr.value_str() {
|
||||
if attr.check_name(sym::keyword) {
|
||||
keyword = Keyword::from_str(&v.as_str()).ok()
|
||||
.map(|x| x.name().to_string());
|
||||
if keyword.is_some() {
|
||||
break
|
||||
if v.is_doc_keyword() {
|
||||
keyword = Some(v.to_string());
|
||||
break;
|
||||
}
|
||||
// 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 {
|
||||
ty::GenericParamDefKind::Lifetime => None,
|
||||
ty::GenericParamDefKind::Type { .. } => {
|
||||
if param.name.as_symbol() == keywords::SelfUpper.name() {
|
||||
if param.name.as_symbol() == kw::SelfUpper {
|
||||
assert_eq!(param.index, 0);
|
||||
return None;
|
||||
}
|
||||
|
@ -3596,7 +3593,7 @@ fn qpath_to_string(p: &hir::QPath) -> String {
|
|||
if i > 0 {
|
||||
s.push_str("::");
|
||||
}
|
||||
if seg.ident.name != keywords::PathRoot.name() {
|
||||
if seg.ident.name != kw::PathRoot {
|
||||
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()),
|
||||
},
|
||||
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 => {
|
||||
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=\"generator\" content=\"rustdoc\">\
|
||||
<meta name=\"description\" content=\"{description}\">\
|
||||
<meta name=\"keywords\" content=\"{keywords}\">\
|
||||
<meta name=\"keywords\" content=\"{kw}\">\
|
||||
<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}rustdoc{suffix}.css\" \
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::parse::token;
|
|||
use crate::print::pprust;
|
||||
use crate::ptr::P;
|
||||
use crate::source_map::{dummy_spanned, respan, Spanned};
|
||||
use crate::symbol::{keywords, Symbol};
|
||||
use crate::symbol::{kw, Symbol};
|
||||
use crate::tokenstream::TokenStream;
|
||||
use crate::ThinVec;
|
||||
|
||||
|
@ -65,7 +65,7 @@ impl fmt::Debug for Lifetime {
|
|||
pub struct Path {
|
||||
pub span: Span,
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ impl Path {
|
|||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
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 {
|
||||
pub fn to_self(&self) -> Option<ExplicitSelf> {
|
||||
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 {
|
||||
TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
|
||||
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 {
|
||||
if let PatKind::Ident(_, ident, _) = self.pat.node {
|
||||
ident.name == keywords::SelfLower.name()
|
||||
ident.name == kw::SelfLower
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use crate::parse::parser::Parser;
|
|||
use crate::parse::{self, ParseSess, PResult};
|
||||
use crate::parse::token::{self, Token};
|
||||
use crate::ptr::P;
|
||||
use crate::symbol::{keywords, Symbol, sym};
|
||||
use crate::symbol::{kw, sym, Symbol};
|
||||
use crate::ThinVec;
|
||||
use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};
|
||||
use crate::GLOBALS;
|
||||
|
@ -90,7 +90,7 @@ impl NestedMetaItem {
|
|||
self.meta_item().and_then(|meta_item| meta_item.ident())
|
||||
}
|
||||
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
|
||||
|
@ -168,7 +168,7 @@ impl Attribute {
|
|||
}
|
||||
}
|
||||
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> {
|
||||
|
@ -206,7 +206,7 @@ impl MetaItem {
|
|||
}
|
||||
}
|
||||
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")]
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::ext::base::{ExtCtxt, MacEager, MacResult};
|
|||
use crate::ext::build::AstBuilder;
|
||||
use crate::parse::token;
|
||||
use crate::ptr::P;
|
||||
use crate::symbol::keywords;
|
||||
use crate::symbol::kw;
|
||||
use crate::tokenstream::{TokenTree};
|
||||
|
||||
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))
|
||||
});
|
||||
|
||||
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(
|
||||
span,
|
||||
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::token;
|
||||
use crate::ptr::P;
|
||||
use crate::symbol::{keywords, Ident, Symbol, sym};
|
||||
use crate::symbol::{kw, sym, Ident, Symbol};
|
||||
use crate::ThinVec;
|
||||
use crate::tokenstream::{self, TokenStream};
|
||||
|
||||
|
@ -971,7 +971,7 @@ impl<'a> ExtCtxt<'a> {
|
|||
}
|
||||
pub fn std_path(&self, components: &[&str]) -> Vec<ast::Ident> {
|
||||
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)))
|
||||
.collect()
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::attr;
|
|||
use crate::source_map::{dummy_spanned, respan, Spanned};
|
||||
use crate::ext::base::ExtCtxt;
|
||||
use crate::ptr::P;
|
||||
use crate::symbol::{Symbol, keywords};
|
||||
use crate::symbol::{Symbol, kw};
|
||||
use crate::ThinVec;
|
||||
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
@ -628,7 +628,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
|||
self.expr_path(self.path_ident(span, id))
|
||||
}
|
||||
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,
|
||||
|
@ -1175,7 +1175,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
|||
vis: ast::Visibility, vp: P<ast::UseTree>) -> P<ast::Item> {
|
||||
P(ast::Item {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
ident: keywords::Invalid.ident(),
|
||||
ident: Ident::with_empty_ctxt(kw::Invalid),
|
||||
attrs: vec![],
|
||||
node: ast::ItemKind::Use(vp),
|
||||
vis,
|
||||
|
|
|
@ -14,7 +14,7 @@ use crate::parse::token::{self, Token};
|
|||
use crate::parse::parser::Parser;
|
||||
use crate::ptr::P;
|
||||
use crate::symbol::Symbol;
|
||||
use crate::symbol::{keywords, sym};
|
||||
use crate::symbol::{kw, sym};
|
||||
use crate::tokenstream::{TokenStream, TokenTree};
|
||||
use crate::visit::{self, Visitor};
|
||||
use crate::util::map_in_place::MapInPlace;
|
||||
|
@ -198,7 +198,7 @@ fn macro_bang_format(path: &ast::Path) -> ExpnFormat {
|
|||
if i != 0 {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
attrs: krate.attrs,
|
||||
span: krate.span,
|
||||
node: ast::ItemKind::Mod(krate.module),
|
||||
ident: keywords::Invalid.ident(),
|
||||
ident: Ident::with_empty_ctxt(kw::Invalid),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
|
||||
tokens: None,
|
||||
|
@ -708,7 +708,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
};
|
||||
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
|
||||
def_site_span: Option<Span>,
|
||||
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);
|
||||
this.cx.span_err(path.span, &msg);
|
||||
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 } => {
|
||||
if ident.name == keywords::Invalid.name() {
|
||||
if ident.name == kw::Invalid {
|
||||
self.cx.span_err(path.span,
|
||||
&format!("macro {}! expects an ident argument", path));
|
||||
self.cx.trace_macros_diag();
|
||||
|
@ -828,7 +828,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
}
|
||||
|
||||
SyntaxExtension::ProcMacro { ref expander, ref allow_internal_unstable, edition } => {
|
||||
if ident.name != keywords::Invalid.name() {
|
||||
if ident.name != kw::Invalid {
|
||||
let msg =
|
||||
format!("macro {}! expects no ident argument, given '{}'", path, ident);
|
||||
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);
|
||||
let span = span.with_ctxt(self.cx.backtrace());
|
||||
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,
|
||||
node: ast::MetaItemKind::Word,
|
||||
};
|
||||
|
@ -1338,7 +1338,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
|||
})
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::ext::hygiene::Mark;
|
|||
use crate::tokenstream::TokenStream;
|
||||
use crate::mut_visit::*;
|
||||
use crate::ptr::P;
|
||||
use crate::symbol::keywords;
|
||||
use crate::symbol::kw;
|
||||
use crate::ThinVec;
|
||||
|
||||
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 generics = ast::Generics::default();
|
||||
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::token::{self, DocComment, Nonterminal, Token};
|
||||
use crate::print::pprust;
|
||||
use crate::symbol::keywords;
|
||||
use crate::symbol::kw;
|
||||
use crate::tokenstream::{DelimSpan, TokenStream};
|
||||
|
||||
use errors::FatalError;
|
||||
|
@ -382,7 +382,7 @@ fn nameize<I: Iterator<Item = NamedMatch>>(
|
|||
TokenTree::Delimited(_, ref delim) => for next_m in &delim.tts {
|
||||
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) {
|
||||
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
|
||||
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) {
|
||||
return Error(span, "missing fragment specifier".to_string());
|
||||
}
|
||||
|
@ -802,7 +802,7 @@ pub fn parse(
|
|||
/// We prohibit passing `_` to macros expecting `ident` for now.
|
||||
fn get_macro_ident(token: &Token) -> Option<(Ident, bool)> {
|
||||
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)),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
@ -1107,7 +1107,7 @@ fn is_in_follow(tok: "ed::TokenTree, frag: &str) -> IsInFollow {
|
|||
_ => IsInFollow::No(tokens),
|
||||
}
|
||||
},
|
||||
"" => IsInFollow::Yes, // keywords::Invalid
|
||||
"" => IsInFollow::Yes, // kw::Invalid
|
||||
_ => IsInFollow::Invalid(format!("invalid fragment specifier `{}`", frag),
|
||||
VALID_FRAGMENT_NAMES_MSG),
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::parse::{token, ParseSess};
|
|||
use crate::print::pprust;
|
||||
use crate::tokenstream::{self, DelimSpan};
|
||||
use crate::ast;
|
||||
use crate::symbol::keywords;
|
||||
use crate::symbol::kw;
|
||||
|
||||
use syntax_pos::{edition::Edition, BytePos, Span};
|
||||
|
||||
|
@ -228,7 +228,7 @@ pub fn parse(
|
|||
result.push(TokenTree::MetaVarDecl(
|
||||
span,
|
||||
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() => {
|
||||
let (ident, is_raw) = token.ident().unwrap();
|
||||
let span = ident_span.with_lo(span.lo());
|
||||
if ident.name == keywords::Crate.name() && !is_raw {
|
||||
let ident = ast::Ident::new(keywords::DollarCrate.name(), ident.span);
|
||||
if ident.name == kw::Crate && !is_raw {
|
||||
let ident = ast::Ident::new(kw::DollarCrate, ident.span);
|
||||
TokenTree::Token(span, token::Ident(ident, is_raw))
|
||||
} else {
|
||||
TokenTree::MetaVar(span, ident)
|
||||
|
@ -334,7 +334,7 @@ where
|
|||
pprust::token_to_string(&tok)
|
||||
);
|
||||
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.
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::ast::*;
|
|||
use crate::source_map::{Spanned, respan};
|
||||
use crate::parse::token::{self, Token};
|
||||
use crate::ptr::P;
|
||||
use crate::symbol::keywords;
|
||||
use crate::symbol::kw;
|
||||
use crate::ThinVec;
|
||||
use crate::tokenstream::*;
|
||||
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) {
|
||||
visit_clobber(krate, |Crate { module, attrs, span }| {
|
||||
let item = P(Item {
|
||||
ident: keywords::Invalid.ident(),
|
||||
ident: Ident::with_empty_ctxt(kw::Invalid),
|
||||
attrs,
|
||||
id: DUMMY_NODE_ID,
|
||||
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::unescape::{unescape_str, unescape_char, unescape_byte_str, unescape_byte};
|
||||
use crate::print::pprust;
|
||||
use crate::symbol::{keywords, Symbol};
|
||||
use crate::symbol::{kw, Symbol};
|
||||
use crate::tokenstream::{TokenStream, TokenTree};
|
||||
|
||||
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::print::pprust;
|
||||
use crate::ptr::P;
|
||||
use crate::symbol::keywords;
|
||||
use crate::symbol::kw;
|
||||
use crate::syntax::parse::parse_stream_from_source_str;
|
||||
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_path_segment_keyword() ||
|
||||
[
|
||||
keywords::Async.name(),
|
||||
kw::Async,
|
||||
|
||||
// FIXME: remove when `await!(..)` syntax is removed
|
||||
// https://github.com/rust-lang/rust/issues/60610
|
||||
keywords::Await.name(),
|
||||
kw::Await,
|
||||
|
||||
keywords::Do.name(),
|
||||
keywords::Box.name(),
|
||||
keywords::Break.name(),
|
||||
keywords::Continue.name(),
|
||||
keywords::False.name(),
|
||||
keywords::For.name(),
|
||||
keywords::If.name(),
|
||||
keywords::Loop.name(),
|
||||
keywords::Match.name(),
|
||||
keywords::Move.name(),
|
||||
keywords::Return.name(),
|
||||
keywords::True.name(),
|
||||
keywords::Unsafe.name(),
|
||||
keywords::While.name(),
|
||||
keywords::Yield.name(),
|
||||
keywords::Static.name(),
|
||||
kw::Do,
|
||||
kw::Box,
|
||||
kw::Break,
|
||||
kw::Continue,
|
||||
kw::False,
|
||||
kw::For,
|
||||
kw::If,
|
||||
kw::Loop,
|
||||
kw::Match,
|
||||
kw::Move,
|
||||
kw::Return,
|
||||
kw::True,
|
||||
kw::Unsafe,
|
||||
kw::While,
|
||||
kw::Yield,
|
||||
kw::Static,
|
||||
].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_path_segment_keyword() ||
|
||||
[
|
||||
keywords::Underscore.name(),
|
||||
keywords::For.name(),
|
||||
keywords::Impl.name(),
|
||||
keywords::Fn.name(),
|
||||
keywords::Unsafe.name(),
|
||||
keywords::Extern.name(),
|
||||
keywords::Typeof.name(),
|
||||
keywords::Dyn.name(),
|
||||
kw::Underscore,
|
||||
kw::For,
|
||||
kw::Impl,
|
||||
kw::Fn,
|
||||
kw::Unsafe,
|
||||
kw::Extern,
|
||||
kw::Typeof,
|
||||
kw::Dyn,
|
||||
].contains(&ident.name)
|
||||
}
|
||||
|
||||
|
@ -306,7 +306,7 @@ impl Token {
|
|||
|
||||
/// Returns `true` if the token can appear at the start of a generic bound.
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -324,8 +324,8 @@ impl Token {
|
|||
match *self {
|
||||
Literal(..) => true,
|
||||
BinOp(Minus) => true,
|
||||
Ident(ident, false) if ident.name == keywords::True.name() => true,
|
||||
Ident(ident, false) if ident.name == keywords::False.name() => true,
|
||||
Ident(ident, false) if ident.name == kw::True => true,
|
||||
Ident(ident, false) if ident.name == kw::False => true,
|
||||
Interpolated(ref nt) => match **nt {
|
||||
NtLiteral(..) => true,
|
||||
_ => false,
|
||||
|
@ -386,8 +386,8 @@ impl Token {
|
|||
|
||||
/// Returns `true` if the token is either the `mut` or `const` keyword.
|
||||
crate fn is_mutability(&self) -> bool {
|
||||
self.is_keyword(keywords::Mut) ||
|
||||
self.is_keyword(keywords::Const)
|
||||
self.is_keyword(kw::Mut) ||
|
||||
self.is_keyword(kw::Const)
|
||||
}
|
||||
|
||||
crate fn is_qpath_start(&self) -> bool {
|
||||
|
@ -400,8 +400,8 @@ impl Token {
|
|||
}
|
||||
|
||||
/// Returns `true` if the token is a given keyword, `kw`.
|
||||
pub fn is_keyword(&self, kw: keywords::Keyword) -> bool {
|
||||
self.ident().map(|(ident, is_raw)| ident.name == kw.name() && !is_raw).unwrap_or(false)
|
||||
pub fn is_keyword(&self, kw: Symbol) -> bool {
|
||||
self.ident().map(|(ident, is_raw)| ident.name == kw && !is_raw).unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn is_path_segment_keyword(&self) -> bool {
|
||||
|
@ -566,8 +566,8 @@ impl Token {
|
|||
|
||||
(&Lifetime(a), &Lifetime(b)) => a.name == b.name,
|
||||
(&Ident(a, b), &Ident(c, d)) => b == d && (a.name == c.name ||
|
||||
a.name == keywords::DollarCrate.name() ||
|
||||
c.name == keywords::DollarCrate.name()),
|
||||
a.name == kw::DollarCrate ||
|
||||
c.name == kw::DollarCrate),
|
||||
|
||||
(&Literal(ref a, b), &Literal(ref c, d)) => {
|
||||
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::ptr::P;
|
||||
use crate::std_inject;
|
||||
use crate::symbol::{keywords, sym};
|
||||
use crate::symbol::{kw, sym};
|
||||
use crate::tokenstream::{self, TokenStream, TokenTree};
|
||||
|
||||
use rustc_target::spec::abi::{self, Abi};
|
||||
|
@ -641,8 +641,8 @@ pub trait PrintState<'a> {
|
|||
if i > 0 {
|
||||
self.writer().word("::")?
|
||||
}
|
||||
if segment.ident.name != keywords::PathRoot.name() {
|
||||
if segment.ident.name == keywords::DollarCrate.name() {
|
||||
if segment.ident.name != kw::PathRoot {
|
||||
if segment.ident.name == kw::DollarCrate {
|
||||
self.print_dollar_crate(segment.ident)?;
|
||||
} else {
|
||||
self.writer().word(segment.ident.as_str().to_string())?;
|
||||
|
@ -1340,7 +1340,7 @@ impl<'a> State<'a> {
|
|||
self.s.word(";")?;
|
||||
}
|
||||
ast::ItemKind::Mac(ref mac) => {
|
||||
if item.ident.name == keywords::Invalid.name() {
|
||||
if item.ident.name == kw::Invalid {
|
||||
self.print_mac(mac)?;
|
||||
match mac.node.delim {
|
||||
MacDelimiter::Brace => {}
|
||||
|
@ -2400,8 +2400,8 @@ impl<'a> State<'a> {
|
|||
colons_before_params: bool)
|
||||
-> io::Result<()>
|
||||
{
|
||||
if segment.ident.name != keywords::PathRoot.name() {
|
||||
if segment.ident.name == keywords::DollarCrate.name() {
|
||||
if segment.ident.name != kw::PathRoot {
|
||||
if segment.ident.name == kw::DollarCrate {
|
||||
self.print_dollar_crate(segment.ident)?;
|
||||
} else {
|
||||
self.print_ident(segment.ident)?;
|
||||
|
@ -2984,7 +2984,7 @@ impl<'a> State<'a> {
|
|||
self.print_explicit_self(&eself)?;
|
||||
} else {
|
||||
let invalid = if let PatKind::Ident(_, ident, _) = input.pat.node {
|
||||
ident.name == keywords::Invalid.name()
|
||||
ident.name == kw::Invalid
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::ast;
|
|||
use crate::attr;
|
||||
use crate::edition::Edition;
|
||||
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::ptr::P;
|
||||
use crate::tokenstream::TokenStream;
|
||||
|
@ -107,7 +107,7 @@ pub fn maybe_inject_crates_ref(
|
|||
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
|
||||
node: ast::ItemKind::Use(P(ast::UseTree {
|
||||
prefix: ast::Path {
|
||||
segments: iter::once(keywords::PathRoot.ident())
|
||||
segments: iter::once(ast::Ident::with_empty_ctxt(kw::PathRoot))
|
||||
.chain(
|
||||
[name, "prelude", "v1"].iter().cloned()
|
||||
.map(ast::Ident::from_str)
|
||||
|
@ -118,7 +118,7 @@ pub fn maybe_inject_crates_ref(
|
|||
span,
|
||||
})),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
ident: keywords::Invalid.ident(),
|
||||
ident: ast::Ident::with_empty_ctxt(kw::Invalid),
|
||||
span,
|
||||
tokens: None,
|
||||
}));
|
||||
|
|
|
@ -29,7 +29,7 @@ use crate::parse::{token, ParseSess};
|
|||
use crate::print::pprust;
|
||||
use crate::ast::{self, Ident};
|
||||
use crate::ptr::P;
|
||||
use crate::symbol::{self, Symbol, keywords, sym};
|
||||
use crate::symbol::{self, Symbol, kw, sym};
|
||||
use crate::ThinVec;
|
||||
|
||||
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]> {
|
||||
let ident = i.ident;
|
||||
if ident.name != keywords::Invalid.name() {
|
||||
if ident.name != kw::Invalid {
|
||||
self.cx.path.push(ident);
|
||||
}
|
||||
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);
|
||||
}
|
||||
if ident.name != keywords::Invalid.name() {
|
||||
if ident.name != kw::Invalid {
|
||||
self.cx.path.pop();
|
||||
}
|
||||
smallvec![P(item)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::parse::token::{Token, BinOpToken};
|
||||
use crate::symbol::keywords;
|
||||
use crate::symbol::kw;
|
||||
use crate::ast::{self, BinOpKind};
|
||||
|
||||
/// Associative operator with precedence.
|
||||
|
@ -100,7 +100,7 @@ impl AssocOp {
|
|||
// DotDotDot is no longer supported, but we need some way to display the error
|
||||
Token::DotDotDot => Some(DotDotEq),
|
||||
Token::Colon => Some(Colon),
|
||||
_ if t.is_keyword(keywords::As) => Some(As),
|
||||
_ if t.is_keyword(kw::As) => Some(As),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use syntax::attr;
|
|||
use syntax::ext::base::{Annotatable, ExtCtxt};
|
||||
use syntax::ext::build::AstBuilder;
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::{Symbol, keywords, sym};
|
||||
use syntax::symbol::{Symbol, kw, sym};
|
||||
use syntax_pos::Span;
|
||||
|
||||
pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
|
||||
|
@ -129,7 +129,8 @@ fn cs_clone_shallow(name: &str,
|
|||
let mut stmts = Vec::new();
|
||||
if is_union {
|
||||
// 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");
|
||||
} else {
|
||||
match *substr.fields {
|
||||
|
|
|
@ -191,7 +191,7 @@ use syntax::ext::build::AstBuilder;
|
|||
use syntax::source_map::{self, respan};
|
||||
use syntax::util::map_in_place::MapInPlace;
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::{Symbol, keywords, sym};
|
||||
use syntax::symbol::{Symbol, kw, sym};
|
||||
use syntax::parse::ParseSess;
|
||||
use syntax_pos::{DUMMY_SP, Span};
|
||||
|
||||
|
@ -686,7 +686,7 @@ impl<'a> TraitDef<'a> {
|
|||
};
|
||||
|
||||
cx.item(self.span,
|
||||
keywords::Invalid.ident(),
|
||||
Ident::with_empty_ctxt(kw::Invalid),
|
||||
a,
|
||||
ast::ItemKind::Impl(unsafety,
|
||||
ast::ImplPolarity::Positive,
|
||||
|
@ -929,8 +929,8 @@ impl<'a> MethodDef<'a> {
|
|||
|
||||
let args = {
|
||||
let self_args = explicit_self.map(|explicit_self| {
|
||||
ast::Arg::from_self(explicit_self,
|
||||
keywords::SelfLower.ident().with_span_pos(trait_.span))
|
||||
let ident = Ident::with_empty_ctxt(kw::SelfLower).with_span_pos(trait_.span);
|
||||
ast::Arg::from_self(explicit_self, ident)
|
||||
});
|
||||
let nonself_args = arg_types.into_iter()
|
||||
.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::ptr::P;
|
||||
use syntax_pos::Span;
|
||||
use syntax_pos::symbol::keywords;
|
||||
use syntax_pos::symbol::kw;
|
||||
|
||||
/// The types of pointers
|
||||
#[derive(Clone)]
|
||||
|
@ -86,7 +86,7 @@ impl<'a> Path<'a> {
|
|||
PathKind::Local => cx.path_all(span, false, idents, params, Vec::new()),
|
||||
PathKind::Std => {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
use syntax::ast::{self, Ident, GenericArg};
|
||||
use syntax::ext::base::{self, *};
|
||||
use syntax::ext::build::AstBuilder;
|
||||
use syntax::symbol::{keywords, Symbol, sym};
|
||||
use syntax::symbol::{kw, sym, Symbol};
|
||||
use syntax_pos::Span;
|
||||
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 e = match env::var(&*var.as_str()) {
|
||||
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,
|
||||
true,
|
||||
cx.std_path(&["option", "Option", "None"]),
|
||||
|
|
|
@ -13,7 +13,7 @@ use syntax::mut_visit::MutVisitor;
|
|||
use syntax::parse::ParseSess;
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::symbol::{keywords, sym};
|
||||
use syntax::symbol::{kw, sym};
|
||||
use syntax::visit::{self, Visitor};
|
||||
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
|
@ -378,7 +378,7 @@ fn mk_decls(
|
|||
let custom_derive = Ident::from_str("custom_derive");
|
||||
let attr = Ident::from_str("attr");
|
||||
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 local_path = |sp: Span, name| {
|
||||
|
|
|
@ -14,7 +14,7 @@ use syntax::parse::lexer::comments;
|
|||
use syntax::parse::{self, token, ParseSess};
|
||||
use syntax::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
|
||||
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};
|
||||
|
||||
trait FromInternal<T> {
|
||||
|
@ -142,7 +142,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
|
|||
Question => op!('?'),
|
||||
SingleQuote => op!('\''),
|
||||
|
||||
Ident(ident, false) if ident.name == keywords::DollarCrate.name() =>
|
||||
Ident(ident, false) if ident.name == kw::DollarCrate =>
|
||||
tt!(Ident::dollar_crate()),
|
||||
Ident(ident, is_raw) => tt!(Ident::new(ident.name, is_raw)),
|
||||
Lifetime(ident) => {
|
||||
|
@ -347,7 +347,7 @@ impl Ident {
|
|||
}
|
||||
fn dollar_crate(span: Span) -> Ident {
|
||||
// `$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::feature_gate;
|
||||
use syntax::symbol::{keywords, sym};
|
||||
use syntax::symbol::{kw, sym};
|
||||
use syntax_pos::Span;
|
||||
use syntax::tokenstream::TokenTree;
|
||||
|
||||
|
@ -17,10 +17,10 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt<'_>,
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
(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.span_err(sp, "trace_macros! accepts only `true` or `false`"),
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
use crate::GLOBALS;
|
||||
use crate::Span;
|
||||
use crate::edition::Edition;
|
||||
use crate::symbol::{keywords, Symbol};
|
||||
use crate::symbol::{kw, Symbol};
|
||||
|
||||
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
|
@ -192,7 +192,7 @@ impl HygieneData {
|
|||
prev_ctxt: SyntaxContext(0),
|
||||
opaque: SyntaxContext(0),
|
||||
opaque_and_semitransparent: SyntaxContext(0),
|
||||
dollar_crate_name: keywords::DollarCrate.name(),
|
||||
dollar_crate_name: kw::DollarCrate,
|
||||
}],
|
||||
markings: FxHashMap::default(),
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ impl SyntaxContext {
|
|||
prev_ctxt: SyntaxContext::empty(),
|
||||
opaque: 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)
|
||||
})
|
||||
|
@ -312,7 +312,7 @@ impl SyntaxContext {
|
|||
prev_ctxt,
|
||||
opaque: new_opaque,
|
||||
opaque_and_semitransparent: new_opaque,
|
||||
dollar_crate_name: keywords::DollarCrate.name(),
|
||||
dollar_crate_name: kw::DollarCrate,
|
||||
});
|
||||
new_opaque
|
||||
});
|
||||
|
@ -330,7 +330,7 @@ impl SyntaxContext {
|
|||
prev_ctxt,
|
||||
opaque,
|
||||
opaque_and_semitransparent: new_opaque_and_semitransparent,
|
||||
dollar_crate_name: keywords::DollarCrate.name(),
|
||||
dollar_crate_name: kw::DollarCrate,
|
||||
});
|
||||
new_opaque_and_semitransparent
|
||||
});
|
||||
|
@ -346,7 +346,7 @@ impl SyntaxContext {
|
|||
prev_ctxt,
|
||||
opaque,
|
||||
opaque_and_semitransparent,
|
||||
dollar_crate_name: keywords::DollarCrate.name(),
|
||||
dollar_crate_name: kw::DollarCrate,
|
||||
});
|
||||
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
|
||||
);
|
||||
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");
|
||||
})
|
||||
}
|
||||
|
|
|
@ -692,7 +692,7 @@ impl Ident {
|
|||
/// Transforms an underscore identifier into one with the same name, but
|
||||
/// gensymed. Leaves non-underscore identifiers unchanged.
|
||||
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.
|
||||
|
@ -864,8 +864,8 @@ impl Interner {
|
|||
this.strings.reserve(init.len());
|
||||
|
||||
// We can't allocate empty strings in the arena, so handle this here.
|
||||
assert!(keywords::Invalid.name().as_u32() == 0 && init[0].is_empty());
|
||||
this.names.insert("", keywords::Invalid.name());
|
||||
assert!(kw::Invalid.as_u32() == 0 && init[0].is_empty());
|
||||
this.names.insert("", kw::Invalid);
|
||||
this.strings.push("");
|
||||
|
||||
for string in &init[1..] {
|
||||
|
@ -926,26 +926,9 @@ impl Interner {
|
|||
}
|
||||
}
|
||||
|
||||
pub mod keywords {
|
||||
use super::{Symbol, Ident};
|
||||
|
||||
#[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
|
||||
}
|
||||
}
|
||||
|
||||
// This module has a very short name because it's used a lot.
|
||||
pub mod kw {
|
||||
use super::Symbol;
|
||||
keywords!();
|
||||
}
|
||||
|
||||
|
@ -957,11 +940,11 @@ pub mod sym {
|
|||
|
||||
impl Symbol {
|
||||
fn is_used_keyword_2018(self) -> bool {
|
||||
self == keywords::Dyn.name()
|
||||
self == kw::Dyn
|
||||
}
|
||||
|
||||
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,
|
||||
// unnamed method parameters, crate root module, error recovery etc.
|
||||
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.
|
||||
pub fn is_used_keyword(self) -> bool {
|
||||
// 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()
|
||||
}
|
||||
|
||||
/// Returns `true` if the token is a keyword reserved for possible future use.
|
||||
pub fn is_unused_keyword(self) -> bool {
|
||||
// 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()
|
||||
}
|
||||
|
||||
|
@ -993,17 +976,17 @@ impl Ident {
|
|||
|
||||
/// A keyword or reserved identifier that can be used as a path segment.
|
||||
pub fn is_path_segment_keyword(self) -> bool {
|
||||
self.name == keywords::Super.name() ||
|
||||
self.name == keywords::SelfLower.name() ||
|
||||
self.name == keywords::SelfUpper.name() ||
|
||||
self.name == keywords::Crate.name() ||
|
||||
self.name == keywords::PathRoot.name() ||
|
||||
self.name == keywords::DollarCrate.name()
|
||||
self.name == kw::Super ||
|
||||
self.name == kw::SelfLower ||
|
||||
self.name == kw::SelfUpper ||
|
||||
self.name == kw::Crate ||
|
||||
self.name == kw::PathRoot ||
|
||||
self.name == kw::DollarCrate
|
||||
}
|
||||
|
||||
/// This identifier can be a raw identifier.
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -1267,7 +1250,7 @@ mod tests {
|
|||
fn without_first_quote_test() {
|
||||
GLOBALS.set(&Globals::new(edition::DEFAULT_EDITION), || {
|
||||
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