Skip to content

Commit 80f0149

Browse files
committed
Eliminate unnecessary Ident::with_empty_ctxts
1 parent ce7f76d commit 80f0149

File tree

18 files changed

+33
-33
lines changed

18 files changed

+33
-33
lines changed

src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ impl<'a> LoweringContext<'a> {
16131613
trace!("registering existential type with id {:#?}", exist_ty_id);
16141614
let exist_ty_item = hir::Item {
16151615
hir_id: exist_ty_id,
1616-
ident: Ident::with_empty_ctxt(kw::Invalid),
1616+
ident: Ident::invalid(),
16171617
attrs: Default::default(),
16181618
node: exist_ty_item_kind,
16191619
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),

src/librustc/hir/map/def_collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
138138
// information we encapsulate into, the better
139139
let def_data = match i.node {
140140
ItemKind::Impl(..) => DefPathData::Impl,
141-
ItemKind::Mod(..) if i.ident == Ident::with_empty_ctxt(kw::Invalid) => {
141+
ItemKind::Mod(..) if i.ident.name == kw::Invalid => {
142142
return visit::walk_item(self, i);
143143
}
144144
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |

src/librustc/hir/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ pub enum LifetimeName {
234234
impl LifetimeName {
235235
pub fn ident(&self) -> Ident {
236236
match *self {
237-
LifetimeName::Implicit => Ident::with_empty_ctxt(kw::Invalid),
238-
LifetimeName::Error => Ident::with_empty_ctxt(kw::Invalid),
237+
LifetimeName::Implicit | LifetimeName::Error => Ident::invalid(),
239238
LifetimeName::Underscore => Ident::with_empty_ctxt(kw::UnderscoreLifetime),
240239
LifetimeName::Static => Ident::with_empty_ctxt(kw::StaticLifetime),
241240
LifetimeName::Param(param_name) => param_name.ident(),

src/librustc/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
16021602
} {
16031603
debug!("id = {:?} span = {:?} name = {:?}", id, span, name);
16041604

1605-
if name == ast::Ident::with_empty_ctxt(kw::UnderscoreLifetime) {
1605+
if name.name == kw::UnderscoreLifetime {
16061606
continue;
16071607
}
16081608

src/librustc_resolve/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl<'a> Resolver<'a> {
420420

421421
ItemKind::GlobalAsm(..) => {}
422422

423-
ItemKind::Mod(..) if ident == Ident::with_empty_ctxt(kw::Invalid) => {} // Crate root
423+
ItemKind::Mod(..) if ident.name == kw::Invalid => {} // Crate root
424424

425425
ItemKind::Mod(..) => {
426426
let def_id = self.definitions.local_def_id(item.id);

src/librustc_resolve/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
460460
(Some(fst), _) if fst.ident.span.rust_2018() &&
461461
!fst.ident.is_path_segment_keyword() => {
462462
// Insert a placeholder that's later replaced by `self`/`super`/etc.
463-
path.insert(0, Segment::from_ident(Ident::with_empty_ctxt(kw::Invalid)));
463+
path.insert(0, Segment::from_ident(Ident::invalid()));
464464
}
465465
_ => return None,
466466
}

src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4670,7 +4670,7 @@ impl<'a> Resolver<'a> {
46704670
{
46714671
let mut candidates = Vec::new();
46724672
let mut seen_modules = FxHashSet::default();
4673-
let not_local_module = crate_name != Ident::with_empty_ctxt(kw::Crate);
4673+
let not_local_module = crate_name.name != kw::Crate;
46744674
let mut worklist = vec![(start_module, Vec::<ast::PathSegment>::new(), not_local_module)];
46754675

46764676
while let Some((in_module,

src/librustc_resolve/resolve_imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
992992
// HACK(eddyb) `lint_if_path_starts_with_module` needs at least
993993
// 2 segments, so the `resolve_path` above won't trigger it.
994994
let mut full_path = directive.module_path.clone();
995-
full_path.push(Segment::from_ident(Ident::with_empty_ctxt(kw::Invalid)));
995+
full_path.push(Segment::from_ident(Ident::invalid()));
996996
self.lint_if_path_starts_with_module(
997997
directive.crate_lint(),
998998
&full_path,

src/libsyntax/ext/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
11751175
vis: ast::Visibility, vp: P<ast::UseTree>) -> P<ast::Item> {
11761176
P(ast::Item {
11771177
id: ast::DUMMY_NODE_ID,
1178-
ident: Ident::with_empty_ctxt(kw::Invalid),
1178+
ident: Ident::invalid(),
11791179
attrs: vec![],
11801180
node: ast::ItemKind::Use(vp),
11811181
vis,

src/libsyntax/ext/expand.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
271271
attrs: krate.attrs,
272272
span: krate.span,
273273
node: ast::ItemKind::Mod(krate.module),
274-
ident: Ident::with_empty_ctxt(kw::Invalid),
274+
ident: Ident::invalid(),
275275
id: ast::DUMMY_NODE_ID,
276276
vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
277277
tokens: None,
@@ -708,7 +708,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
708708
};
709709
let path = &mac.node.path;
710710

711-
let ident = ident.unwrap_or_else(|| Ident::with_empty_ctxt(kw::Invalid));
711+
let ident = ident.unwrap_or_else(|| Ident::invalid());
712712
let validate_and_set_expn_info = |this: &mut Self, // arg instead of capture
713713
def_site_span: Option<Span>,
714714
allow_internal_unstable,
@@ -929,7 +929,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
929929
invoc.expansion_data.mark.set_expn_info(expn_info);
930930
let span = span.with_ctxt(self.cx.backtrace());
931931
let dummy = ast::MetaItem { // FIXME(jseyfried) avoid this
932-
path: Path::from_ident(Ident::with_empty_ctxt(kw::Invalid)),
932+
path: Path::from_ident(Ident::invalid()),
933933
span: DUMMY_SP,
934934
node: ast::MetaItemKind::Word,
935935
};
@@ -1338,7 +1338,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13381338
})
13391339
}
13401340
ast::ItemKind::Mod(ast::Mod { inner, .. }) => {
1341-
if item.ident == Ident::with_empty_ctxt(kw::Invalid) {
1341+
if item.ident == Ident::invalid() {
13421342
return noop_flat_map_item(item, self);
13431343
}
13441344

src/libsyntax/ext/placeholders.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::ext::hygiene::Mark;
66
use crate::tokenstream::TokenStream;
77
use crate::mut_visit::*;
88
use crate::ptr::P;
9-
use crate::symbol::kw;
109
use crate::ThinVec;
1110

1211
use smallvec::{smallvec, SmallVec};
@@ -22,7 +21,7 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
2221
})
2322
}
2423

25-
let ident = ast::Ident::with_empty_ctxt(kw::Invalid);
24+
let ident = ast::Ident::invalid();
2625
let attrs = Vec::new();
2726
let generics = ast::Generics::default();
2827
let vis = dummy_spanned(ast::VisibilityKind::Inherited);

src/libsyntax/ext/tt/quoted.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub fn parse(
228228
result.push(TokenTree::MetaVarDecl(
229229
span,
230230
ident,
231-
ast::Ident::with_empty_ctxt(kw::Invalid),
231+
ast::Ident::invalid(),
232232
));
233233
}
234234

@@ -334,7 +334,7 @@ where
334334
pprust::token_to_string(&tok)
335335
);
336336
sess.span_diagnostic.span_err(span, &msg);
337-
TokenTree::MetaVar(span, ast::Ident::with_empty_ctxt(kw::Invalid))
337+
TokenTree::MetaVar(span, ast::Ident::invalid())
338338
}
339339

340340
// There are no more tokens. Just return the `$` we already have.

src/libsyntax/mut_visit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::ast::*;
1111
use crate::source_map::{Spanned, respan};
1212
use crate::parse::token::{self, Token};
1313
use crate::ptr::P;
14-
use crate::symbol::kw;
1514
use crate::ThinVec;
1615
use crate::tokenstream::*;
1716
use crate::util::map_in_place::MapInPlace;
@@ -977,7 +976,7 @@ pub fn noop_visit_mod<T: MutVisitor>(Mod { inner, items, inline: _ }: &mut Mod,
977976
pub fn noop_visit_crate<T: MutVisitor>(krate: &mut Crate, vis: &mut T) {
978977
visit_clobber(krate, |Crate { module, attrs, span }| {
979978
let item = P(Item {
980-
ident: Ident::with_empty_ctxt(kw::Invalid),
979+
ident: Ident::invalid(),
981980
attrs,
982981
id: DUMMY_NODE_ID,
983982
vis: respan(span.shrink_to_lo(), VisibilityKind::Public),

src/libsyntax/parse/parser.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1530,9 +1530,7 @@ impl<'a> Parser<'a> {
15301530
(ident, TraitItemKind::Const(ty, default), ast::Generics::default())
15311531
} else if let Some(mac) = self.parse_assoc_macro_invoc("trait", None, &mut false)? {
15321532
// trait item macro.
1533-
(Ident::with_empty_ctxt(kw::Invalid),
1534-
ast::TraitItemKind::Macro(mac),
1535-
ast::Generics::default())
1533+
(Ident::invalid(), ast::TraitItemKind::Macro(mac), ast::Generics::default())
15361534
} else {
15371535
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
15381536

@@ -5169,7 +5167,7 @@ impl<'a> Parser<'a> {
51695167

51705168
// it's a macro invocation
51715169
let id = match self.token {
5172-
token::OpenDelim(_) => Ident::with_empty_ctxt(kw::Invalid), // no special identifier
5170+
token::OpenDelim(_) => Ident::invalid(), // no special identifier
51735171
_ => self.parse_ident()?,
51745172
};
51755173

@@ -6577,7 +6575,7 @@ impl<'a> Parser<'a> {
65776575
// code copied from parse_macro_use_or_failure... abstraction!
65786576
if let Some(mac) = self.parse_assoc_macro_invoc("impl", Some(vis), at_end)? {
65796577
// method macro
6580-
Ok((Ident::with_empty_ctxt(kw::Invalid), vec![], ast::Generics::default(),
6578+
Ok((Ident::invalid(), vec![], ast::Generics::default(),
65816579
ast::ImplItemKind::Macro(mac)))
65826580
} else {
65836581
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
@@ -6797,7 +6795,7 @@ impl<'a> Parser<'a> {
67976795
}
67986796
};
67996797

6800-
Ok((Ident::with_empty_ctxt(kw::Invalid), item_kind, Some(attrs)))
6798+
Ok((Ident::invalid(), item_kind, Some(attrs)))
68016799
}
68026800

68036801
fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec<GenericParam>> {
@@ -7614,7 +7612,7 @@ impl<'a> Parser<'a> {
76147612
abi,
76157613
items: foreign_items
76167614
};
7617-
let invalid = Ident::with_empty_ctxt(kw::Invalid);
7615+
let invalid = Ident::invalid();
76187616
Ok(self.mk_item(lo.to(prev_span), invalid, ItemKind::ForeignMod(m), visibility, attrs))
76197617
}
76207618

@@ -7862,7 +7860,7 @@ impl<'a> Parser<'a> {
78627860

78637861
let span = lo.to(self.prev_span);
78647862
let item =
7865-
self.mk_item(span, Ident::with_empty_ctxt(kw::Invalid), item_, visibility, attrs);
7863+
self.mk_item(span, Ident::invalid(), item_, visibility, attrs);
78667864
return Ok(Some(item));
78677865
}
78687866

@@ -8308,7 +8306,7 @@ impl<'a> Parser<'a> {
83088306
Some(mac) => {
83098307
Ok(
83108308
ForeignItem {
8311-
ident: Ident::with_empty_ctxt(kw::Invalid),
8309+
ident: Ident::invalid(),
83128310
span: lo.to(self.prev_span),
83138311
id: ast::DUMMY_NODE_ID,
83148312
attrs,
@@ -8355,7 +8353,7 @@ impl<'a> Parser<'a> {
83558353
let id = if self.token.is_ident() {
83568354
self.parse_ident()?
83578355
} else {
8358-
Ident::with_empty_ctxt(kw::Invalid) // no special identifier
8356+
Ident::invalid() // no special identifier
83598357
};
83608358
// eat a matched-delimiter token tree:
83618359
let (delim, tts) = self.expect_delimited_token_tree()?;

src/libsyntax/std_inject.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn maybe_inject_crates_ref(
119119
span,
120120
})),
121121
id: ast::DUMMY_NODE_ID,
122-
ident: ast::Ident::with_empty_ctxt(kw::Invalid),
122+
ident: ast::Ident::invalid(),
123123
span,
124124
tokens: None,
125125
}));

src/libsyntax_ext/deriving/generic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ impl<'a> TraitDef<'a> {
686686
};
687687

688688
cx.item(self.span,
689-
Ident::with_empty_ctxt(kw::Invalid),
689+
Ident::invalid(),
690690
a,
691691
ast::ItemKind::Impl(unsafety,
692692
ast::ImplPolarity::Positive,

src/libsyntax_ext/global_asm.rs

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

src/libsyntax_pos/symbol.rs

+5
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,11 @@ impl Ident {
622622
Ident::new(name, DUMMY_SP)
623623
}
624624

625+
#[inline]
626+
pub fn invalid() -> Ident {
627+
Ident::with_empty_ctxt(kw::Invalid)
628+
}
629+
625630
/// Maps an interned string to an identifier with an empty syntax context.
626631
pub fn from_interned_str(string: InternedString) -> Ident {
627632
Ident::with_empty_ctxt(string.as_symbol())

0 commit comments

Comments
 (0)