Skip to content

Commit c389a39

Browse files
committed
Eliminate unnecessary Ident::with_empty_ctxts
1 parent 59a3821 commit c389a39

File tree

18 files changed

+33
-33
lines changed

18 files changed

+33
-33
lines changed

src/librustc/hir/lowering.rs

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

src/librustc/hir/map/def_collector.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4669,7 +4669,7 @@ impl<'a> Resolver<'a> {
46694669
{
46704670
let mut candidates = Vec::new();
46714671
let mut seen_modules = FxHashSet::default();
4672-
let not_local_module = crate_name != Ident::with_empty_ctxt(kw::Crate);
4672+
let not_local_module = crate_name.name != kw::Crate;
46734673
let mut worklist = vec![(start_module, Vec::<ast::PathSegment>::new(), not_local_module)];
46744674

46754675
while let Some((in_module,

src/librustc_resolve/resolve_imports.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,9 +1480,7 @@ impl<'a> Parser<'a> {
14801480
(ident, TraitItemKind::Const(ty, default), ast::Generics::default())
14811481
} else if let Some(mac) = self.parse_assoc_macro_invoc("trait", None, &mut false)? {
14821482
// trait item macro.
1483-
(Ident::with_empty_ctxt(kw::Invalid),
1484-
ast::TraitItemKind::Macro(mac),
1485-
ast::Generics::default())
1483+
(Ident::invalid(), ast::TraitItemKind::Macro(mac), ast::Generics::default())
14861484
} else {
14871485
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
14881486

@@ -4988,7 +4986,7 @@ impl<'a> Parser<'a> {
49884986

49894987
// it's a macro invocation
49904988
let id = match self.token {
4991-
token::OpenDelim(_) => Ident::with_empty_ctxt(kw::Invalid), // no special identifier
4989+
token::OpenDelim(_) => Ident::invalid(), // no special identifier
49924990
_ => self.parse_ident()?,
49934991
};
49944992

@@ -6396,7 +6394,7 @@ impl<'a> Parser<'a> {
63966394
// code copied from parse_macro_use_or_failure... abstraction!
63976395
if let Some(mac) = self.parse_assoc_macro_invoc("impl", Some(vis), at_end)? {
63986396
// method macro
6399-
Ok((Ident::with_empty_ctxt(kw::Invalid), vec![], ast::Generics::default(),
6397+
Ok((Ident::invalid(), vec![], ast::Generics::default(),
64006398
ast::ImplItemKind::Macro(mac)))
64016399
} else {
64026400
let (constness, unsafety, mut asyncness, abi) = self.parse_fn_front_matter()?;
@@ -6616,7 +6614,7 @@ impl<'a> Parser<'a> {
66166614
}
66176615
};
66186616

6619-
Ok((Ident::with_empty_ctxt(kw::Invalid), item_kind, Some(attrs)))
6617+
Ok((Ident::invalid(), item_kind, Some(attrs)))
66206618
}
66216619

66226620
fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec<GenericParam>> {
@@ -7414,7 +7412,7 @@ impl<'a> Parser<'a> {
74147412
abi,
74157413
items: foreign_items
74167414
};
7417-
let invalid = Ident::with_empty_ctxt(kw::Invalid);
7415+
let invalid = Ident::invalid();
74187416
Ok(self.mk_item(lo.to(prev_span), invalid, ItemKind::ForeignMod(m), visibility, attrs))
74197417
}
74207418

@@ -7662,7 +7660,7 @@ impl<'a> Parser<'a> {
76627660

76637661
let span = lo.to(self.prev_span);
76647662
let item =
7665-
self.mk_item(span, Ident::with_empty_ctxt(kw::Invalid), item_, visibility, attrs);
7663+
self.mk_item(span, Ident::invalid(), item_, visibility, attrs);
76667664
return Ok(Some(item));
76677665
}
76687666

@@ -8108,7 +8106,7 @@ impl<'a> Parser<'a> {
81088106
Some(mac) => {
81098107
Ok(
81108108
ForeignItem {
8111-
ident: Ident::with_empty_ctxt(kw::Invalid),
8109+
ident: Ident::invalid(),
81128110
span: lo.to(self.prev_span),
81138111
id: ast::DUMMY_NODE_ID,
81148112
attrs,
@@ -8155,7 +8153,7 @@ impl<'a> Parser<'a> {
81558153
let id = if self.token.is_ident() {
81568154
self.parse_ident()?
81578155
} else {
8158-
Ident::with_empty_ctxt(kw::Invalid) // no special identifier
8156+
Ident::invalid() // no special identifier
81598157
};
81608158
// eat a matched-delimiter token tree:
81618159
let (delim, tts) = self.expect_delimited_token_tree()?;

src/libsyntax/std_inject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub fn maybe_inject_crates_ref(
118118
span,
119119
})),
120120
id: ast::DUMMY_NODE_ID,
121-
ident: ast::Ident::with_empty_ctxt(kw::Invalid),
121+
ident: ast::Ident::invalid(),
122122
span,
123123
tokens: None,
124124
}));

src/libsyntax_ext/deriving/generic/mod.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,11 @@ impl Ident {
641641
Ident::new(name, DUMMY_SP)
642642
}
643643

644+
#[inline]
645+
pub fn invalid() -> Ident {
646+
Ident::with_empty_ctxt(kw::Invalid)
647+
}
648+
644649
/// Maps an interned string to an identifier with an empty syntax context.
645650
pub fn from_interned_str(string: InternedString) -> Ident {
646651
Ident::with_empty_ctxt(string.as_symbol())

0 commit comments

Comments
 (0)