Generate synthetic impl region even in closure body in associated fn

This commit is contained in:
Michael Goulet 2022-09-29 22:27:50 +00:00
parent 9f1a21ae2b
commit c1c3dacc78
3 changed files with 53 additions and 5 deletions

View File

@ -864,15 +864,13 @@ fn give_name_if_anonymous_region_appears_in_impl_signature(
};
let tcx = self.infcx.tcx;
let body_parent_did = tcx.opt_parent(self.mir_def_id().to_def_id())?;
if tcx.parent(region.def_id) != body_parent_did
|| tcx.def_kind(body_parent_did) != DefKind::Impl
{
let region_parent = tcx.parent(region.def_id);
if tcx.def_kind(region_parent) != DefKind::Impl {
return None;
}
let mut found = false;
tcx.fold_regions(tcx.type_of(body_parent_did), |r: ty::Region<'tcx>, _| {
tcx.fold_regions(tcx.type_of(region_parent), |r: ty::Region<'tcx>, _| {
if *r == ty::ReEarlyBound(region) {
found = true;
}

View File

@ -0,0 +1,28 @@
use std::marker::PhantomData;
pub struct NfaBuilder<'brand> {
brand: PhantomData<&'brand mut &'brand mut ()>,
}
impl NfaBuilder<'_> {
pub fn with<R, F: FnOnce(NfaBuilder<'_>) -> R>(f: F) -> R {
Brand::with(|brand| {
f(Self { brand: brand.lt })
//~^ ERROR lifetime may not live long enough
//~| ERROR lifetime may not live long enough
})
}
}
#[derive(Clone, Copy)]
pub struct Brand<'brand> {
lt: PhantomData<&'brand mut &'brand mut ()>,
}
impl Brand<'_> {
pub fn with<R, F: FnOnce(Brand<'_>) -> R>(f: F) -> R {
f(Self { lt: PhantomData })
}
}
fn main() {}

View File

@ -0,0 +1,22 @@
error: lifetime may not live long enough
--> $DIR/issue-102209.rs:10:29
|
LL | impl NfaBuilder<'_> {
| -- lifetime `'2` appears in the `impl`'s self type
LL | pub fn with<R, F: FnOnce(NfaBuilder<'_>) -> R>(f: F) -> R {
LL | Brand::with(|brand| {
| ----- has type `Brand<'1>`
LL | f(Self { brand: brand.lt })
| ^^^^^^^^ this usage requires that `'1` must outlive `'2`
error: lifetime may not live long enough
--> $DIR/issue-102209.rs:10:29
|
LL | impl NfaBuilder<'_> {
| -- lifetime `'1` appears in the `impl`'s self type
...
LL | f(Self { brand: brand.lt })
| ^^^^^^^^ this usage requires that `'1` must outlive `'static`
error: aborting due to 2 previous errors