Skip to content

Commit

Permalink
Eliminate unnecessary Ident::with_empty_ctxts
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed May 22, 2019
1 parent 59a3821 commit c389a39
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..) |
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/ext/placeholders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/tt/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub fn parse(
result.push(TokenTree::MetaVarDecl(
span,
ident,
ast::Ident::with_empty_ctxt(kw::Invalid),
ast::Ident::invalid(),
));
}

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
18 changes: 8 additions & 10 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;

Expand Down Expand Up @@ -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()?,
};

Expand Down Expand Up @@ -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()?;
Expand Down Expand Up @@ -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>> {
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()?;
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/std_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}));
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/global_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
5 changes: 5 additions & 0 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit c389a39

Please sign in to comment.