Skip to content

Commit 9386ea9

Browse files
Remove LifetimeDefOrigin
1 parent bb548a9 commit 9386ea9

File tree

6 files changed

+41
-79
lines changed

6 files changed

+41
-79
lines changed

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
125125
// Find the index of the named region that was part of the
126126
// error. We will then search the function parameters for a bound
127127
// region at the right depth with the same index
128-
(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => {
128+
(Some(rl::Region::EarlyBound(_, id)), ty::BrNamed(def_id, _)) => {
129129
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
130130
if id == def_id {
131131
self.found_type = Some(arg);
@@ -137,7 +137,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
137137
// error. We will then search the function parameters for a bound
138138
// region at the right depth with the same index
139139
(
140-
Some(rl::Region::LateBound(debruijn_index, _, id, _)),
140+
Some(rl::Region::LateBound(debruijn_index, _, id)),
141141
ty::BrNamed(def_id, _),
142142
) => {
143143
debug!(
@@ -155,8 +155,8 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
155155
Some(
156156
rl::Region::Static
157157
| rl::Region::Free(_, _)
158-
| rl::Region::EarlyBound(_, _, _)
159-
| rl::Region::LateBound(_, _, _, _)
158+
| rl::Region::EarlyBound(_, _)
159+
| rl::Region::LateBound(_, _, _)
160160
| rl::Region::LateBoundAnon(_, _, _),
161161
)
162162
| None,
@@ -221,15 +221,15 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
221221
}
222222
}
223223

224-
(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => {
224+
(Some(rl::Region::EarlyBound(_, id)), ty::BrNamed(def_id, _)) => {
225225
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
226226
if id == def_id {
227227
self.found_it = true;
228228
return; // we can stop visiting now
229229
}
230230
}
231231

232-
(Some(rl::Region::LateBound(debruijn_index, _, id, _)), ty::BrNamed(def_id, _)) => {
232+
(Some(rl::Region::LateBound(debruijn_index, _, id)), ty::BrNamed(def_id, _)) => {
233233
debug!("FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}", debruijn_index,);
234234
debug!("id={:?}", id);
235235
debug!("def_id={:?}", def_id);
@@ -242,8 +242,8 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
242242
(
243243
Some(
244244
rl::Region::Static
245-
| rl::Region::EarlyBound(_, _, _)
246-
| rl::Region::LateBound(_, _, _, _)
245+
| rl::Region::EarlyBound(_, _)
246+
| rl::Region::LateBound(_, _, _)
247247
| rl::Region::LateBoundAnon(_, _, _)
248248
| rl::Region::Free(_, _),
249249
)

compiler/rustc_middle/src/middle/resolve_lifetime.rs

+3-33
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,14 @@ use crate::ty;
44

55
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
66
use rustc_hir::def_id::{DefId, LocalDefId};
7-
use rustc_hir::{GenericParam, ItemLocalId};
8-
use rustc_hir::{GenericParamKind, LifetimeParamKind};
7+
use rustc_hir::ItemLocalId;
98
use rustc_macros::HashStable;
109

11-
/// The origin of a named lifetime definition.
12-
///
13-
/// This is used to prevent the usage of in-band lifetimes in `Fn`/`fn` syntax.
14-
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
15-
pub enum LifetimeDefOrigin {
16-
// Explicit binders like `fn foo<'a>(x: &'a u8)` or elided like `impl Foo<&u32>`
17-
ExplicitOrElided,
18-
// Some kind of erroneous origin
19-
Error,
20-
}
21-
22-
impl LifetimeDefOrigin {
23-
pub fn from_param(param: &GenericParam<'_>) -> Self {
24-
match param.kind {
25-
GenericParamKind::Lifetime { kind } => match kind {
26-
LifetimeParamKind::Explicit => LifetimeDefOrigin::ExplicitOrElided,
27-
LifetimeParamKind::Elided => LifetimeDefOrigin::ExplicitOrElided,
28-
LifetimeParamKind::Error => LifetimeDefOrigin::Error,
29-
},
30-
_ => bug!("expected a lifetime param"),
31-
}
32-
}
33-
}
34-
3510
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
3611
pub enum Region {
3712
Static,
38-
EarlyBound(/* index */ u32, /* lifetime decl */ DefId, LifetimeDefOrigin),
39-
LateBound(
40-
ty::DebruijnIndex,
41-
/* late-bound index */ u32,
42-
/* lifetime decl */ DefId,
43-
LifetimeDefOrigin,
44-
),
13+
EarlyBound(/* index */ u32, /* lifetime decl */ DefId),
14+
LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* lifetime decl */ DefId),
4515
LateBoundAnon(ty::DebruijnIndex, /* late-bound index */ u32, /* anon index */ u32),
4616
Free(DefId, /* lifetime decl */ DefId),
4717
}

compiler/rustc_resolve/src/late/lifetimes.rs

+25-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore-tidy-filelength
21
//! Name resolution for lifetimes.
32
//!
43
//! Name resolution for lifetimes follows *much* simpler rules than the
@@ -63,23 +62,18 @@ impl RegionExt for Region {
6362
let i = *index;
6463
*index += 1;
6564
let def_id = hir_map.local_def_id(param.hir_id);
66-
let origin = LifetimeDefOrigin::from_param(param);
6765
debug!("Region::early: index={} def_id={:?}", i, def_id);
68-
(param.name.normalize_to_macros_2_0(), Region::EarlyBound(i, def_id.to_def_id(), origin))
66+
(param.name.normalize_to_macros_2_0(), Region::EarlyBound(i, def_id.to_def_id()))
6967
}
7068

7169
fn late(idx: u32, hir_map: Map<'_>, param: &GenericParam<'_>) -> (ParamName, Region) {
7270
let depth = ty::INNERMOST;
7371
let def_id = hir_map.local_def_id(param.hir_id);
74-
let origin = LifetimeDefOrigin::from_param(param);
7572
debug!(
76-
"Region::late: idx={:?}, param={:?} depth={:?} def_id={:?} origin={:?}",
77-
idx, param, depth, def_id, origin,
73+
"Region::late: idx={:?}, param={:?} depth={:?} def_id={:?}",
74+
idx, param, depth, def_id,
7875
);
79-
(
80-
param.name.normalize_to_macros_2_0(),
81-
Region::LateBound(depth, idx, def_id.to_def_id(), origin),
82-
)
76+
(param.name.normalize_to_macros_2_0(), Region::LateBound(depth, idx, def_id.to_def_id()))
8377
}
8478

8579
fn late_anon(named_late_bound_vars: u32, index: &Cell<u32>) -> Region {
@@ -93,16 +87,16 @@ impl RegionExt for Region {
9387
match *self {
9488
Region::Static | Region::LateBoundAnon(..) => None,
9589

96-
Region::EarlyBound(_, id, _) | Region::LateBound(_, _, id, _) | Region::Free(_, id) => {
90+
Region::EarlyBound(_, id) | Region::LateBound(_, _, id) | Region::Free(_, id) => {
9791
Some(id)
9892
}
9993
}
10094
}
10195

10296
fn shifted(self, amount: u32) -> Region {
10397
match self {
104-
Region::LateBound(debruijn, idx, id, origin) => {
105-
Region::LateBound(debruijn.shifted_in(amount), idx, id, origin)
98+
Region::LateBound(debruijn, idx, id) => {
99+
Region::LateBound(debruijn.shifted_in(amount), idx, id)
106100
}
107101
Region::LateBoundAnon(debruijn, index, anon_index) => {
108102
Region::LateBoundAnon(debruijn.shifted_in(amount), index, anon_index)
@@ -113,8 +107,8 @@ impl RegionExt for Region {
113107

114108
fn shifted_out_to_binder(self, binder: ty::DebruijnIndex) -> Region {
115109
match self {
116-
Region::LateBound(debruijn, index, id, origin) => {
117-
Region::LateBound(debruijn.shifted_out_to_binder(binder), index, id, origin)
110+
Region::LateBound(debruijn, index, id) => {
111+
Region::LateBound(debruijn.shifted_out_to_binder(binder), index, id)
118112
}
119113
Region::LateBoundAnon(debruijn, index, anon_index) => {
120114
Region::LateBoundAnon(debruijn.shifted_out_to_binder(binder), index, anon_index)
@@ -127,7 +121,7 @@ impl RegionExt for Region {
127121
where
128122
L: Iterator<Item = &'a hir::Lifetime>,
129123
{
130-
if let Region::EarlyBound(index, _, _) = self {
124+
if let Region::EarlyBound(index, _) = self {
131125
params.nth(index as usize).and_then(|lifetime| map.defs.get(&lifetime.hir_id).cloned())
132126
} else {
133127
Some(self)
@@ -568,7 +562,7 @@ fn sub_items_have_self_param(node: &hir::ItemKind<'_>) -> bool {
568562

569563
fn late_region_as_bound_region<'tcx>(tcx: TyCtxt<'tcx>, region: &Region) -> ty::BoundVariableKind {
570564
match region {
571-
Region::LateBound(_, _, def_id, _) => {
565+
Region::LateBound(_, _, def_id) => {
572566
let name = tcx.hir().name(tcx.hir().local_def_id_to_hir_id(def_id.expect_local()));
573567
ty::BoundVariableKind::Region(ty::BrNamed(*def_id, name))
574568
}
@@ -1010,7 +1004,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
10101004
// well-supported at the moment, so this doesn't work.
10111005
// In the future, this should be fixed and this error should be removed.
10121006
let def = self.map.defs.get(&lifetime.hir_id).cloned();
1013-
let Some(Region::LateBound(_, _, def_id, _)) = def else {
1007+
let Some(Region::LateBound(_, _, def_id)) = def else {
10141008
continue
10151009
};
10161010
let Some(def_id) = def_id.as_local() else {
@@ -1046,7 +1040,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
10461040
match param.kind {
10471041
GenericParamKind::Lifetime { .. } => {
10481042
let (name, reg) = Region::early(self.tcx.hir(), &mut index, &param);
1049-
let Region::EarlyBound(_, def_id, _) = reg else {
1043+
let Region::EarlyBound(_, def_id) = reg else {
10501044
bug!();
10511045
};
10521046
// We cannot predict what lifetimes are unused in opaque type.
@@ -1668,7 +1662,7 @@ fn compute_object_lifetime_defaults<'tcx>(
16681662
.map(|set| match *set {
16691663
Set1::Empty => "BaseDefault".into(),
16701664
Set1::One(Region::Static) => "'static".into(),
1671-
Set1::One(Region::EarlyBound(mut i, _, _)) => generics
1665+
Set1::One(Region::EarlyBound(mut i, _)) => generics
16721666
.params
16731667
.iter()
16741668
.find_map(|param| match param.kind {
@@ -1749,18 +1743,16 @@ fn object_lifetime_defaults_for_item<'tcx>(
17491743
.params
17501744
.iter()
17511745
.filter_map(|param| match param.kind {
1752-
GenericParamKind::Lifetime { .. } => Some((
1753-
param.hir_id,
1754-
hir::LifetimeName::Param(param.name),
1755-
LifetimeDefOrigin::from_param(param),
1756-
)),
1746+
GenericParamKind::Lifetime { .. } => {
1747+
Some((param.hir_id, hir::LifetimeName::Param(param.name)))
1748+
}
17571749
_ => None,
17581750
})
17591751
.enumerate()
1760-
.find(|&(_, (_, lt_name, _))| lt_name == name)
1761-
.map_or(Set1::Many, |(i, (id, _, origin))| {
1752+
.find(|&(_, (_, lt_name))| lt_name == name)
1753+
.map_or(Set1::Many, |(i, (id, _))| {
17621754
let def_id = tcx.hir().local_def_id(id);
1763-
Set1::One(Region::EarlyBound(i as u32, def_id.to_def_id(), origin))
1755+
Set1::One(Region::EarlyBound(i as u32, def_id.to_def_id()))
17641756
})
17651757
}
17661758
}
@@ -1948,8 +1940,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
19481940
let def_ids: Vec<_> = defined_by
19491941
.values()
19501942
.flat_map(|region| match region {
1951-
Region::EarlyBound(_, def_id, _)
1952-
| Region::LateBound(_, _, def_id, _)
1943+
Region::EarlyBound(_, def_id)
1944+
| Region::LateBound(_, _, def_id)
19531945
| Region::Free(_, def_id) => Some(*def_id),
19541946

19551947
Region::LateBoundAnon(..) | Region::Static => None,
@@ -2883,7 +2875,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
28832875
fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) {
28842876
if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.hir_id) {
28852877
match lifetime {
2886-
Region::LateBound(debruijn, _, _, _)
2878+
Region::LateBound(debruijn, _, _)
28872879
| Region::LateBoundAnon(debruijn, _, _)
28882880
if debruijn < self.outer_index =>
28892881
{
@@ -3289,8 +3281,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
32893281
}
32903282

32913283
Region::Free(_, def_id)
3292-
| Region::LateBound(_, _, def_id, _)
3293-
| Region::EarlyBound(_, def_id, _) => {
3284+
| Region::LateBound(_, _, def_id)
3285+
| Region::EarlyBound(_, def_id) => {
32943286
// A lifetime declared by the user.
32953287
let track_lifetime_uses = self.track_lifetime_uses();
32963288
debug!(?track_lifetime_uses);

compiler/rustc_typeck/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
205205
let r = match tcx.named_region(lifetime.hir_id) {
206206
Some(rl::Region::Static) => tcx.lifetimes.re_static,
207207

208-
Some(rl::Region::LateBound(debruijn, index, def_id, _)) => {
208+
Some(rl::Region::LateBound(debruijn, index, def_id)) => {
209209
let name = lifetime_name(def_id.expect_local());
210210
let br = ty::BoundRegion {
211211
var: ty::BoundVar::from_u32(index),
@@ -222,7 +222,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
222222
tcx.mk_region(ty::ReLateBound(debruijn, br))
223223
}
224224

225-
Some(rl::Region::EarlyBound(index, id, _)) => {
225+
Some(rl::Region::EarlyBound(index, id)) => {
226226
let name = lifetime_name(id.expect_local());
227227
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { def_id: id, index, name }))
228228
}

compiler/rustc_typeck/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
13751375
match self.tcx.named_region(lt.hir_id) {
13761376
Some(rl::Region::Static | rl::Region::EarlyBound(..)) => {}
13771377
Some(
1378-
rl::Region::LateBound(debruijn, _, _, _)
1378+
rl::Region::LateBound(debruijn, _, _)
13791379
| rl::Region::LateBoundAnon(debruijn, _, _),
13801380
) if debruijn < self.outer_index => {}
13811381
Some(

src/librustdoc/clean/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ impl Clean<Lifetime> for hir::Lifetime {
193193
fn clean(&self, cx: &mut DocContext<'_>) -> Lifetime {
194194
let def = cx.tcx.named_region(self.hir_id);
195195
if let Some(
196-
rl::Region::EarlyBound(_, node_id, _)
197-
| rl::Region::LateBound(_, _, node_id, _)
196+
rl::Region::EarlyBound(_, node_id)
197+
| rl::Region::LateBound(_, _, node_id)
198198
| rl::Region::Free(_, node_id),
199199
) = def
200200
{

0 commit comments

Comments
 (0)