Eliminate unnecessary Ident::with_empty_ctxts
This commit is contained in:
@@ -1614,7 +1614,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
trace!("registering existential type with id {:#?}", exist_ty_id);
|
trace!("registering existential type with id {:#?}", exist_ty_id);
|
||||||
let exist_ty_item = hir::Item {
|
let exist_ty_item = hir::Item {
|
||||||
hir_id: exist_ty_id,
|
hir_id: exist_ty_id,
|
||||||
ident: Ident::with_empty_ctxt(kw::Invalid),
|
ident: Ident::invalid(),
|
||||||
attrs: Default::default(),
|
attrs: Default::default(),
|
||||||
node: exist_ty_item_kind,
|
node: exist_ty_item_kind,
|
||||||
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
|
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||||||
// information we encapsulate into, the better
|
// information we encapsulate into, the better
|
||||||
let def_data = match i.node {
|
let def_data = match i.node {
|
||||||
ItemKind::Impl(..) => DefPathData::Impl,
|
ItemKind::Impl(..) => DefPathData::Impl,
|
||||||
ItemKind::Mod(..) if i.ident == Ident::with_empty_ctxt(kw::Invalid) => {
|
ItemKind::Mod(..) if i.ident.name == kw::Invalid => {
|
||||||
return visit::walk_item(self, i);
|
return visit::walk_item(self, i);
|
||||||
}
|
}
|
||||||
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
|
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
|
||||||
|
|||||||
@@ -234,8 +234,7 @@ pub enum LifetimeName {
|
|||||||
impl LifetimeName {
|
impl LifetimeName {
|
||||||
pub fn ident(&self) -> Ident {
|
pub fn ident(&self) -> Ident {
|
||||||
match *self {
|
match *self {
|
||||||
LifetimeName::Implicit => Ident::with_empty_ctxt(kw::Invalid),
|
LifetimeName::Implicit | LifetimeName::Error => Ident::invalid(),
|
||||||
LifetimeName::Error => Ident::with_empty_ctxt(kw::Invalid),
|
|
||||||
LifetimeName::Underscore => Ident::with_empty_ctxt(kw::UnderscoreLifetime),
|
LifetimeName::Underscore => Ident::with_empty_ctxt(kw::UnderscoreLifetime),
|
||||||
LifetimeName::Static => Ident::with_empty_ctxt(kw::StaticLifetime),
|
LifetimeName::Static => Ident::with_empty_ctxt(kw::StaticLifetime),
|
||||||
LifetimeName::Param(param_name) => param_name.ident(),
|
LifetimeName::Param(param_name) => param_name.ident(),
|
||||||
|
|||||||
@@ -1602,7 +1602,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||||||
} {
|
} {
|
||||||
debug!("id = {:?} span = {:?} name = {:?}", id, span, name);
|
debug!("id = {:?} span = {:?} name = {:?}", id, span, name);
|
||||||
|
|
||||||
if name == ast::Ident::with_empty_ctxt(kw::UnderscoreLifetime) {
|
if name.name == kw::UnderscoreLifetime {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ impl<'a> Resolver<'a> {
|
|||||||
|
|
||||||
ItemKind::GlobalAsm(..) => {}
|
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(..) => {
|
ItemKind::Mod(..) => {
|
||||||
let def_id = self.definitions.local_def_id(item.id);
|
let def_id = self.definitions.local_def_id(item.id);
|
||||||
|
|||||||
@@ -460,7 +460,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
|||||||
(Some(fst), _) if fst.ident.span.rust_2018() &&
|
(Some(fst), _) if fst.ident.span.rust_2018() &&
|
||||||
!fst.ident.is_path_segment_keyword() => {
|
!fst.ident.is_path_segment_keyword() => {
|
||||||
// Insert a placeholder that's later replaced by `self`/`super`/etc.
|
// Insert a placeholder that's later replaced by `self`/`super`/etc.
|
||||||
path.insert(0, Segment::from_ident(Ident::with_empty_ctxt(kw::Invalid)));
|
path.insert(0, Segment::from_ident(Ident::invalid()));
|
||||||
}
|
}
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4669,7 +4669,7 @@ impl<'a> Resolver<'a> {
|
|||||||
{
|
{
|
||||||
let mut candidates = Vec::new();
|
let mut candidates = Vec::new();
|
||||||
let mut seen_modules = FxHashSet::default();
|
let mut seen_modules = FxHashSet::default();
|
||||||
let not_local_module = crate_name != 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)];
|
let mut worklist = vec![(start_module, Vec::<ast::PathSegment>::new(), not_local_module)];
|
||||||
|
|
||||||
while let Some((in_module,
|
while let Some((in_module,
|
||||||
|
|||||||
@@ -992,7 +992,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
|||||||
// HACK(eddyb) `lint_if_path_starts_with_module` needs at least
|
// HACK(eddyb) `lint_if_path_starts_with_module` needs at least
|
||||||
// 2 segments, so the `resolve_path` above won't trigger it.
|
// 2 segments, so the `resolve_path` above won't trigger it.
|
||||||
let mut full_path = directive.module_path.clone();
|
let mut full_path = directive.module_path.clone();
|
||||||
full_path.push(Segment::from_ident(Ident::with_empty_ctxt(kw::Invalid)));
|
full_path.push(Segment::from_ident(Ident::invalid()));
|
||||||
self.lint_if_path_starts_with_module(
|
self.lint_if_path_starts_with_module(
|
||||||
directive.crate_lint(),
|
directive.crate_lint(),
|
||||||
&full_path,
|
&full_path,
|
||||||
|
|||||||
@@ -1175,7 +1175,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
|||||||
vis: ast::Visibility, vp: P<ast::UseTree>) -> P<ast::Item> {
|
vis: ast::Visibility, vp: P<ast::UseTree>) -> P<ast::Item> {
|
||||||
P(ast::Item {
|
P(ast::Item {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
ident: Ident::with_empty_ctxt(kw::Invalid),
|
ident: Ident::invalid(),
|
||||||
attrs: vec![],
|
attrs: vec![],
|
||||||
node: ast::ItemKind::Use(vp),
|
node: ast::ItemKind::Use(vp),
|
||||||
vis,
|
vis,
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||||||
attrs: krate.attrs,
|
attrs: krate.attrs,
|
||||||
span: krate.span,
|
span: krate.span,
|
||||||
node: ast::ItemKind::Mod(krate.module),
|
node: ast::ItemKind::Mod(krate.module),
|
||||||
ident: Ident::with_empty_ctxt(kw::Invalid),
|
ident: Ident::invalid(),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
|
vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
|
||||||
tokens: None,
|
tokens: None,
|
||||||
@@ -708,7 +708,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||||||
};
|
};
|
||||||
let path = &mac.node.path;
|
let path = &mac.node.path;
|
||||||
|
|
||||||
let ident = ident.unwrap_or_else(|| 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
|
let validate_and_set_expn_info = |this: &mut Self, // arg instead of capture
|
||||||
def_site_span: Option<Span>,
|
def_site_span: Option<Span>,
|
||||||
allow_internal_unstable,
|
allow_internal_unstable,
|
||||||
@@ -929,7 +929,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||||||
invoc.expansion_data.mark.set_expn_info(expn_info);
|
invoc.expansion_data.mark.set_expn_info(expn_info);
|
||||||
let span = span.with_ctxt(self.cx.backtrace());
|
let span = span.with_ctxt(self.cx.backtrace());
|
||||||
let dummy = ast::MetaItem { // FIXME(jseyfried) avoid this
|
let dummy = ast::MetaItem { // FIXME(jseyfried) avoid this
|
||||||
path: Path::from_ident(Ident::with_empty_ctxt(kw::Invalid)),
|
path: Path::from_ident(Ident::invalid()),
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
node: ast::MetaItemKind::Word,
|
node: ast::MetaItemKind::Word,
|
||||||
};
|
};
|
||||||
@@ -1338,7 +1338,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
ast::ItemKind::Mod(ast::Mod { inner, .. }) => {
|
ast::ItemKind::Mod(ast::Mod { inner, .. }) => {
|
||||||
if item.ident == Ident::with_empty_ctxt(kw::Invalid) {
|
if item.ident == Ident::invalid() {
|
||||||
return noop_flat_map_item(item, self);
|
return noop_flat_map_item(item, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use crate::ext::hygiene::Mark;
|
|||||||
use crate::tokenstream::TokenStream;
|
use crate::tokenstream::TokenStream;
|
||||||
use crate::mut_visit::*;
|
use crate::mut_visit::*;
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::kw;
|
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
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 attrs = Vec::new();
|
||||||
let generics = ast::Generics::default();
|
let generics = ast::Generics::default();
|
||||||
let vis = dummy_spanned(ast::VisibilityKind::Inherited);
|
let vis = dummy_spanned(ast::VisibilityKind::Inherited);
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ pub fn parse(
|
|||||||
result.push(TokenTree::MetaVarDecl(
|
result.push(TokenTree::MetaVarDecl(
|
||||||
span,
|
span,
|
||||||
ident,
|
ident,
|
||||||
ast::Ident::with_empty_ctxt(kw::Invalid),
|
ast::Ident::invalid(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,7 +334,7 @@ where
|
|||||||
pprust::token_to_string(&tok)
|
pprust::token_to_string(&tok)
|
||||||
);
|
);
|
||||||
sess.span_diagnostic.span_err(span, &msg);
|
sess.span_diagnostic.span_err(span, &msg);
|
||||||
TokenTree::MetaVar(span, ast::Ident::with_empty_ctxt(kw::Invalid))
|
TokenTree::MetaVar(span, ast::Ident::invalid())
|
||||||
}
|
}
|
||||||
|
|
||||||
// There are no more tokens. Just return the `$` we already have.
|
// There are no more tokens. Just return the `$` we already have.
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ use crate::ast::*;
|
|||||||
use crate::source_map::{Spanned, respan};
|
use crate::source_map::{Spanned, respan};
|
||||||
use crate::parse::token::{self, Token};
|
use crate::parse::token::{self, Token};
|
||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::symbol::kw;
|
|
||||||
use crate::ThinVec;
|
use crate::ThinVec;
|
||||||
use crate::tokenstream::*;
|
use crate::tokenstream::*;
|
||||||
use crate::util::map_in_place::MapInPlace;
|
use crate::util::map_in_place::MapInPlace;
|
||||||
@@ -977,7 +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) {
|
pub fn noop_visit_crate<T: MutVisitor>(krate: &mut Crate, vis: &mut T) {
|
||||||
visit_clobber(krate, |Crate { module, attrs, span }| {
|
visit_clobber(krate, |Crate { module, attrs, span }| {
|
||||||
let item = P(Item {
|
let item = P(Item {
|
||||||
ident: Ident::with_empty_ctxt(kw::Invalid),
|
ident: Ident::invalid(),
|
||||||
attrs,
|
attrs,
|
||||||
id: DUMMY_NODE_ID,
|
id: DUMMY_NODE_ID,
|
||||||
vis: respan(span.shrink_to_lo(), VisibilityKind::Public),
|
vis: respan(span.shrink_to_lo(), VisibilityKind::Public),
|
||||||
|
|||||||
@@ -1480,9 +1480,7 @@ impl<'a> Parser<'a> {
|
|||||||
(ident, TraitItemKind::Const(ty, default), ast::Generics::default())
|
(ident, TraitItemKind::Const(ty, default), ast::Generics::default())
|
||||||
} else if let Some(mac) = self.parse_assoc_macro_invoc("trait", None, &mut false)? {
|
} else if let Some(mac) = self.parse_assoc_macro_invoc("trait", None, &mut false)? {
|
||||||
// trait item macro.
|
// trait item macro.
|
||||||
(Ident::with_empty_ctxt(kw::Invalid),
|
(Ident::invalid(), ast::TraitItemKind::Macro(mac), ast::Generics::default())
|
||||||
ast::TraitItemKind::Macro(mac),
|
|
||||||
ast::Generics::default())
|
|
||||||
} else {
|
} else {
|
||||||
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
|
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
|
||||||
|
|
||||||
@@ -4988,7 +4986,7 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
// it's a macro invocation
|
// it's a macro invocation
|
||||||
let id = match self.token {
|
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()?,
|
_ => self.parse_ident()?,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -6396,7 +6394,7 @@ impl<'a> Parser<'a> {
|
|||||||
// code copied from parse_macro_use_or_failure... abstraction!
|
// code copied from parse_macro_use_or_failure... abstraction!
|
||||||
if let Some(mac) = self.parse_assoc_macro_invoc("impl", Some(vis), at_end)? {
|
if let Some(mac) = self.parse_assoc_macro_invoc("impl", Some(vis), at_end)? {
|
||||||
// method macro
|
// method macro
|
||||||
Ok((Ident::with_empty_ctxt(kw::Invalid), vec![], ast::Generics::default(),
|
Ok((Ident::invalid(), vec![], ast::Generics::default(),
|
||||||
ast::ImplItemKind::Macro(mac)))
|
ast::ImplItemKind::Macro(mac)))
|
||||||
} else {
|
} else {
|
||||||
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
|
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>> {
|
fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec<GenericParam>> {
|
||||||
@@ -7414,7 +7412,7 @@ impl<'a> Parser<'a> {
|
|||||||
abi,
|
abi,
|
||||||
items: foreign_items
|
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))
|
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 span = lo.to(self.prev_span);
|
||||||
let item =
|
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));
|
return Ok(Some(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8108,7 +8106,7 @@ impl<'a> Parser<'a> {
|
|||||||
Some(mac) => {
|
Some(mac) => {
|
||||||
Ok(
|
Ok(
|
||||||
ForeignItem {
|
ForeignItem {
|
||||||
ident: Ident::with_empty_ctxt(kw::Invalid),
|
ident: Ident::invalid(),
|
||||||
span: lo.to(self.prev_span),
|
span: lo.to(self.prev_span),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
attrs,
|
attrs,
|
||||||
@@ -8155,7 +8153,7 @@ impl<'a> Parser<'a> {
|
|||||||
let id = if self.token.is_ident() {
|
let id = if self.token.is_ident() {
|
||||||
self.parse_ident()?
|
self.parse_ident()?
|
||||||
} else {
|
} else {
|
||||||
Ident::with_empty_ctxt(kw::Invalid) // no special identifier
|
Ident::invalid() // no special identifier
|
||||||
};
|
};
|
||||||
// eat a matched-delimiter token tree:
|
// eat a matched-delimiter token tree:
|
||||||
let (delim, tts) = self.expect_delimited_token_tree()?;
|
let (delim, tts) = self.expect_delimited_token_tree()?;
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ pub fn maybe_inject_crates_ref(
|
|||||||
span,
|
span,
|
||||||
})),
|
})),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
ident: ast::Ident::with_empty_ctxt(kw::Invalid),
|
ident: ast::Ident::invalid(),
|
||||||
span,
|
span,
|
||||||
tokens: None,
|
tokens: None,
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -686,7 +686,7 @@ impl<'a> TraitDef<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
cx.item(self.span,
|
cx.item(self.span,
|
||||||
Ident::with_empty_ctxt(kw::Invalid),
|
Ident::invalid(),
|
||||||
a,
|
a,
|
||||||
ast::ItemKind::Impl(unsafety,
|
ast::ItemKind::Impl(unsafety,
|
||||||
ast::ImplPolarity::Positive,
|
ast::ImplPolarity::Positive,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
|
|||||||
match parse_global_asm(cx, sp, tts) {
|
match parse_global_asm(cx, sp, tts) {
|
||||||
Ok(Some(global_asm)) => {
|
Ok(Some(global_asm)) => {
|
||||||
MacEager::items(smallvec![P(ast::Item {
|
MacEager::items(smallvec![P(ast::Item {
|
||||||
ident: ast::Ident::with_empty_ctxt(Symbol::intern("")),
|
ident: ast::Ident::invalid(),
|
||||||
attrs: Vec::new(),
|
attrs: Vec::new(),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: ast::ItemKind::GlobalAsm(P(global_asm)),
|
node: ast::ItemKind::GlobalAsm(P(global_asm)),
|
||||||
|
|||||||
@@ -641,6 +641,11 @@ impl Ident {
|
|||||||
Ident::new(name, DUMMY_SP)
|
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.
|
/// Maps an interned string to an identifier with an empty syntax context.
|
||||||
pub fn from_interned_str(string: InternedString) -> Ident {
|
pub fn from_interned_str(string: InternedString) -> Ident {
|
||||||
Ident::with_empty_ctxt(string.as_symbol())
|
Ident::with_empty_ctxt(string.as_symbol())
|
||||||
|
|||||||
Reference in New Issue
Block a user