Skip to content

Commit aa2450f

Browse files
committed
Merge Implicit and ImplicitMissing.
1 parent 72dc29c commit aa2450f

File tree

6 files changed

+19
-36
lines changed

6 files changed

+19
-36
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17861786
GenericArg::Lifetime(hir::Lifetime {
17871787
hir_id: self.next_id(),
17881788
span: self.lower_span(span),
1789-
name: hir::LifetimeName::Implicit,
1789+
name: hir::LifetimeName::Implicit(false),
17901790
})));
17911791
let generic_args = self.arena.alloc_from_iter(generic_args);
17921792

@@ -1927,8 +1927,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19271927
});
19281928
let param_name = match lt.name {
19291929
hir::LifetimeName::Param(param_name) => param_name,
1930-
hir::LifetimeName::Implicit
1931-
| hir::LifetimeName::ImplicitMissing
1930+
hir::LifetimeName::Implicit(_)
19321931
| hir::LifetimeName::Underscore
19331932
| hir::LifetimeName::Static => hir::ParamName::Plain(lt.name.ident()),
19341933
hir::LifetimeName::ImplicitObjectLifetimeDefault => {
@@ -2291,7 +2290,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22912290

22922291
AnonymousLifetimeMode::ReportError => self.new_error_lifetime(None, span),
22932292

2294-
AnonymousLifetimeMode::PassThrough => self.new_implicit_lifetime(span),
2293+
AnonymousLifetimeMode::PassThrough => self.new_implicit_lifetime(span, false),
22952294
}
22962295
}
22972296

@@ -2344,12 +2343,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23442343
// lifetime. Instead, we simply create an implicit lifetime, which will be checked
23452344
// later, at which point a suitable error will be emitted.
23462345
AnonymousLifetimeMode::PassThrough | AnonymousLifetimeMode::ReportError => {
2347-
if param_mode == ParamMode::Explicit {
2348-
let id = self.resolver.next_node_id();
2349-
self.new_named_lifetime(id, span, hir::LifetimeName::ImplicitMissing)
2350-
} else {
2351-
self.new_implicit_lifetime(span)
2352-
}
2346+
self.new_implicit_lifetime(span, param_mode == ParamMode::Explicit)
23532347
}
23542348
}
23552349
}
@@ -2392,11 +2386,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23922386
r
23932387
}
23942388

