-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strict region folders #110312
Strict region folders #110312
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -458,13 +458,13 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> { | |
} | ||
|
||
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { | ||
if let ty::ReFree(fr) = *r { | ||
self.tcx.mk_re_free( | ||
match r.kind() { | ||
ty::ReFree(fr) => self.tcx.mk_re_free( | ||
fr.scope, | ||
self.mapping.get(&fr.bound_region).copied().unwrap_or(fr.bound_region), | ||
) | ||
} else { | ||
r | ||
), | ||
ty::ReEarlyBound(_) | ty::ReStatic => r, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably need to support |
||
r => bug!("unexpected region: {r:?}"), | ||
} | ||
} | ||
} | ||
|
@@ -765,11 +765,15 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( | |
let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len(); | ||
let ty = tcx.fold_regions(ty, |region, _| { | ||
match region.kind() { | ||
// Remap all free regions, which correspond to late-bound regions in the function. | ||
// Remap all free regions, which correspond to late-bound regions in the | ||
// function. | ||
ty::ReFree(_) => {} | ||
// Remap early-bound regions as long as they don't come from the `impl` itself. | ||
// Remap early-bound regions as long as they don't come from the `impl` | ||
// itself. | ||
ty::ReEarlyBound(ebr) if tcx.parent(ebr.def_id) != impl_m.container_id(tcx) => {} | ||
_ => return region, | ||
ty::ReEarlyBound(_) | | ||
ty::ReStatic => return region, | ||
r => bug!("unexpected region: {r:?}"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ReError here |
||
} | ||
let Some(ty::ReEarlyBound(e)) = map.get(®ion.into()).map(|r| r.expect_region().kind()) | ||
else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1574,17 +1574,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> { | |
&& let hir::OpaqueTyOrigin::FnReturn(source) | hir::OpaqueTyOrigin::AsyncFn(source) = opaque.origin | ||
&& source == self.fn_def_id | ||
{ | ||
let opaque_ty = tcx.fold_regions(unshifted_opaque_ty, |re, depth| { | ||
if let ty::ReLateBound(index, bv) = re.kind() { | ||
if depth != ty::INNERMOST { | ||
return tcx.mk_re_error_with_message( | ||
DUMMY_SP, | ||
"we shouldn't walk non-predicate binders with `impl Trait`...", | ||
); | ||
} | ||
tcx.mk_re_late_bound(index.shifted_out_to_binder(self.depth), bv) | ||
} else { | ||
re | ||
let opaque_ty = tcx.fold_regions(unshifted_opaque_ty, |re, _depth| { | ||
match re.kind() { | ||
ty::ReEarlyBound(_) | ty::ReFree(_) => re, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably need to support |
||
r => bug!("unexpected region: {r:?}"), | ||
} | ||
}); | ||
for (bound, bound_span) in tcx | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -387,8 +387,10 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { | |
|
||
fn ct_infer(&self, ty: Ty<'tcx>, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> { | ||
let ty = self.tcx.fold_regions(ty, |r, _| match *r { | ||
ty::ReErased => self.tcx.lifetimes.re_static, | ||
_ => r, | ||
// This is never reached in practice. If it ever is reached, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not hit this in practice, I checked. But as far as I know, |
||
// `ReErased` should be changed to `ReStatic`, and any other region | ||
// left alone. | ||
r => bug!("unexpected region: {r:?}"), | ||
}); | ||
self.tcx().const_error_with_message(ty, span, "bad placeholder constant") | ||
} | ||
|
@@ -1142,7 +1144,7 @@ fn infer_return_ty_for_fn_sig<'tcx>( | |
// Typeck doesn't expect erased regions to be returned from `type_of`. | ||
let fn_sig = tcx.fold_regions(fn_sig, |r, _| match *r { | ||
ty::ReErased => tcx.lifetimes.re_static, | ||
_ => r, | ||
r => bug!("unexpected region: {r:?}"), | ||
}); | ||
|
||
let mut visitor = HirPlaceholderCollector::default(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,7 +270,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
// Hack to make equality checks on types with inference variables and regions useful. | ||
let mut eraser = BottomUpFolder { | ||
tcx: self.tcx, | ||
lt_op: |_| self.tcx.lifetimes.re_erased, | ||
lt_op: |r| match r.kind() { | ||
ty::ReStatic | ty::ReVar(_) | ty::ReErased => self.tcx.lifetimes.re_erased, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ICEs on struct Wrapper<'a, T>(&'a T);
fn foo<'a, T>() -> Wrapper<'a, T> {}
fn needs_i32(_: Wrapper<'static, i32>) {}
fn test<'a>() {
let x = foo::<'a, ()>();
needs_i32(x);
}
fn main() {} But also, I just rewrote all this code in #108687, so whatever. |
||
r => bug!("unexpected region: {r:?}"), | ||
}, | ||
ct_op: |c| c, | ||
ty_op: |t| match *t.kind() { | ||
ty::Infer(ty::TyVar(_)) => self.tcx.mk_ty_var(ty::TyVid::from_u32(0)), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,19 +257,20 @@ pub fn resolve_interior<'a, 'tcx>( | |
_ => mk_bound_region(None), | ||
} | ||
} | ||
// FIXME: these should use `BrNamed` | ||
// // FIXME: these should use `BrNamed` | ||
ty::ReEarlyBound(region) => { | ||
mk_bound_region(Some(fcx.tcx.def_span(region.def_id))) | ||
} | ||
ty::ReLateBound(_, ty::BoundRegion { kind, .. }) | ||
| ty::ReFree(ty::FreeRegion { bound_region: kind, .. }) => match kind { | ||
// ty::ReLateBound(_, ty::BoundRegion { kind, .. }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stray comment? I think it's ok to ICE on |
||
ty::ReFree(ty::FreeRegion { bound_region: kind, .. }) => match kind { | ||
ty::BoundRegionKind::BrAnon(span) => mk_bound_region(span), | ||
ty::BoundRegionKind::BrNamed(def_id, _) => { | ||
mk_bound_region(Some(fcx.tcx.def_span(def_id))) | ||
} | ||
ty::BoundRegionKind::BrEnv => mk_bound_region(None), | ||
}, | ||
_ => mk_bound_region(None), | ||
ty::ReStatic | ty::ReErased => mk_bound_region(None), | ||
r => bug!("unexpected region: {r:?}"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We must handle fn missing() -> &'missing () { &() }
async fn async_fn() {}
fn main() {
async {
let x = missing();
async_fn().await;
drop(x);
};
} |
||
}; | ||
let r = fcx.tcx.mk_re_late_bound(current_depth, br); | ||
r | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
ReErased
is the only kind we expect here.