Skip to content

Commit 69b3e6f

Browse files
committed
Rename LifetimeSyntax variants to lang-team-approved names
1 parent da1e442 commit 69b3e6f

File tree

4 files changed

+39
-43
lines changed

4 files changed

+39
-43
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14051405
};
14061406
let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
14071407
let region = Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id };
1408-
(region, LifetimeSyntax::Hidden)
1408+
(region, LifetimeSyntax::Implicit)
14091409
}
14101410
};
14111411
self.lower_lifetime(&region, LifetimeSource::Reference, syntax)
@@ -1789,7 +1789,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17891789
id,
17901790
Ident::new(kw::UnderscoreLifetime, span),
17911791
LifetimeSource::Path { angle_brackets },
1792-
LifetimeSyntax::Hidden,
1792+
LifetimeSyntax::Implicit,
17931793
)
17941794
}
17951795

@@ -2421,7 +2421,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24212421
Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
24222422
hir::LifetimeKind::ImplicitObjectLifetimeDefault,
24232423
LifetimeSource::Other,
2424-
LifetimeSyntax::Hidden,
2424+
LifetimeSyntax::Implicit,
24252425
);
24262426
debug!("elided_dyn_bound: r={:?}", r);
24272427
self.arena.alloc(r)

compiler/rustc_hir/src/hir.rs