2395-
fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime {
2389+
fn new_implicit_lifetime(&mut self, span: Span, missing: bool) -> hir::Lifetime {
23962390
hir::Lifetime {
23972391
hir_id: self.next_id(),
23982392
span: self.lower_span(span),
2399-
name: hir::LifetimeName::Implicit,
2393+
name: hir::LifetimeName::Implicit(missing),
24002394
}
24012395
}
24022396

@@ -2543,9 +2537,7 @@ fn lifetimes_from_impl_trait_bounds(
25432537

25442538
fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) {
25452539
let name = match lifetime.name {
2546-
hir::LifetimeName::Implicit
2547-
| hir::LifetimeName::ImplicitMissing
2548-
| hir::LifetimeName::Underscore => {
2540+
hir::LifetimeName::Implicit(_) | hir::LifetimeName::Underscore => {
25492541
if self.collect_elided_lifetimes {
25502542
// Use `'_` for both implicit and underscore lifetimes in
25512543
// `type Foo<'_> = impl SomeTrait<'_>;`.

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
584584
Some(RegionNameHighlight::MatchedAdtAndSegment(lifetime_span))
585585
}
586586

587-
hir::LifetimeName::ImplicitObjectLifetimeDefault
588-
| hir::LifetimeName::Implicit
589-
| hir::LifetimeName::ImplicitMissing => {
587+
hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Implicit(_) => {
590588
// In this case, the user left off the lifetime; so
591589
// they wrote something like:
592590
//

compiler/rustc_hir/src/hir.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ pub enum LifetimeName {
9292
Param(ParamName),
9393

9494
/// User wrote nothing (e.g., the lifetime in `&u32`).
95-
Implicit,
96-
97-
/// User wrote nothing, but should have provided something.
98-
ImplicitMissing,
95+
///
96+
/// The bool indicates whether the user should have written something.
97+
Implicit(bool),
9998

10099
/// Implicit lifetime in a context like `dyn Foo`. This is
101100
/// distinguished from implicit lifetimes elsewhere because the
@@ -125,8 +124,7 @@ impl LifetimeName {
125124
pub fn ident(&self) -> Ident {
126125
match *self {
127126
LifetimeName::ImplicitObjectLifetimeDefault
128-
| LifetimeName::Implicit
129-
| LifetimeName::ImplicitMissing
127+
| LifetimeName::Implicit(_)
130128
| LifetimeName::Error => Ident::empty(),
131129
LifetimeName::Underscore => Ident::with_dummy_span(kw::UnderscoreLifetime),
132130
LifetimeName::Static => Ident::with_dummy_span(kw::StaticLifetime),
@@ -137,8 +135,7 @@ impl LifetimeName {
137135
pub fn is_elided(&self) -> bool {
138136
match self {
139137
LifetimeName::ImplicitObjectLifetimeDefault
140-
| LifetimeName::Implicit
141-
| LifetimeName::ImplicitMissing
138+
| LifetimeName::Implicit(_)
142139
| LifetimeName::Underscore => true,
143140

144141
// It might seem surprising that `Fresh(_)` counts as
@@ -3303,7 +3300,7 @@ mod size_asserts {
33033300
rustc_data_structures::static_assert_size!(super::Expr<'static>, 64);
33043301
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
33053302
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
3306-
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
3303+
rustc_data_structures::static_assert_size!(super::Ty<'static>, 80);
33073304

33083305
rustc_data_structures::static_assert_size!(super::Item<'static>, 184);
33093306
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128);

compiler/rustc_hir/src/intravisit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,7 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime
545545
| LifetimeName::Param(ParamName::Error)
546546
| LifetimeName::Static
547547
| LifetimeName::Error
548-
| LifetimeName::Implicit
549-
| LifetimeName::ImplicitMissing
548+
| LifetimeName::Implicit(_)
550549
| LifetimeName::ImplicitObjectLifetimeDefault
551550
| LifetimeName::Underscore => {}
552551
}

compiler/rustc_resolve/src/late/diagnostics.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
19521952

19531953
crate fn report_elided_lifetime_in_ty(&self, lifetime_refs: &[&hir::Lifetime]) {
19541954
let Some(missing_lifetime) = lifetime_refs.iter().find(|lt| {
1955-
lt.name == hir::LifetimeName::ImplicitMissing
1955+
lt.name == hir::LifetimeName::Implicit(true)
19561956
}) else { return };
19571957

19581958
let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect();
@@ -2408,8 +2408,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
24082408
);
24092409
let is_allowed_lifetime = matches!(
24102410
lifetime_ref.name,
2411-
hir::LifetimeName::Implicit
2412-
| hir::LifetimeName::ImplicitMissing
2411+
hir::LifetimeName::Implicit(_)
24132412
| hir::LifetimeName::Static
24142413
| hir::LifetimeName::Underscore
24152414
);

compiler/rustc_resolve/src/late/lifetimes.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
923923
}
924924
});
925925
match lifetime.name {
926-
LifetimeName::Implicit | hir::LifetimeName::ImplicitMissing => {
926+
LifetimeName::Implicit(_) => {
927927
// For types like `dyn Foo`, we should
928928
// generate a special form of elided.
929929
span_bug!(ty.span, "object-lifetime-default expected, not implicit",);
@@ -3282,9 +3282,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
32823282
))
32833283
.emit();
32843284
}
3285-
hir::LifetimeName::Param(_)
3286-
| hir::LifetimeName::Implicit
3287-
| hir::LifetimeName::ImplicitMissing => {
3285+
hir::LifetimeName::Param(_) | hir::LifetimeName::Implicit(_) => {
32883286
self.resolve_lifetime_ref(lt);
32893287
}
32903288
hir::LifetimeName::ImplicitObjectLifetimeDefault => {

0 commit comments

Comments
 (0)