File tree Expand file tree Collapse file tree 3 files changed +53
-5
lines changed
compiler/rustc_borrowck/src/diagnostics Expand file tree Collapse file tree 3 files changed +53
-5
lines changed Original file line number Diff line number Diff line change @@ -864,15 +864,13 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
864864 } ;
865865
866866 let tcx = self . infcx . tcx ;
867- let body_parent_did = tcx. opt_parent ( self . mir_def_id ( ) . to_def_id ( ) ) ?;
868- if tcx. parent ( region. def_id ) != body_parent_did
869- || tcx. def_kind ( body_parent_did) != DefKind :: Impl
870- {
867+ let region_parent = tcx. parent ( region. def_id ) ;
868+ if tcx. def_kind ( region_parent) != DefKind :: Impl {
871869 return None ;
872870 }
873871
874872 let mut found = false ;
875- tcx. fold_regions ( tcx. type_of ( body_parent_did ) , |r : ty:: Region < ' tcx > , _| {
873+ tcx. fold_regions ( tcx. type_of ( region_parent ) , |r : ty:: Region < ' tcx > , _| {
876874 if * r == ty:: ReEarlyBound ( region) {
877875 found = true ;
878876 }
Original file line number Diff line number Diff line change 1+ use std:: marker:: PhantomData ;
2+
3+ pub struct NfaBuilder < ' brand > {
4+ brand : PhantomData < & ' brand mut & ' brand mut ( ) > ,
5+ }
6+
7+ impl NfaBuilder < ' _ > {
8+ pub fn with < R , F : FnOnce ( NfaBuilder < ' _ > ) -> R > ( f : F ) -> R {
9+ Brand :: with ( |brand| {
10+ f ( Self { brand : brand. lt } )
11+ //~^ ERROR lifetime may not live long enough
12+ //~| ERROR lifetime may not live long enough
13+ } )
14+ }
15+ }
16+
17+ #[ derive( Clone , Copy ) ]
18+ pub struct Brand < ' brand > {
19+ lt : PhantomData < & ' brand mut & ' brand mut ( ) > ,
20+ }
21+
22+ impl Brand < ' _ > {
23+ pub fn with < R , F : FnOnce ( Brand < ' _ > ) -> R > ( f : F ) -> R {
24+ f ( Self { lt : PhantomData } )
25+ }
26+ }
27+
28+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: lifetime may not live long enough
2+ --> $DIR/issue-102209.rs:10:29
3+ |
4+ LL | impl NfaBuilder<'_> {
5+ | -- lifetime `'2` appears in the `impl`'s self type
6+ LL | pub fn with<R, F: FnOnce(NfaBuilder<'_>) -> R>(f: F) -> R {
7+ LL | Brand::with(|brand| {
8+ | ----- has type `Brand<'1>`
9+ LL | f(Self { brand: brand.lt })
10+ | ^^^^^^^^ this usage requires that `'1` must outlive `'2`
11+
12+ error: lifetime may not live long enough
13+ --> $DIR/issue-102209.rs:10:29
14+ |
15+ LL | impl NfaBuilder<'_> {
16+ | -- lifetime `'1` appears in the `impl`'s self type
17+ ...
18+ LL | f(Self { brand: brand.lt })
19+ | ^^^^^^^^ this usage requires that `'1` must outlive `'static`
20+
21+ error: aborting due to 2 previous errors
22+
You can’t perform that action at this time.
0 commit comments