+34-38
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ pub enum LifetimeSource {
7272
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
7373
pub enum LifetimeSyntax {
7474
/// E.g. `&Type`, `ContainsLifetime`
75-
Hidden,
75+
Implicit,
7676

7777
/// E.g. `&'_ Type`, `ContainsLifetime<'_>`, `impl Trait + '_`, `impl Trait + use<'_>`
78-
Anonymous,
78+
ExplicitAnonymous,
7979

8080
/// E.g. `&'a Type`, `ContainsLifetime<'a>`, `impl Trait + 'a`, `impl Trait + use<'a>`
81-
Named,
81+
ExplicitBound,
8282
}
8383

8484
impl From<Ident> for LifetimeSyntax {
@@ -88,10 +88,10 @@ impl From<Ident> for LifetimeSyntax {
8888
if name == kw::Empty {
8989
unreachable!("A lifetime name should never be empty");
9090
} else if name == kw::UnderscoreLifetime {
91-
LifetimeSyntax::Anonymous
91+
LifetimeSyntax::ExplicitAnonymous
9292
} else {
9393
debug_assert!(name.as_str().starts_with('\''));
94-
LifetimeSyntax::Named
94+
LifetimeSyntax::ExplicitBound
9595
}
9696
}
9797
}
@@ -102,48 +102,48 @@ impl From<Ident> for LifetimeSyntax {
102102
///
103103
/// ```
104104
/// #[repr(C)]
105-
/// struct S<'a>(&'a u32); // res=Param, name='a, source=Reference, syntax=Named
105+
/// struct S<'a>(&'a u32); // res=Param, name='a, source=Reference, syntax=ExplicitBound
106106
/// unsafe extern "C" {
107-
/// fn f1(s: S); // res=Param, name='_, source=Path, syntax=Hidden
108-
/// fn f2(s: S<'_>); // res=Param, name='_, source=Path, syntax=Anonymous
109-
/// fn f3<'a>(s: S<'a>); // res=Param, name='a, source=Path, syntax=Named
107+
/// fn f1(s: S); // res=Param, name='_, source=Path, syntax=Implicit
108+
/// fn f2(s: S<'_>); // res=Param, name='_, source=Path, syntax=ExplicitAnonymous
109+
/// fn f3<'a>(s: S<'a>); // res=Param, name='a, source=Path, syntax=ExplicitBound
110110
/// }
111111
///
112-
/// struct St<'a> { x: &'a u32 } // res=Param, name='a, source=Reference, syntax=Named
112+
/// struct St<'a> { x: &'a u32 } // res=Param, name='a, source=Reference, syntax=ExplicitBound
113113
/// fn f() {
114-
/// _ = St { x: &0 }; // res=Infer, name='_, source=Path, syntax=Hidden
115-
/// _ = St::<'_> { x: &0 }; // res=Infer, name='_, source=Path, syntax=Anonymous
114+
/// _ = St { x: &0 }; // res=Infer, name='_, source=Path, syntax=Implicit
115+
/// _ = St::<'_> { x: &0 }; // res=Infer, name='_, source=Path, syntax=ExplicitAnonymous
116116
/// }
117117
///
118-
/// struct Name<'a>(&'a str); // res=Param, name='a, source=Reference, syntax=Named
119-
/// const A: Name = Name("a"); // res=Static, name='_, source=Path, syntax=Hidden
120-
/// const B: &str = ""; // res=Static, name='_, source=Reference, syntax=Hidden
121-
/// static C: &'_ str = ""; // res=Static, name='_, source=Reference, syntax=Anonymous
122-
/// static D: &'static str = ""; // res=Static, name='static, source=Reference, syntax=Named
118+
/// struct Name<'a>(&'a str); // res=Param, name='a, source=Reference, syntax=ExplicitBound
119+
/// const A: Name = Name("a"); // res=Static, name='_, source=Path, syntax=Implicit
120+
/// const B: &str = ""; // res=Static, name='_, source=Reference, syntax=Implicit
121+
/// static C: &'_ str = ""; // res=Static, name='_, source=Reference, syntax=ExplicitAnonymous
122+
/// static D: &'static str = ""; // res=Static, name='static, source=Reference, syntax=ExplicitBound
123123
///
124124
/// trait Tr {}
125-
/// fn tr(_: Box<dyn Tr>) {} // res=ImplicitObjectLifetimeDefault, name='_, source=Other, syntax=Hidden
125+
/// fn tr(_: Box<dyn Tr>) {} // res=ImplicitObjectLifetimeDefault, name='_, source=Other, syntax=Implicit
126126
///
127127
/// fn capture_outlives<'a>() ->
128-
/// impl FnOnce() + 'a // res=Param, ident='a, source=OutlivesBound, syntax=Named
128+
/// impl FnOnce() + 'a // res=Param, ident='a, source=OutlivesBound, syntax=ExplicitBound
129129
/// {
130130
/// || {}
131131
/// }
132132
///
133133
/// fn capture_precise<'a>() ->
134-
/// impl FnOnce() + use<'a> // res=Param, ident='a, source=PreciseCapturing, syntax=Named
134+
/// impl FnOnce() + use<'a> // res=Param, ident='a, source=PreciseCapturing, syntax=ExplicitBound
135135
/// {
136136
/// || {}
137137
/// }
138138
///
139139
/// // (commented out because these cases trigger errors)
140-
/// // struct S1<'a>(&'a str); // res=Param, name='a, source=Reference, syntax=Named
141-
/// // struct S2(S1); // res=Error, name='_, source=Path, syntax=Hidden
142-
/// // struct S3(S1<'_>); // res=Error, name='_, source=Path, syntax=Anonymous
143-
/// // struct S4(S1<'a>); // res=Error, name='a, source=Path, syntax=Named
140+
/// // struct S1<'a>(&'a str); // res=Param, name='a, source=Reference, syntax=ExplicitBound
141+
/// // struct S2(S1); // res=Error, name='_, source=Path, syntax=Implicit
142+
/// // struct S3(S1<'_>); // res=Error, name='_, source=Path, syntax=ExplicitAnonymous
143+
/// // struct S4(S1<'a>); // res=Error, name='a, source=Path, syntax=ExplicitBound
144144
/// ```
145145
///
146-
/// Some combinations that cannot occur are `LifetimeSyntax::Hidden` with
146+
/// Some combinations that cannot occur are `LifetimeSyntax::Implicit` with
147147
/// `LifetimeSource::OutlivesBound` or `LifetimeSource::PreciseCapturing`
148148
/// — there's no way to "elide" these lifetimes.
149149
#[derive(Debug, Copy, Clone, HashStable_Generic)]
@@ -287,12 +287,8 @@ impl Lifetime {
287287
self.ident.name == kw::UnderscoreLifetime
288288
}
289289

290-
pub fn is_syntactically_hidden(&self) -> bool {
291-
matches!(self.syntax, LifetimeSyntax::Hidden)
292-
}
293-
294-
pub fn is_syntactically_anonymous(&self) -> bool {
295-
matches!(self.syntax, LifetimeSyntax::Anonymous)
290+
pub fn is_implicit(&self) -> bool {
291+
matches!(self.syntax, LifetimeSyntax::Implicit)
296292
}
297293

298294
pub fn is_static(&self) -> bool {
@@ -307,28 +303,28 @@ impl Lifetime {
307303

308304
match (self.syntax, self.source) {
309305
// The user wrote `'a` or `'_`.
310-
(Named | Anonymous, _) => (self.ident.span, format!("{new_lifetime}")),
306+
(ExplicitBound | ExplicitAnonymous, _) => (self.ident.span, format!("{new_lifetime}")),
311307

312308
// The user wrote `Path<T>`, and omitted the `'_,`.
313-
(Hidden, Path { angle_brackets: AngleBrackets::Full }) => {
309+
(Implicit, Path { angle_brackets: AngleBrackets::Full }) => {
314310
(self.ident.span, format!("{new_lifetime}, "))
315311
}
316312

317313
// The user wrote `Path<>`, and omitted the `'_`..
318-
(Hidden, Path { angle_brackets: AngleBrackets::Empty }) => {
314+
(Implicit, Path { angle_brackets: AngleBrackets::Empty }) => {
319315
(self.ident.span, format!("{new_lifetime}"))
320316
}
321317

322318
// The user wrote `Path` and omitted the `<'_>`.
323-
(Hidden, Path { angle_brackets: AngleBrackets::Missing }) => {
319+
(Implicit, Path { angle_brackets: AngleBrackets::Missing }) => {
324320
(self.ident.span.shrink_to_hi(), format!("<{new_lifetime}>"))
325321
}
326322

327323
// The user wrote `&type` or `&mut type`.
328-
(Hidden, Reference) => (self.ident.span, format!("{new_lifetime} ")),
324+
(Implicit, Reference) => (self.ident.span, format!("{new_lifetime} ")),
329325

330-
(Hidden, source) => {
331-
unreachable!("can't suggest for a hidden lifetime of {source:?}")
326+
(Implicit, source) => {
327+
unreachable!("can't suggest for a implicit lifetime of {source:?}")
332328
}
333329
}
334330
}

compiler/rustc_hir/src/hir/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn trait_object_roundtrips_impl(syntax: TraitObjectSyntax) {
5555
ident: Ident::new(sym::name, DUMMY_SP),
5656
kind: LifetimeKind::Static,
5757
source: LifetimeSource::Other,
58-
syntax: LifetimeSyntax::Hidden,
58+
syntax: LifetimeSyntax::Implicit,
5959
};
6060
let unambig = TyKind::TraitObject::<'_, ()>(&[], TaggedRef::new(&lt, syntax));
6161
let unambig_to_ambig = unsafe { std::mem::transmute::<_, TyKind<'_, AmbigArg>>(unambig) };

compiler/rustc_trait_selection/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
587587
matches!(
588588
arg,
589589
hir::GenericArg::Lifetime(lifetime)
590-
if lifetime.is_syntactically_hidden()
590+
if lifetime.is_implicit()
591591
)
592592
}) {
593593
self.suggestions.push((

0 commit comments

Comments
 (0)