Skip to content

Commit ab63591

Browse files
committed
Remove the distinction between LifetimeName::Implicit and LifetimeName::Underscore.
1 parent a2254d5 commit ab63591

File tree

7 files changed

+21
-63
lines changed

7 files changed

+21
-63
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1883,7 +1883,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18831883
}
18841884
hir::LifetimeName::Param(param, ParamName::Fresh)
18851885
}
1886-
LifetimeRes::Anonymous { binder, elided } => {
1886+
LifetimeRes::Anonymous { binder } => {
18871887
let mut l_name = None;
18881888
if let Some(mut captured_lifetimes) = self.captured_lifetimes.take() {
18891889
if !captured_lifetimes.binders_to_ignore.contains(&binder) {
@@ -1900,11 +1900,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19001900
}
19011901
self.captured_lifetimes = Some(captured_lifetimes);
19021902
};
1903-
l_name.unwrap_or(if elided {
1904-
hir::LifetimeName::Implicit
1905-
} else {
1906-
hir::LifetimeName::Underscore
1907-
})
1903+
l_name.unwrap_or(hir::LifetimeName::Underscore)
19081904
}
19091905
LifetimeRes::Static => hir::LifetimeName::Static,
19101906
LifetimeRes::Error => hir::LifetimeName::Error,

compiler/rustc_borrowck/src/diagnostics/region_name.rs

-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,6 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
589589

590590
hir::LifetimeName::Param(_, hir::ParamName::Fresh)
591591
| hir::LifetimeName::ImplicitObjectLifetimeDefault
592-
| hir::LifetimeName::Implicit
593592
| hir::LifetimeName::Underscore => {
594593
// In this case, the user left off the lifetime; so
595594
// they wrote something like:

compiler/rustc_hir/src/def.rs

-2
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,6 @@ pub enum LifetimeRes {
742742
Anonymous {
743743
/// Id of the introducing place. See `Param`.
744744
binder: NodeId,
745-
/// Whether this lifetime was spelled or elided.
746-
elided: bool,
747745
},
748746
/// Explicit `'static` lifetime.
749747
Static,

compiler/rustc_hir/src/hir.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ pub enum LifetimeName {
9090
/// User-given names or fresh (synthetic) names.
9191
Param(LocalDefId, ParamName),
9292

93-
/// User wrote nothing (e.g., the lifetime in `&u32`).
94-
Implicit,
95-
9693
/// Implicit lifetime in a context like `dyn Foo`. This is
9794
/// distinguished from implicit lifetimes elsewhere because the
9895
/// lifetime that they default to must appear elsewhere within the
@@ -110,7 +107,7 @@ pub enum LifetimeName {
110107
/// that was already reported.
111108
Error,
112109

113-
/// User wrote specifies `'_`.
110+
/// User wrote an anonymous lifetime, either `'_` or nothing.
114111
Underscore,
115112

116113
/// User wrote `'static`.
@@ -120,9 +117,7 @@ pub enum LifetimeName {
120117
impl LifetimeName {
121118
pub fn ident(&self) -> Ident {
122119
match *self {
123-
LifetimeName::ImplicitObjectLifetimeDefault
124-
| LifetimeName::Implicit
125-
| LifetimeName::Error => Ident::empty(),
120+
LifetimeName::ImplicitObjectLifetimeDefault | LifetimeName::Error => Ident::empty(),
126121
LifetimeName::Underscore => Ident::with_dummy_span(kw::UnderscoreLifetime),
127122
LifetimeName::Static => Ident::with_dummy_span(kw::StaticLifetime),
128123
LifetimeName::Param(_, param_name) => param_name.ident(),
@@ -132,7 +127,6 @@ impl LifetimeName {
132127
pub fn is_anonymous(&self) -> bool {
133128
match *self {
134129
LifetimeName::ImplicitObjectLifetimeDefault
135-
| LifetimeName::Implicit
136130
| LifetimeName::Underscore
137131
| LifetimeName::Param(_, ParamName::Fresh)
138132
| LifetimeName::Error => true,
@@ -142,9 +136,7 @@ impl LifetimeName {
142136

143137
pub fn is_elided(&self) -> bool {
144138
match self {
145-
LifetimeName::ImplicitObjectLifetimeDefault
146-
| LifetimeName::Implicit
147-
| LifetimeName::Underscore => true,
139+
LifetimeName::ImplicitObjectLifetimeDefault | LifetimeName::Underscore => true,
148140

149141
// It might seem surprising that `Fresh` counts as
150142
// *not* elided -- but this is because, as far as the code

compiler/rustc_hir/src/intravisit.rs

-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime
496496
| LifetimeName::Param(_, ParamName::Error)
497497
| LifetimeName::Static
498498
| LifetimeName::Error
499-
| LifetimeName::Implicit
500499
| LifetimeName::ImplicitObjectLifetimeDefault
501500
| LifetimeName::Underscore => {}
502501
}

compiler/rustc_resolve/src/late.rs

+12-38
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,6 @@ enum LifetimeRibKind {
262262
/// error on default object bounds (e.g., `Box<dyn Foo>`).
263263
AnonymousReportError,
264264

265-
/// Pass responsibility to `resolve_lifetime` code for all cases.
266-
AnonymousPassThrough(NodeId),
267-
268265
/// Replace all anonymous lifetimes by provided lifetime.
269266
Elided(LifetimeRes),
270267

@@ -868,7 +865,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
868865
let previous_state = replace(&mut this.in_func_body, true);
869866
// Resolve the function body, potentially inside the body of an async closure
870867
this.with_lifetime_rib(
871-
LifetimeRibKind::AnonymousPassThrough(fn_id),
868+
LifetimeRibKind::Elided(LifetimeRes::Anonymous { binder: fn_id }),
872869
|this| this.visit_block(body),
873870
);
874871

@@ -896,7 +893,9 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
896893
this.with_lifetime_rib(
897894
match binder {
898895
ClosureBinder::NotPresent => {
899-
LifetimeRibKind::AnonymousPassThrough(fn_id)
896+
LifetimeRibKind::Elided(LifetimeRes::Anonymous {
897+
binder: fn_id,
898+
})
900899
}
901900
ClosureBinder::For { .. } => LifetimeRibKind::AnonymousReportError,
902901
},
@@ -908,7 +907,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
908907
let previous_state = replace(&mut this.in_func_body, true);
909908
// Resolve the function body, potentially inside the body of an async closure
910909
this.with_lifetime_rib(
911-
LifetimeRibKind::AnonymousPassThrough(fn_id),
910+
LifetimeRibKind::Elided(LifetimeRes::Anonymous { binder: fn_id }),
912911
|this| this.visit_expr(body),
913912
);
914913

@@ -1053,8 +1052,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
10531052
visit::walk_generic_args(self, path_span, args);
10541053
break;
10551054
}
1056-
LifetimeRibKind::AnonymousPassThrough(..)
1057-
| LifetimeRibKind::AnonymousCreateParameter { .. }
1055+
LifetimeRibKind::AnonymousCreateParameter { .. }
10581056
| LifetimeRibKind::AnonymousReportError
10591057
| LifetimeRibKind::Elided(_)
10601058
| LifetimeRibKind::ElisionFailure
@@ -1415,8 +1413,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
14151413
| LifetimeRibKind::AnonymousReportError
14161414
| LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
14171415
// An anonymous lifetime is legal here, go ahead.
1418-
LifetimeRibKind::AnonymousPassThrough(_)
1419-
| LifetimeRibKind::AnonymousCreateParameter { .. } => {
1416+
LifetimeRibKind::AnonymousCreateParameter { .. } => {
14201417
Some(LifetimeUseSet::One { use_span: ident.span, use_ctxt })
14211418
}
14221419
// Only report if eliding the lifetime would have the same
@@ -1527,14 +1524,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
15271524
self.record_lifetime_res(lifetime.id, LifetimeRes::Error, elision_candidate);
15281525
return;
15291526
}
1530-
LifetimeRibKind::AnonymousPassThrough(node_id) => {
1531-
self.record_lifetime_res(
1532-
lifetime.id,
1533-
LifetimeRes::Anonymous { binder: node_id, elided },
1534-
elision_candidate,
1535-
);
1536-
return;
1537-
}
15381527
LifetimeRibKind::Elided(res) => {
15391528
self.record_lifetime_res(lifetime.id, res, elision_candidate);
15401529
return;
@@ -1658,8 +1647,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
16581647
// Do not create a parameter for patterns and expressions.
16591648
for rib in self.lifetime_ribs.iter().rev() {
16601649
match rib.kind {
1661-
LifetimeRibKind::AnonymousPassThrough(binder) => {
1662-
let res = LifetimeRes::Anonymous { binder, elided: true };
1650+
LifetimeRibKind::Elided(res @ LifetimeRes::Anonymous { .. }) => {
16631651
for id in node_ids {
16641652
self.record_lifetime_res(id, res, LifetimeElisionCandidate::Named);
16651653
}
@@ -1673,8 +1661,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
16731661
// FIXME(cjgillot) This resolution is wrong, but this does not matter
16741662
// since these cases are erroneous anyway. Lifetime resolution should
16751663
// emit a "missing lifetime specifier" diagnostic.
1676-
let res =
1677-
LifetimeRes::Anonymous { binder: DUMMY_NODE_ID, elided: true };
1664+
let res = LifetimeRes::Anonymous { binder: DUMMY_NODE_ID };
16781665
for id in node_ids {
16791666
self.record_lifetime_res(id, res, LifetimeElisionCandidate::Named);
16801667
}
@@ -1753,19 +1740,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
17531740
}
17541741
break;
17551742
}
1756-
// `PassThrough` is the normal case.
1757-
LifetimeRibKind::AnonymousPassThrough(binder) => {
1758-
let res = LifetimeRes::Anonymous { binder, elided: true };
1759-
let mut candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
1760-
for id in node_ids {
1761-
self.record_lifetime_res(
1762-
id,
1763-
res,
1764-
replace(&mut candidate, LifetimeElisionCandidate::Ignore),
1765-
);
1766-
}
1767-
break;
1768-
}
17691743
LifetimeRibKind::Elided(res) => {
17701744
let mut candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
17711745
for id in node_ids {
@@ -2272,7 +2246,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
22722246
this.visit_ty(ty);
22732247
});
22742248
this.with_lifetime_rib(
2275-
LifetimeRibKind::AnonymousPassThrough(item.id),
2249+
LifetimeRibKind::Elided(LifetimeRes::Anonymous { binder: item.id }),
22762250
|this| {
22772251
if let Some(expr) = expr {
22782252
let constant_item_kind = match item.kind {
@@ -2547,7 +2521,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
25472521
// Type parameters can already be used and as associated consts are
25482522
// not used as part of the type system, this is far less surprising.
25492523
self.with_lifetime_rib(
2550-
LifetimeRibKind::AnonymousPassThrough(item.id),
2524+
LifetimeRibKind::Elided(LifetimeRes::Anonymous { binder: item.id }),
25512525
|this| {
25522526
this.with_constant_rib(
25532527
IsRepeatExpr::No,
@@ -2721,7 +2695,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
27212695
// Type parameters can already be used and as associated consts are
27222696
// not used as part of the type system, this is far less surprising.
27232697
self.with_lifetime_rib(
2724-
LifetimeRibKind::AnonymousPassThrough(item.id),
2698+
LifetimeRibKind::Elided(LifetimeRes::Anonymous { binder: item.id }),
27252699
|this| {
27262700
this.with_constant_rib(
27272701
IsRepeatExpr::No,

compiler/rustc_resolve/src/late/lifetimes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
819819
// `Box<dyn Debug + 'static>`.
820820
self.resolve_object_lifetime_default(lifetime)
821821
}
822-
LifetimeName::Implicit | LifetimeName::Underscore => {
822+
LifetimeName::Underscore => {
823823
// If the user writes `'_`, we use the *ordinary* elision
824824
// rules. So the `'_` in e.g., `Box<dyn Debug + '_>` will be
825825
// resolved the same as the `'_` in `&'_ Foo`.
@@ -1135,9 +1135,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
11351135
#[tracing::instrument(level = "debug", skip(self))]
11361136
fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
11371137
match lifetime_ref.name {
1138-
hir::LifetimeName::ImplicitObjectLifetimeDefault
1139-
| hir::LifetimeName::Implicit
1140-
| hir::LifetimeName::Underscore => self.resolve_elided_lifetimes(&[lifetime_ref]),
1138+
hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Underscore => {
1139+
self.resolve_elided_lifetimes(&[lifetime_ref])
1140+
}
11411141
hir::LifetimeName::Static => self.insert_lifetime(lifetime_ref, Region::Static),
11421142
hir::LifetimeName::Param(param_def_id, _) => {
11431143
self.resolve_lifetime_ref(param_def_id, lifetime_ref)

0 commit comments

Comments
 (0)