Skip to content

Commit ebf1508

Browse files
committed
Remove '_ from the keyword list.
The anonymous lifetime `'_` is not a keyword according to the Reference and the Ferrocene spec. This commit changes it to a symbol. It wasn't included in any of the `Symbol::is_*` functions, so this has no functional effect.
1 parent a94fce9 commit ebf1508

File tree

20 files changed

+45
-43
lines changed

20 files changed

+45
-43
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
755755
let _def_id = self.create_def(
756756
self.current_hir_id_owner.def_id,
757757
param,
758-
kw::UnderscoreLifetime,
758+
sym::underscore_lifetime,
759759
DefKind::LifetimeParam,
760760
ident.span,
761761
);
@@ -1187,7 +1187,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11871187
self.next_node_id()
11881188
};
11891189
let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
1190-
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
1190+
Lifetime { ident: Ident::new(sym::underscore_lifetime, span), id }
11911191
});
11921192
let lifetime = self.lower_lifetime(&region);
11931193
hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx))
@@ -1203,7 +1203,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12031203
self.next_node_id()
12041204
};
12051205
let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
1206-
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
1206+
Lifetime { ident: Ident::new(sym::underscore_lifetime, span), id }
12071207
});
12081208
let lifetime = self.lower_lifetime(&region);
12091209
let kind = hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx));

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::mir::{
1717
};
1818
use rustc_middle::ty::adjustment::PointerCoercion;
1919
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
20-
use rustc_span::symbol::{Symbol, kw};
20+
use rustc_span::symbol::Symbol;
2121
use rustc_span::{DesugaringKind, Span, sym};
2222
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
2323
use tracing::{debug, instrument};
@@ -418,7 +418,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
418418
}
419419
if let ConstraintCategory::OpaqueType = category {
420420
let suggestable_name =
421-
if region_name.was_named() { region_name.name } else { kw::UnderscoreLifetime };
421+
if region_name.was_named() { region_name.name } else { sym::underscore_lifetime };
422422

423423
let msg = format!(
424424
"you can add a bound to the {}to make it last less than `'static` and match `{region_name}`",

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::hir::place::PlaceBase;
1616
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
1717
use rustc_middle::ty::{self, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeVisitor};
1818
use rustc_span::Span;
19-
use rustc_span::symbol::{Ident, kw};
19+
use rustc_span::symbol::{Ident, kw, sym};
2020
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2121
use rustc_trait_selection::error_reporting::infer::nice_region_error::{
2222
self, HirTraitObjectVisitor, NiceRegionError, TraitObjectVisitor, find_anon_type,
@@ -786,7 +786,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
786786
// These situations are bound to result in errors.
787787
// To prevent an immediate ICE, we opt to create a dummy name instead.
788788
let fr_name = self.give_region_a_name(*fr).unwrap_or(RegionName {
789-
name: kw::UnderscoreLifetime,
789+
name: sym::underscore_lifetime,
790790
source: RegionNameSource::Static,
791791
});
792792
fr_name.highlight_region_name(&mut diag);
@@ -858,7 +858,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
858858
return;
859859
};
860860

861-
let lifetime = if f.has_name() { fr_name.name } else { kw::UnderscoreLifetime };
861+
let lifetime = if f.has_name() { fr_name.name } else { sym::underscore_lifetime };
862862

863863
let arg = match param.param.pat.simple_ident() {
864864
Some(simple_ident) => format!("argument `{simple_ident}`"),

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl ParamName {
7575
pub fn ident(&self) -> Ident {
7676
match *self {
7777
ParamName::Plain(ident) => ident,
78-
ParamName::Fresh | ParamName::Error => Ident::with_dummy_span(kw::UnderscoreLifetime),
78+
ParamName::Fresh | ParamName::Error => Ident::with_dummy_span(sym::underscore_lifetime),
7979
}
8080
}
8181
}
@@ -149,7 +149,7 @@ impl Lifetime {
149149
}
150150

151151
pub fn is_anonymous(&self) -> bool {
152-
self.ident.name == kw::Empty || self.ident.name == kw::UnderscoreLifetime
152+
self.ident.name == kw::Empty || self.ident.name == sym::underscore_lifetime
153153
}
154154

155155
pub fn suggestion_position(&self) -> (LifetimeSuggestionPosition, Span) {

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use rustc_middle::ty::{
4545
use rustc_middle::{bug, span_bug};
4646
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
4747
use rustc_span::edit_distance::find_best_match_for_name;
48-
use rustc_span::symbol::{Ident, Symbol, kw};
48+
use rustc_span::symbol::{Ident, Symbol, kw, sym};
4949
use rustc_span::{DUMMY_SP, Span};
5050
use rustc_trait_selection::infer::InferCtxtExt;
5151
use rustc_trait_selection::traits::wf::object_region_bounds;
@@ -2655,15 +2655,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
26552655
) {
26562656
for br in referenced_regions.difference(&constrained_regions) {
26572657
let br_name = match *br {
2658-
ty::BoundRegionKind::Named(_, kw::UnderscoreLifetime)
2658+
ty::BoundRegionKind::Named(_, sym::underscore_lifetime)
26592659
| ty::BoundRegionKind::Anon
26602660
| ty::BoundRegionKind::ClosureEnv => "an anonymous lifetime".to_string(),
26612661
ty::BoundRegionKind::Named(_, name) => format!("lifetime `{name}`"),
26622662
};
26632663

26642664
let mut err = generate_err(&br_name);
26652665

2666-
if let ty::BoundRegionKind::Named(_, kw::UnderscoreLifetime)
2666+
if let ty::BoundRegionKind::Named(_, sym::underscore_lifetime)
26672667
| ty::BoundRegionKind::Anon = *br
26682668
{
26692669
// The only way for an anonymous lifetime to wind up

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_data_structures::fx::FxHashMap;
33
use rustc_hir::def_id::DefId;
44
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
55
use rustc_span::Span;
6-
use rustc_span::symbol::{Symbol, kw};
6+
use rustc_span::symbol::{Symbol, kw, sym};
77
use tracing::instrument;
88

99
use super::{Clause, InstantiatedPredicates, ParamConst, ParamTy, Ty, TyCtxt};
@@ -75,7 +75,7 @@ impl GenericParamDef {
7575
pub fn is_anonymous_lifetime(&self) -> bool {
7676
match self.kind {
7777
GenericParamDefKind::Lifetime => {
78-
self.name == kw::UnderscoreLifetime || self.name == kw::Empty
78+
self.name == sym::underscore_lifetime || self.name == kw::Empty
7979
}
8080
_ => false,
8181
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl EarlyParamRegion {
451451
/// Does this early bound region have a name? Early bound regions normally
452452
/// always have names except when using anonymous lifetimes (`'_`).
453453
pub fn has_name(&self) -> bool {
454-
self.name != kw::UnderscoreLifetime && self.name != kw::Empty
454+
self.name != sym::underscore_lifetime && self.name != kw::Empty
455455
}
456456
}
457457

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2676,7 +2676,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
26762676

26772677
(name, ty::BoundRegionKind::Named(CRATE_DEF_ID.to_def_id(), name))
26782678
}
2679-
ty::BoundRegionKind::Named(def_id, kw::UnderscoreLifetime | kw::Empty) => {
2679+
ty::BoundRegionKind::Named(def_id, sym::underscore_lifetime | kw::Empty) => {
26802680
let name = next_name(self);
26812681

26822682
if let Some(lt_idx) = lifetime_idx {

compiler/rustc_middle/src/ty/region.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,9 @@ impl core::fmt::Debug for BoundRegion {
411411
impl BoundRegionKind {
412412
pub fn is_named(&self) -> bool {
413413
match *self {
414-
BoundRegionKind::Named(_, name) => name != kw::UnderscoreLifetime && name != kw::Empty,
414+
BoundRegionKind::Named(_, name) => {
415+
name != sym::underscore_lifetime && name != kw::Empty
416+
}
415417
_ => false,
416418
}
417419
}

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ impl<'a> Parser<'a> {
12731273
if let Some((ident, is_raw)) = self.token.lifetime() {
12741274
if matches!(is_raw, IdentIsRaw::No)
12751275
&& ident.without_first_quote().is_reserved()
1276-
&& ![kw::UnderscoreLifetime, kw::StaticLifetime].contains(&ident.name)
1276+
&& ![sym::underscore_lifetime, kw::StaticLifetime].contains(&ident.name)
12771277
{
12781278
self.dcx().emit_err(errors::KeywordLifetime { span: ident.span });
12791279
}

0 commit comments

Comments
 (0)