Eliminate unnecessary Ident::with_empty_ctxts

This commit is contained in:
Vadim Petrochenkov 2019-05-11 19:08:09 +03:00
parent 59a382122f
commit c389a39c97
18 changed files with 33 additions and 33 deletions

View File

@ -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: Ident::with_empty_ctxt(kw::Invalid),
ident: Ident::invalid(),
attrs: Default::default(),
node: exist_ty_item_kind,
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),

View File

@ -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 == Ident::with_empty_ctxt(kw::Invalid) => {
ItemKind::Mod(..) if i.ident.name == kw::Invalid => {
return visit::walk_item(self, i);
}
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |

View File

@ -234,8 +234,7 @@ pub enum LifetimeName {
impl LifetimeName {
pub fn ident(&self) -> Ident {
match *self {
LifetimeName::Implicit => Ident::with_empty_ctxt(kw::Invalid),
LifetimeName::Error => Ident::with_empty_ctxt(kw::Invalid),
LifetimeName::Implicit | LifetimeName::Error => Ident::invalid(),
LifetimeName::Underscore => Ident::with_empty_ctxt(kw::UnderscoreLifetime),
LifetimeName::Static => Ident::with_empty_ctxt(kw::StaticLifetime),
LifetimeName::Param(param_name) => param_name.ident(),

View File

@ -1602,7 +1602,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
} {
debug!("id = {:?} span = {:?} name = {:?}", id, span, name);
if name == ast::Ident::with_empty_ctxt(kw::UnderscoreLifetime) {
if name.name == kw::UnderscoreLifetime {
continue;
}

View File

@ -420,7 +420,7 @@ impl<'a> Resolver<'a> {
ItemKind::GlobalAsm(..) => {}
ItemKind::Mod(..) if ident == Ident::with_empty_ctxt(kw::Invalid) => {} // Crate root
ItemKind::Mod(..) if ident.name == kw::Invalid => {} // Crate root
ItemKind::Mod(..) => {
let def_id = self.definitions.local_def_id(item.id);

View File

@ -460,7 +460,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
(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(Ident::with_empty_ctxt(kw::Invalid)));
path.insert(0, Segment::from_ident(Ident::invalid()));
}
_ => return None,
}

View File

@ -4669,7 +4669,7 @@ impl<'a> Resolver<'a> {
{
let mut candidates = Vec::new();
let mut seen_modules = FxHashSet::default();
let not_local_module = crate_name != Ident::with_empty_ctxt(kw::Crate);
let not_local_module = crate_name.name != kw::Crate;
let mut worklist = vec![(start_module, Vec::<ast::PathSegment>::new(), not_local_module)];
while let Some((in_module,

View File

@ -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(Ident::with_empty_ctxt(kw::Invalid)));
full_path.push(Segment::from_ident(Ident::invalid()));
self.lint_if_path_starts_with_module(
directive.crate_lint(),
&full_path,

View File

@ -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: Ident::with_empty_ctxt(kw::Invalid),
ident: Ident::invalid(),
attrs: vec![],
node: ast::ItemKind::Use(vp),
vis,

View File

@ -271,7 +271,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
attrs: krate.attrs,
span: krate.span,
node: ast::ItemKind::Mod(krate.module),
ident: Ident::with_empty_ctxt(kw::Invalid),
ident: Ident::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(|| Ident::with_empty_ctxt(kw::Invalid));
let ident = ident.unwrap_or_else(|| Ident::invalid());
let validate_and_set_expn_info = |this: &mut Self, // arg instead of capture
def_site_span: Option<Span>,
allow_internal_unstable,
@ -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(Ident::with_empty_ctxt(kw::Invalid)),
path: Path::from_ident(Ident::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 == Ident::with_empty_ctxt(kw::Invalid) {
if item.ident == Ident::invalid() {
return noop_flat_map_item(item, self);
}

View File

@ -6,7 +6,6 @@ use crate::ext::hygiene::Mark;
use crate::tokenstream::TokenStream;
use crate::mut_visit::*;
use crate::ptr::P;
use crate::symbol::kw;
use crate::ThinVec;
use smallvec::{smallvec, SmallVec};
@ -22,7 +21,7 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
})
}
let ident = ast::Ident::with_empty_ctxt(kw::Invalid);
let ident = ast::Ident::invalid();
let attrs = Vec::new();
let generics = ast::Generics::default();
let vis = dummy_spanned(ast::VisibilityKind::Inherited);

View File

@ -228,7 +228,7 @@ pub fn parse(
result.push(TokenTree::MetaVarDecl(
span,
ident,
ast::Ident::with_empty_ctxt(kw::Invalid),
ast::Ident::invalid(),
));
}
@ -334,7 +334,7 @@ where
pprust::token_to_string(&tok)
);
sess.span_diagnostic.span_err(span, &msg);
TokenTree::MetaVar(span, ast::Ident::with_empty_ctxt(kw::Invalid))
TokenTree::MetaVar(span, ast::Ident::invalid())
}
// There are no more tokens. Just return the `$` we already have.

View File

@ -11,7 +11,6 @@ use crate::ast::*;
use crate::source_map::{Spanned, respan};
use crate::parse::token::{self, Token};
use crate::ptr::P;
use crate::symbol::kw;
use crate::ThinVec;
use crate::tokenstream::*;
use crate::util::map_in_place::MapInPlace;
@ -977,7 +976,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: Ident::with_empty_ctxt(kw::Invalid),
ident: Ident::invalid(),
attrs,
id: DUMMY_NODE_ID,
vis: respan(span.shrink_to_lo(), VisibilityKind::Public),

View File

@ -1480,9 +1480,7 @@ impl<'a> Parser<'a> {
(ident, TraitItemKind::Const(ty, default), ast::Generics::default())
} else if let Some(mac) = self.parse_assoc_macro_invoc("trait", None, &mut false)? {
// trait item macro.
(Ident::with_empty_ctxt(kw::Invalid),
ast::TraitItemKind::Macro(mac),
ast::Generics::default())
(Ident::invalid(), ast::TraitItemKind::Macro(mac), ast::Generics::default())
} else {
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
@ -4988,7 +4986,7 @@ impl<'a> Parser<'a> {
// it's a macro invocation
let id = match self.token {
token::OpenDelim(_) => Ident::with_empty_ctxt(kw::Invalid), // no special identifier
token::OpenDelim(_) => Ident::invalid(), // no special identifier
_ => self.parse_ident()?,
};
@ -6396,7 +6394,7 @@ impl<'a> Parser<'a> {
// code copied from parse_macro_use_or_failure... abstraction!
if let Some(mac) = self.parse_assoc_macro_invoc("impl", Some(vis), at_end)? {
// method macro
Ok((Ident::with_empty_ctxt(kw::Invalid), vec![], ast::Generics::default(),
Ok((Ident::invalid(), vec![], ast::Generics::default(),
ast::ImplItemKind::Macro(mac)))
} else {
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
@ -6616,7 +6614,7 @@ impl<'a> Parser<'a> {
}
};
Ok((Ident::with_empty_ctxt(kw::Invalid), item_kind, Some(attrs)))
Ok((Ident::invalid(), item_kind, Some(attrs)))
}
fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec<GenericParam>> {
@ -7414,7 +7412,7 @@ impl<'a> Parser<'a> {
abi,
items: foreign_items
};
let invalid = Ident::with_empty_ctxt(kw::Invalid);
let invalid = Ident::invalid();
Ok(self.mk_item(lo.to(prev_span), invalid, ItemKind::ForeignMod(m), visibility, attrs))
}
@ -7662,7 +7660,7 @@ impl<'a> Parser<'a> {
let span = lo.to(self.prev_span);
let item =
self.mk_item(span, Ident::with_empty_ctxt(kw::Invalid), item_, visibility, attrs);
self.mk_item(span, Ident::invalid(), item_, visibility, attrs);
return Ok(Some(item));
}
@ -8108,7 +8106,7 @@ impl<'a> Parser<'a> {
Some(mac) => {
Ok(
ForeignItem {
ident: Ident::with_empty_ctxt(kw::Invalid),
ident: Ident::invalid(),
span: lo.to(self.prev_span),
id: ast::DUMMY_NODE_ID,
attrs,
@ -8155,7 +8153,7 @@ impl<'a> Parser<'a> {
let id = if self.token.is_ident() {
self.parse_ident()?
} else {
Ident::with_empty_ctxt(kw::Invalid) // no special identifier
Ident::invalid() // no special identifier
};
// eat a matched-delimiter token tree:
let (delim, tts) = self.expect_delimited_token_tree()?;

View File

@ -118,7 +118,7 @@ pub fn maybe_inject_crates_ref(
span,
})),
id: ast::DUMMY_NODE_ID,
ident: ast::Ident::with_empty_ctxt(kw::Invalid),
ident: ast::Ident::invalid(),
span,
tokens: None,
}));

View File

@ -686,7 +686,7 @@ impl<'a> TraitDef<'a> {
};
cx.item(self.span,
Ident::with_empty_ctxt(kw::Invalid),
Ident::invalid(),
a,
ast::ItemKind::Impl(unsafety,
ast::ImplPolarity::Positive,

View File

@ -37,7 +37,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
match parse_global_asm(cx, sp, tts) {
Ok(Some(global_asm)) => {
MacEager::items(smallvec![P(ast::Item {
ident: ast::Ident::with_empty_ctxt(Symbol::intern("")),
ident: ast::Ident::invalid(),
attrs: Vec::new(),
id: ast::DUMMY_NODE_ID,
node: ast::ItemKind::GlobalAsm(P(global_asm)),

View File

@ -641,6 +641,11 @@ impl Ident {
Ident::new(name, DUMMY_SP)
}
#[inline]
pub fn invalid() -> Ident {
Ident::with_empty_ctxt(kw::Invalid)
}
/// Maps an interned string to an identifier with an empty syntax context.
pub fn from_interned_str(string: InternedString) -> Ident {
Ident::with_empty_ctxt(string.as_symbol())