forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#102490 - compiler-errors:closure-body-impl-…
…lifetime, r=cjgillot Generate synthetic region from `impl` even in closure body within an associated fn Fixes rust-lang#102209
- Loading branch information
Showing
3 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|