Skip to content

Commit 0c46eb5

Browse files
committed
Remove non-keywords from keywords list.
Specifically, `Empty`, `PathRoot`, `DollarCrate`, and `Underscore`. They are turned into ordinary symbols. `is_special` is changed: `{{root}}` and the empty symbol are no longer considered special, but `$crate` and `_` still are. This is required to avoid changing any behaviour (in tests, etc.)
1 parent e96cd6c commit 0c46eb5

File tree

90 files changed

+280
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+280
-294
lines changed

compiler/rustc_ast/src/ast.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl fmt::Display for Lifetime {
9292
pub struct Path {
9393
pub span: Span,
9494
/// The segments in the path: the things separated by `::`.
95-
/// Global paths begin with `kw::PathRoot`.
95+
/// Global paths begin with `sym::path_root`.
9696
pub segments: ThinVec<PathSegment>,
9797
pub tokens: Option<LazyAttrTokenStream>,
9898
}
@@ -121,7 +121,7 @@ impl Path {
121121
}
122122

123123
pub fn is_global(&self) -> bool {
124-
!self.segments.is_empty() && self.segments[0].ident.name == kw::PathRoot
124+
!self.segments.is_empty() && self.segments[0].ident.name == sym::path_root
125125
}
126126

127127
/// If this path is a single identifier with no arguments, does not ensure
@@ -156,7 +156,7 @@ impl PathSegment {
156156
}
157157

158158
pub fn path_root(span: Span) -> Self {
159-
PathSegment::from_ident(Ident::new(kw::PathRoot, span))
159+
PathSegment::from_ident(Ident::new(sym::path_root, span))
160160
}
161161

162162
pub fn span(&self) -> Span {

compiler/rustc_ast/src/token.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: IdentIsRaw) -> bool {
326326

327327
!ident_token.is_reserved_ident()
328328
|| ident_token.is_path_segment_keyword()
329-
|| [kw::Underscore, kw::For, kw::Impl, kw::Fn, kw::Unsafe, kw::Extern, kw::Typeof, kw::Dyn]
329+
|| [sym::underscore, kw::For, kw::Impl, kw::Fn, kw::Unsafe, kw::Extern, kw::Typeof, kw::Dyn]
330330
.contains(&name)
331331
}
332332

@@ -922,8 +922,7 @@ impl Token {
922922
self.is_non_raw_ident_where(Ident::is_any_keyword)
923923
}
924924

925-
/// Returns true for reserved identifiers used internally for elided lifetimes,
926-
/// unnamed method parameters, crate root module, error recovery etc.
925+
/// Returns true for reserved identifiers.
927926
pub fn is_special_ident(&self) -> bool {
928927
self.is_non_raw_ident_where(Ident::is_special)
929928
}

compiler/rustc_ast_lowering/src/asm.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
77
use rustc_hir as hir;
88
use rustc_hir::def::{DefKind, Res};
99
use rustc_session::parse::feature_err;
10-
use rustc_span::symbol::kw;
1110
use rustc_span::{Span, sym};
1211
use rustc_target::asm;
1312

@@ -232,7 +231,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
232231
self.create_def(
233232
parent_def_id,
234233
node_id,
235-
kw::Empty,
234+
sym::empty,
236235
DefKind::AnonConst,
237236
*op_sp,
238237
);

compiler/rustc_ast_lowering/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::symbol::{Ident, Symbol, kw, sym};
16+
use rustc_span::symbol::{Ident, Symbol, sym};
1717
use rustc_span::{DUMMY_SP, DesugaringKind, Span};
1818
use thin_vec::{ThinVec, thin_vec};
1919
use visit::{Visitor, walk_expr};
@@ -457,7 +457,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
457457
if legacy_args_idx.contains(&idx) {
458458
let parent_def_id = self.current_hir_id_owner.def_id;
459459
let node_id = self.next_node_id();
460-
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
460+
self.create_def(parent_def_id, node_id, sym::empty, DefKind::AnonConst, f.span);
461461
let mut visitor = WillCreateDefIdsVisitor {};
462462
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
463463
AstP(Expr {

compiler/rustc_ast_lowering/src/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::*;
66
use rustc_data_structures::fx::FxIndexMap;
77
use rustc_hir as hir;
88
use rustc_session::config::FmtDebug;
9-
use rustc_span::symbol::{Ident, kw};
9+
use rustc_span::symbol::Ident;
1010
use rustc_span::{Span, Symbol, sym};
1111

1212
use super::LoweringContext;
@@ -416,7 +416,7 @@ fn expand_format_args<'hir>(
416416
&FormatArgsPiece::Placeholder(_) => {
417417
// Inject empty string before placeholders when not already preceded by a literal piece.
418418
if i == 0 || matches!(fmt.template[i - 1], FormatArgsPiece::Placeholder(_)) {
419-
Some(ctx.expr_str(fmt.span, kw::Empty))
419+
Some(ctx.expr_str(fmt.span, sym::empty))
420420
} else {
421421
None
422422
}

compiler/rustc_ast_lowering/src/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
564564
let path = if trees.is_empty()
565565
&& !(prefix.segments.is_empty()
566566
|| prefix.segments.len() == 1
567-
&& prefix.segments[0].ident.name == kw::PathRoot)
567+
&& prefix.segments[0].ident.name == sym::path_root)
568568
{
569569
// For empty lists we need to lower the prefix so it is checked for things
570570
// like stability later.
@@ -1173,7 +1173,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11731173
// This lets rustdoc render it correctly in documentation.
11741174
hir::PatKind::Binding(_, _, ident, _) => (ident, false),
11751175
hir::PatKind::Wild => {
1176-
(Ident::with_dummy_span(rustc_span::symbol::kw::Underscore), false)
1176+
(Ident::with_dummy_span(rustc_span::symbol::sym::underscore), false)
11771177
}
11781178
_ => {
11791179
// Replace the ident for bindings that aren't simple.

compiler/rustc_ast_lowering/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
907907
} else {
908908
let guar = self.dcx().has_errors().unwrap();
909909
MetaItemLit {
910-
symbol: kw::Empty,
910+
symbol: sym::empty,
911911
suffix: None,
912912
kind: LitKind::Err(guar),
913913
span: DUMMY_SP,
@@ -1502,7 +1502,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15021502
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
15031503
self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
15041504
PatKind::Ident(_, ident, _) => self.lower_ident(ident),
1505-
_ => Ident::new(kw::Empty, self.lower_span(param.pat.span)),
1505+
_ => Ident::new(sym::empty, self.lower_span(param.pat.span)),
15061506
}))
15071507
}
15081508

@@ -2086,7 +2086,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20862086
// so the def collector didn't create the def ahead of time. That's why we have to do
20872087
// it here.
20882088
let def_id =
2089-
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, span);
2089+
self.create_def(parent_def_id, node_id, sym::empty, DefKind::AnonConst, span);
20902090
let hir_id = self.lower_node_id(node_id);
20912091

20922092
let path_expr = Expr {
@@ -2382,7 +2382,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23822382
fn elided_dyn_bound(&mut self, span: Span) -> &'hir hir::Lifetime {
23832383
let r = hir::Lifetime {
23842384
hir_id: self.next_id(),
2385-
ident: Ident::new(kw::Empty, self.lower_span(span)),
2385+
ident: Ident::new(sym::empty, self.lower_span(span)),
23862386
res: hir::LifetimeName::ImplicitObjectLifetimeDefault,
23872387
};
23882388
debug!("elided_dyn_bound: r={:?}", r);

compiler/rustc_ast_lowering/src/path.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::def::{DefKind, PartialRes, Res};
66
use rustc_hir::def_id::DefId;
77
use rustc_middle::span_bug;
88
use rustc_session::parse::add_feature_diagnostics;
9-
use rustc_span::symbol::{Ident, kw, sym};
9+
use rustc_span::symbol::{Ident, sym};
1010
use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Span, Symbol};
1111
use smallvec::{SmallVec, smallvec};
1212
use tracing::{debug, instrument};
@@ -445,7 +445,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
445445
let id = NodeId::from_u32(i);
446446
let l = self.lower_lifetime(&Lifetime {
447447
id,
448-
ident: Ident::new(kw::Empty, elided_lifetime_span),
448+
ident: Ident::new(sym::empty, elided_lifetime_span),
449449
});
450450
GenericArg::Lifetime(l)
451451
}),

