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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)