Skip to content

Commit 8e5df28

Browse files
authored
Rollup merge of rust-lang#139770 - nnethercote:rename-LifetimeName, r=BoxyUwU
Rename `LifetimeName` as `LifetimeKind`. It's a much better name, more consistent with how we name such things. Also rename `Lifetime::res` as `Lifetime::kind` to match. I suspect this field used to have the type `LifetimeRes` and then the type was changed but the field name remained the same. r? ``@BoxyUwU``
2 parents 5c963a4 + fe882bf commit 8e5df28

File tree

13 files changed

+68
-68
lines changed

13 files changed

+68
-68
lines changed

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1767,21 +1767,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17671767
) -> &'hir hir::Lifetime {
17681768
let res = self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
17691769
let res = match res {
1770-
LifetimeRes::Param { param, .. } => hir::LifetimeName::Param(param),
1770+
LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
17711771
LifetimeRes::Fresh { param, .. } => {
17721772
debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
17731773
let param = self.local_def_id(param);
1774-
hir::LifetimeName::Param(param)
1774+
hir::LifetimeKind::Param(param)
17751775
}
17761776
LifetimeRes::Infer => {
17771777
debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
1778-
hir::LifetimeName::Infer
1778+
hir::LifetimeKind::Infer
17791779
}
17801780
LifetimeRes::Static { .. } => {
17811781
debug_assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
1782-
hir::LifetimeName::Static
1782+
hir::LifetimeKind::Static
17831783
}
1784-
LifetimeRes::Error => hir::LifetimeName::Error,
1784+
LifetimeRes::Error => hir::LifetimeKind::Error,
17851785
LifetimeRes::ElidedAnchor { .. } => {
17861786
panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
17871787
}
@@ -2388,7 +2388,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23882388
let r = hir::Lifetime::new(
23892389
self.next_id(),
23902390
Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
2391-
hir::LifetimeName::ImplicitObjectLifetimeDefault,
2391+
hir::LifetimeKind::ImplicitObjectLifetimeDefault,
23922392
IsAnonInPath::No,
23932393
);
23942394
debug!("elided_dyn_bound: r={:?}", r);

Diff for: compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
888888
// Skip `async` desugaring `impl Future`.
889889
}
890890
if let TyKind::TraitObject(_, lt) = alias_ty.kind {
891-
if lt.res == hir::LifetimeName::ImplicitObjectLifetimeDefault {
891+
if lt.kind == hir::LifetimeKind::ImplicitObjectLifetimeDefault {
892892
spans_suggs.push((lt.ident.span.shrink_to_hi(), " + 'a".to_string()));
893893
} else {
894894
spans_suggs.push((lt.ident.span, "'a".to_string()));

Diff for: compiler/rustc_hir/src/hir.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub enum IsAnonInPath {
4242
}
4343

4444
/// A lifetime. The valid field combinations are non-obvious. The following
45-
/// example shows some of them. See also the comments on `LifetimeName`.
45+
/// example shows some of them. See also the comments on `LifetimeKind`.
4646
/// ```
4747
/// #[repr(C)]
4848
/// struct S<'a>(&'a u32); // res=Param, name='a, IsAnonInPath::No
@@ -84,7 +84,7 @@ pub struct Lifetime {
8484
pub ident: Ident,
8585

8686
/// Semantics of this lifetime.
87-
pub res: LifetimeName,
87+
pub kind: LifetimeKind,
8888

8989
/// Is the lifetime anonymous and in a path? Used only for error
9090
/// suggestions. See `Lifetime::suggestion` for example use.
@@ -130,7 +130,7 @@ impl ParamName {
130130
}
131131

132132
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
133-
pub enum LifetimeName {
133+
pub enum LifetimeKind {
134134
/// User-given names or fresh (synthetic) names.
135135
Param(LocalDefId),
136136

@@ -160,16 +160,16 @@ pub enum LifetimeName {
160160
Static,
161161
}
162162

163-
impl LifetimeName {
163+
impl LifetimeKind {
164164
fn is_elided(&self) -> bool {
165165
match self {
166-
LifetimeName::ImplicitObjectLifetimeDefault | LifetimeName::Infer => true,
166+
LifetimeKind::ImplicitObjectLifetimeDefault | LifetimeKind::Infer => true,
167167

168168
// It might seem surprising that `Fresh` counts as not *elided*
169169
// -- but this is because, as far as the code in the compiler is
170170
// concerned -- `Fresh` variants act equivalently to "some fresh name".
171171
// They correspond to early-bound regions on an impl, in other words.
172-
LifetimeName::Error | LifetimeName::Param(..) | LifetimeName::Static => false,
172+
LifetimeKind::Error | LifetimeKind::Param(..) | LifetimeKind::Static => false,
173173
}
174174
}
175175
}
@@ -184,10 +184,10 @@ impl Lifetime {
184184
pub fn new(
185185
hir_id: HirId,
186186
ident: Ident,
187-
res: LifetimeName,
187+
kind: LifetimeKind,
188188
is_anon_in_path: IsAnonInPath,
189189
) -> Lifetime {
190-
let lifetime = Lifetime { hir_id, ident, res, is_anon_in_path };
190+
let lifetime = Lifetime { hir_id, ident, kind, is_anon_in_path };
191191

192192
// Sanity check: elided lifetimes form a strict subset of anonymous lifetimes.
193193
#[cfg(debug_assertions)]
@@ -202,7 +202,7 @@ impl Lifetime {
202202
}
203203

204204
pub fn is_elided(&self) -> bool {
205-
self.res.is_elided()
205+
self.kind.is_elided()
206206
}
207207

208208
pub fn is_anonymous(&self) -> bool {
@@ -1014,7 +1014,7 @@ pub struct WhereRegionPredicate<'hir> {
10141014
impl<'hir> WhereRegionPredicate<'hir> {
10151015
/// Returns `true` if `param_def_id` matches the `lifetime` of this predicate.
10161016
fn is_param_bound(&self, param_def_id: LocalDefId) -> bool {
1017-
self.lifetime.res == LifetimeName::Param(param_def_id)
1017+
self.lifetime.kind == LifetimeKind::Param(param_def_id)
10181018
}
10191019
}
10201020

Diff for: compiler/rustc_hir/src/hir/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn trait_object_roundtrips_impl(syntax: TraitObjectSyntax) {
5757
Lifetime {
5858
hir_id: HirId::INVALID,
5959
ident: Ident::new(sym::name, DUMMY_SP),
60-
res: LifetimeName::Static,
60+
kind: LifetimeKind::Static,
6161
is_anon_in_path: IsAnonInPath::No,
6262
}
6363
},

Diff for: compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_errors::ErrorGuaranteed;
1616
use rustc_hir::def::{DefKind, Res};
1717
use rustc_hir::intravisit::{self, InferKind, Visitor, VisitorExt};
1818
use rustc_hir::{
19-
self as hir, AmbigArg, GenericArg, GenericParam, GenericParamKind, HirId, LifetimeName, Node,
19+
self as hir, AmbigArg, GenericArg, GenericParam, GenericParamKind, HirId, LifetimeKind, Node,
2020
};
2121
use rustc_macros::extension;
2222
use rustc_middle::hir::nested_filter;
@@ -646,14 +646,14 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
646646
arg: &'tcx hir::PreciseCapturingArg<'tcx>,
647647
) -> Self::Result {
648648
match *arg {
649-
hir::PreciseCapturingArg::Lifetime(lt) => match lt.res {
650-
LifetimeName::Param(def_id) => {
649+
hir::PreciseCapturingArg::Lifetime(lt) => match lt.kind {
650+
LifetimeKind::Param(def_id) => {
651651
self.resolve_lifetime_ref(def_id, lt);
652652
}
653-
LifetimeName::Error => {}
654-
LifetimeName::ImplicitObjectLifetimeDefault
655-
| LifetimeName::Infer
656-
| LifetimeName::Static => {
653+
LifetimeKind::Error => {}
654+
LifetimeKind::ImplicitObjectLifetimeDefault
655+
| LifetimeKind::Infer
656+
| LifetimeKind::Static => {
657657
self.tcx.dcx().emit_err(errors::BadPreciseCapture {
658658
span: lt.ident.span,
659659
kind: "lifetime",
@@ -774,26 +774,26 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
774774
);
775775
}
776776
});
777-
match lifetime.res {
778-
LifetimeName::ImplicitObjectLifetimeDefault => {
777+
match lifetime.kind {
778+
LifetimeKind::ImplicitObjectLifetimeDefault => {
779779
// If the user does not write *anything*, we
780780
// use the object lifetime defaulting
781781
// rules. So e.g., `Box<dyn Debug>` becomes
782782
// `Box<dyn Debug + 'static>`.
783783
self.resolve_object_lifetime_default(&*lifetime)
784784
}
785-
LifetimeName::Infer => {
785+
LifetimeKind::Infer => {
786786
// If the user writes `'_`, we use the *ordinary* elision
787787
// rules. So the `'_` in e.g., `Box<dyn Debug + '_>` will be
788788
// resolved the same as the `'_` in `&'_ Foo`.
789789
//
790790
// cc #48468
791791
}
792-
LifetimeName::Param(..) | LifetimeName::Static => {
792+
LifetimeKind::Param(..) | LifetimeKind::Static => {
793793
// If the user wrote an explicit name, use that.
794794
self.visit_lifetime(&*lifetime);
795795
}
796-
LifetimeName::Error => {}
796+
LifetimeKind::Error => {}
797797
}
798798
}
799799
hir::TyKind::Ref(lifetime_ref, ref mt) => {
@@ -873,17 +873,17 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
873873

874874
#[instrument(level = "debug", skip(self))]
875875
fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
876-
match lifetime_ref.res {
877-
hir::LifetimeName::Static => {
876+
match lifetime_ref.kind {
877+
hir::LifetimeKind::Static => {
878878
self.insert_lifetime(lifetime_ref, ResolvedArg::StaticLifetime)
879879
}
880-
hir::LifetimeName::Param(param_def_id) => {
880+
hir::LifetimeKind::Param(param_def_id) => {
881881
self.resolve_lifetime_ref(param_def_id, lifetime_ref)
882882
}
883883
// If we've already reported an error, just ignore `lifetime_ref`.
884-
hir::LifetimeName::Error => {}
884+
hir::LifetimeKind::Error => {}
885885
// Those will be resolved by typechecking.
886-
hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Infer => {}
886+
hir::LifetimeKind::ImplicitObjectLifetimeDefault | hir::LifetimeKind::Infer => {}
887887
}
888888
}
889889

@@ -1063,15 +1063,15 @@ fn object_lifetime_default(tcx: TyCtxt<'_>, param_def_id: LocalDefId) -> ObjectL
10631063

10641064
for bound in bound.bounds {
10651065
if let hir::GenericBound::Outlives(lifetime) = bound {
1066-
set.insert(lifetime.res);
1066+
set.insert(lifetime.kind);
10671067
}
10681068
}
10691069
}
10701070

10711071
match set {
10721072
Set1::Empty => ObjectLifetimeDefault::Empty,
1073-
Set1::One(hir::LifetimeName::Static) => ObjectLifetimeDefault::Static,
1074-
Set1::One(hir::LifetimeName::Param(param_def_id)) => {
1073+
Set1::One(hir::LifetimeKind::Static) => ObjectLifetimeDefault::Static,
1074+
Set1::One(hir::LifetimeKind::Param(param_def_id)) => {
10751075
ObjectLifetimeDefault::Param(param_def_id.to_def_id())
10761076
}
10771077
_ => ObjectLifetimeDefault::Ambiguous,
@@ -1241,7 +1241,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
12411241
// Fresh lifetimes in APIT used to be allowed in async fns and forbidden in
12421242
// regular fns.
12431243
if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin
1244-
&& let hir::LifetimeName::Param(param_id) = lifetime_ref.res
1244+
&& let hir::LifetimeKind::Param(param_id) = lifetime_ref.kind
12451245
&& let Some(generics) =
12461246
self.tcx.hir_get_generics(self.tcx.local_parent(param_id))
12471247
&& let Some(param) = generics.params.iter().find(|p| p.def_id == param_id)
@@ -2440,7 +2440,7 @@ fn is_late_bound_map(
24402440
}
24412441

24422442
fn visit_lifetime(&mut self, lifetime_ref: &'v hir::Lifetime) {
2443-
if let hir::LifetimeName::Param(def_id) = lifetime_ref.res {
2443+
if let hir::LifetimeKind::Param(def_id) = lifetime_ref.kind {
24442444
self.regions.insert(def_id);
24452445
}
24462446
}
@@ -2453,7 +2453,7 @@ fn is_late_bound_map(
24532453

24542454
impl<'tcx> Visitor<'tcx> for AllCollector {
24552455
fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
2456-
if let hir::LifetimeName::Param(def_id) = lifetime_ref.res {
2456+
if let hir::LifetimeKind::Param(def_id) = lifetime_ref.kind {
24572457
self.regions.insert(def_id);
24582458
}
24592459
}

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
415415
self.lower_lifetime(lifetime, RegionInferReason::ExplicitObjectLifetime)
416416
} else {
417417
let reason =
418-
if let hir::LifetimeName::ImplicitObjectLifetimeDefault = lifetime.res {
418+
if let hir::LifetimeKind::ImplicitObjectLifetimeDefault = lifetime.kind {
419419
if let hir::Node::Ty(hir::Ty {
420420
kind: hir::TyKind::Ref(parent_lifetime, _),
421421
..

Diff for: compiler/rustc_middle/src/ty/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ impl<'v> hir::intravisit::Visitor<'v> for TraitObjectVisitor<'v> {
578578
match ty.kind {
579579
hir::TyKind::TraitObject(_, tagged_ptr)
580580
if let hir::Lifetime {
581-
res:
582-
hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Static,
581+
kind:
582+
hir::LifetimeKind::ImplicitObjectLifetimeDefault | hir::LifetimeKind::Static,
583583
..
584584
} = tagged_ptr.pointer() =>
585585
{

Diff for: compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::def_id::DefId;
66
use rustc_hir::intravisit::{Visitor, VisitorExt, walk_ty};
77
use rustc_hir::{
88
self as hir, AmbigArg, GenericBound, GenericParam, GenericParamKind, Item, ItemKind, Lifetime,
9-
LifetimeName, LifetimeParamKind, MissingLifetimeKind, Node, TyKind,
9+
LifetimeKind, LifetimeParamKind, MissingLifetimeKind, Node, TyKind,
1010
};
1111
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor};
1212
use rustc_span::def_id::LocalDefId;
@@ -165,7 +165,7 @@ pub fn suggest_new_region_bound(
165165

166166
if let Some(span) = opaque.bounds.iter().find_map(|arg| match arg {
167167
GenericBound::Outlives(Lifetime {
168-
res: LifetimeName::Static, ident, ..
168+
kind: LifetimeKind::Static, ident, ..
169169
}) => Some(ident.span),
170170
_ => None,
171171
}) {
@@ -253,7 +253,7 @@ pub fn suggest_new_region_bound(
253253
}
254254
}
255255
TyKind::TraitObject(_, lt) => {
256-
if let LifetimeName::ImplicitObjectLifetimeDefault = lt.res {
256+
if let LifetimeKind::ImplicitObjectLifetimeDefault = lt.kind {
257257
err.span_suggestion_verbose(
258258
fn_return.span.shrink_to_hi(),
259259
format!("{declare} the trait object {captures}, {explicit}",),
@@ -414,7 +414,7 @@ pub struct HirTraitObjectVisitor<'a>(pub &'a mut Vec<Span>, pub DefId);
414414
impl<'a, 'tcx> Visitor<'tcx> for HirTraitObjectVisitor<'a> {
415415
fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx, AmbigArg>) {
416416
if let TyKind::TraitObject(poly_trait_refs, lifetime_ptr) = t.kind
417-
&& let Lifetime { res: LifetimeName::ImplicitObjectLifetimeDefault, .. } =
417+
&& let Lifetime { kind: LifetimeKind::ImplicitObjectLifetimeDefault, .. } =
418418
lifetime_ptr.pointer()
419419
{
420420
for ptr in poly_trait_refs {

Diff for: compiler/rustc_trait_selection/src/error_reporting/infer/region.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -850,14 +850,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
850850
add_lt_suggs: &mut Vec<(Span, String)>,
851851
) -> String {
852852
struct LifetimeReplaceVisitor<'a> {
853-
needle: hir::LifetimeName,
853+
needle: hir::LifetimeKind,
854854
new_lt: &'a str,
855855
add_lt_suggs: &'a mut Vec<(Span, String)>,
856856
}
857857

858858
impl<'hir> hir::intravisit::Visitor<'hir> for LifetimeReplaceVisitor<'_> {
859859
fn visit_lifetime(&mut self, lt: &'hir hir::Lifetime) {
860-
if lt.res == self.needle {
860+
if lt.kind == self.needle {
861861
self.add_lt_suggs.push(lt.suggestion(self.new_lt));
862862
}
863863
}
@@ -894,7 +894,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
894894
};
895895

896896
let mut visitor = LifetimeReplaceVisitor {
897-
needle: hir::LifetimeName::Param(lifetime_def_id),
897+
needle: hir::LifetimeKind::Param(lifetime_def_id),
898898
add_lt_suggs,
899899
new_lt: &new_lt,
900900
};

Diff for: src/doc/rustc-dev-guide/src/ty.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ Here is a summary:
6161
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
6262
| Describe the *syntax* of a type: what the user wrote (with some desugaring). | Describe the *semantics* of a type: the meaning of what the user wrote. |
6363
| Each `rustc_hir::Ty` has its own spans corresponding to the appropriate place in the program. | Doesn’t correspond to a single place in the user’s program. |
64-
| `rustc_hir::Ty` has generics and lifetimes; however, some of those lifetimes are special markers like [`LifetimeName::Implicit`][implicit]. | `ty::Ty` has the full type, including generics and lifetimes, even if the user left them out |
64+
| `rustc_hir::Ty` has generics and lifetimes; however, some of those lifetimes are special markers like [`LifetimeKind::Implicit`][implicit]. | `ty::Ty` has the full type, including generics and lifetimes, even if the user left them out |
6565
| `fn foo(x: u32) → u32 { }` - Two `rustc_hir::Ty` representing each usage of `u32`, each has its own `Span`s, and `rustc_hir::Ty` doesn’t tell us that both are the same type | `fn foo(x: u32) → u32 { }` - One `ty::Ty` for all instances of `u32` throughout the program, and `ty::Ty` tells us that both usages of `u32` mean the same type. |
66-
| `fn foo(x: &u32) -> &u32)` - Two `rustc_hir::Ty` again. Lifetimes for the references show up in the `rustc_hir::Ty`s using a special marker, [`LifetimeName::Implicit`][implicit]. | `fn foo(x: &u32) -> &u32)`- A single `ty::Ty`. The `ty::Ty` has the hidden lifetime param. |
66+
| `fn foo(x: &u32) -> &u32)` - Two `rustc_hir::Ty` again. Lifetimes for the references show up in the `rustc_hir::Ty`s using a special marker, [`LifetimeKind::Implicit`][implicit]. | `fn foo(x: &u32) -> &u32)`- A single `ty::Ty`. The `ty::Ty` has the hidden lifetime param. |
6767

68-
[implicit]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.LifetimeName.html#variant.Implicit
68+
[implicit]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.LifetimeKind.html#variant.Implicit
6969

7070
**Order**
7171

@@ -323,4 +323,4 @@ When looking at the debug output of `Ty` or simply talking about different types
323323
- Generic parameters: `{name}/#{index}` e.g. `T/#0`, where `index` corresponds to its position in the list of generic parameters
324324
- Inference variables: `?{id}` e.g. `?x`/`?0`, where `id` identifies the inference variable
325325
- Variables from binders: `^{binder}_{index}` e.g. `^0_x`/`^0_2`, where `binder` and `index` identify which variable from which binder is being referred to
326-
- Placeholders: `!{id}` or `!{id}_{universe}` e.g. `!x`/`!0`/`!x_2`/`!0_2`, representing some unique type in the specified universe. The universe is often elided when it is `0`
326+
- Placeholders: `!{id}` or `!{id}_{universe}` e.g. `!x`/`!0`/`!x_2`/`!0_2`, representing some unique type in the specified universe. The universe is often elided when it is `0`

0 commit comments

Comments
 (0)