compiler/rustc_ast_passes/src/ast_validation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_session::lint::builtin::{
3535
};
3636
use rustc_session::lint::{BuiltinLintDiag, LintBuffer};
3737
use rustc_span::Span;
38-
use rustc_span::symbol::{Ident, kw, sym};
38+
use rustc_span::symbol::{Ident, sym};
3939
use rustc_target::spec::abi;
4040
use thin_vec::thin_vec;
4141

@@ -209,7 +209,7 @@ impl<'a> AstValidator<'a> {
209209

210210
fn visit_struct_field_def(&mut self, field: &'a FieldDef) {
211211
if let Some(ref ident) = field.ident
212-
&& ident.name == kw::Underscore
212+
&& ident.name == sym::underscore
213213
{
214214
self.visit_vis(&field.vis);
215215
self.visit_ident(ident);
@@ -563,7 +563,7 @@ impl<'a> AstValidator<'a> {
563563
}
564564

565565
fn check_item_named(&self, ident: Ident, kind: &str) {
566-
if ident.name != kw::Underscore {
566+
if ident.name != sym::underscore {
567567
return;
568568
}
569569
self.dcx().emit_err(errors::ItemUnderscore { span: ident.span, kind });

compiler/rustc_ast_pretty/src/pprust/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
834834
}
835835

836836
fn print_path_segment(&mut self, segment: &ast::PathSegment, colons_before_params: bool) {
837-
if segment.ident.name != kw::PathRoot {
837+
if segment.ident.name != sym::path_root {
838838
self.print_ident(segment.ident);
839839
if let Some(args) = &segment.args {
840840
self.print_generic_args(args, colons_before_params);
@@ -1909,7 +1909,7 @@ impl<'a> State<'a> {
19091909
self.print_explicit_self(&eself);
19101910
} else {
19111911
let invalid = if let PatKind::Ident(_, ident, _) = input.pat.kind {
1912-
ident.name == kw::Empty
1912+
ident.name == sym::empty
19131913
} else {
19141914
false
19151915
};

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
895895
// Skip `async` desugaring `impl Future`.
896896
}
897897
if let TyKind::TraitObject(_, lt, _) = alias_ty.kind {
898-
if lt.ident.name == kw::Empty {
898+
if lt.ident.name == sym::empty {
899899
spans_suggs.push((lt.ident.span.shrink_to_hi(), " + 'a".to_string()));
900900
} else {
901901
spans_suggs.push((lt.ident.span, "'a".to_string()));

compiler/rustc_builtin_macros/src/alloc_error_handler.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_ast::{
44
};
55
use rustc_expand::base::{Annotatable, ExtCtxt};
66
use rustc_span::Span;
7-
use rustc_span::symbol::{Ident, kw, sym};
7+
use rustc_span::symbol::{Ident, sym};
88
use thin_vec::{ThinVec, thin_vec};
99

1010
use crate::errors;
@@ -45,7 +45,7 @@ pub(crate) fn expand(
4545
// Generate anonymous constant serving as container for the allocator methods.
4646
let const_ty = ecx.ty(sig_span, TyKind::Tup(ThinVec::new()));
4747
let const_body = ecx.expr_block(ecx.block(span, stmts));
48-
let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body);
48+
let const_item = ecx.item_const(span, Ident::new(sym::underscore, span), const_ty, const_body);
4949
let const_item = if is_stmt {
5050
Annotatable::Stmt(P(ecx.stmt_item(span, const_item)))
5151
} else {

compiler/rustc_builtin_macros/src/asm.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -139,44 +139,44 @@ pub fn parse_asm_args<'a>(
139139
let mut explicit_reg = false;
140140
let op = if eat_operand_keyword(p, kw::In, asm_macro)? {
141141
let reg = parse_reg(p, &mut explicit_reg)?;
142-
if p.eat_keyword(kw::Underscore) {
142+
if p.eat_keyword(sym::underscore) {
143143
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
144144
return Err(err);
145145
}
146146
let expr = p.parse_expr()?;
147147
ast::InlineAsmOperand::In { reg, expr }
148148
} else if eat_operand_keyword(p, sym::out, asm_macro)? {
149149
let reg = parse_reg(p, &mut explicit_reg)?;
150-
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
150+
let expr = if p.eat_keyword(sym::underscore) { None } else { Some(p.parse_expr()?) };
151151
ast::InlineAsmOperand::Out { reg, expr, late: false }
152152
} else if eat_operand_keyword(p, sym::lateout, asm_macro)? {
153153
let reg = parse_reg(p, &mut explicit_reg)?;
154-
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
154+
let expr = if p.eat_keyword(sym::underscore) { None } else { Some(p.parse_expr()?) };
155155
ast::InlineAsmOperand::Out { reg, expr, late: true }
156156
} else if eat_operand_keyword(p, sym::inout, asm_macro)? {
157157
let reg = parse_reg(p, &mut explicit_reg)?;
158-
if p.eat_keyword(kw::Underscore) {
158+
if p.eat_keyword(sym::underscore) {
159159
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
160160
return Err(err);
161161
}
162162
let expr = p.parse_expr()?;
163163
if p.eat(&token::FatArrow) {
164164
let out_expr =
165-
if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
165+
if p.eat_keyword(sym::underscore) { None } else { Some(p.parse_expr()?) };
166166
ast::InlineAsmOperand::SplitInOut { reg, in_expr: expr, out_expr, late: false }
167167
} else {
168168
ast::InlineAsmOperand::InOut { reg, expr, late: false }
169169
}
170170
} else if eat_operand_keyword(p, sym::inlateout, asm_macro)? {
171171
let reg = parse_reg(p, &mut explicit_reg)?;
172-
if p.eat_keyword(kw::Underscore) {
172+
if p.eat_keyword(sym::underscore) {
173173
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
174174
return Err(err);
175175
}
176176
let expr = p.parse_expr()?;
177177
if p.eat(&token::FatArrow) {
178178
let out_expr =
179-
if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
179+
if p.eat_keyword(sym::underscore) { None } else { Some(p.parse_expr()?) };
180180
ast::InlineAsmOperand::SplitInOut { reg, in_expr: expr, out_expr, late: true }
181181
} else {
182182
ast::InlineAsmOperand::InOut { reg, expr, late: true }

compiler/rustc_builtin_macros/src/deriving/generic/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::ptr::P;
66
use rustc_ast::{self as ast, Expr, GenericArg, GenericParamKind, Generics, SelfKind};
77
use rustc_expand::base::ExtCtxt;
88
use rustc_span::source_map::respan;
9-
use rustc_span::symbol::{Ident, Symbol, kw};
9+
use rustc_span::symbol::{Ident, Symbol, sym};
1010
use rustc_span::{DUMMY_SP, Span};
1111
use thin_vec::ThinVec;
1212

@@ -62,7 +62,7 @@ impl Path {
6262
PathKind::Local => cx.path_all(span, false, idents, params),
6363
PathKind::Std => {
6464
let def_site = cx.with_def_site_ctxt(DUMMY_SP);
65-
idents.insert(0, Ident::new(kw::DollarCrate, def_site));
65+
idents.insert(0, Ident::new(sym::dollar_crate, def_site));
6666
cx.path_all(span, false, idents, params)
6767
}
6868
}

compiler/rustc_builtin_macros/src/global_allocator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_ast::{
88
};
99
use rustc_expand::base::{Annotatable, ExtCtxt};
1010
use rustc_span::Span;
11-
use rustc_span::symbol::{Ident, Symbol, kw, sym};
11+
use rustc_span::symbol::{Ident, Symbol, sym};
1212
use thin_vec::{ThinVec, thin_vec};
1313

1414
use crate::errors;
@@ -50,7 +50,7 @@ pub(crate) fn expand(
5050
// Generate anonymous constant serving as container for the allocator methods.
5151
let const_ty = ecx.ty(ty_span, TyKind::Tup(ThinVec::new()));
5252
let const_body = ecx.expr_block(ecx.block(span, stmts));
53-
let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body);
53+
let const_item = ecx.item_const(span, Ident::new(sym::underscore, span), const_ty, const_body);
5454
let const_item = if is_stmt {
5555
Annotatable::Stmt(P(ecx.stmt_item(span, const_item)))
5656
} else {

compiler/rustc_builtin_macros/src/proc_macro_harness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_feature::Features;
1111
use rustc_session::Session;
1212
use rustc_span::hygiene::AstPass;
1313
use rustc_span::source_map::SourceMap;
14-
use rustc_span::symbol::{Ident, Symbol, kw, sym};
14+
use rustc_span::symbol::{Ident, Symbol, sym};
1515
use rustc_span::{DUMMY_SP, Span};
1616
use smallvec::smallvec;
1717
use thin_vec::{ThinVec, thin_vec};
@@ -384,7 +384,7 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
384384

385385
let anon_constant = cx.item_const(
386386
span,
387-
Ident::new(kw::Underscore, span),
387+
Ident::new(sym::underscore, span),
388388
cx.ty(span, ast::TyKind::Tup(ThinVec::new())),
389389
block,
390390
);

compiler/rustc_builtin_macros/src/standard_library_imports.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_session::Session;
66
use rustc_span::DUMMY_SP;
77
use rustc_span::edition::Edition::*;
88
use rustc_span::hygiene::AstPass;
9-
use rustc_span::symbol::{Ident, Symbol, kw, sym};
9+
use rustc_span::symbol::{Ident, Symbol, sym};
1010
use thin_vec::thin_vec;
1111

1212
pub fn inject(
@@ -56,7 +56,7 @@ pub fn inject(
5656
// we do for the panic runtime, profiler runtime, etc.
5757
cx.item(
5858
span,
59-
Ident::new(kw::Underscore, ident_span),
59+
Ident::new(sym::underscore, ident_span),
6060
thin_vec![],
6161
ast::ItemKind::ExternCrate(Some(name)),
6262
)
@@ -75,7 +75,7 @@ pub fn inject(
7575
// the one with the prelude.
7676
let name = names[0];
7777

78-
let root = (edition == Edition2015).then_some(kw::PathRoot);
78+
let root = (edition == Edition2015).then_some(sym::path_root);
7979

8080
let import_path = root
8181
.iter()

0 commit comments

Comments
 (0)