-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check
Copy
lifetimes bounds when copying from a projection
- Loading branch information
1 parent
d538b80
commit cd9f5ff
Showing
3 changed files
with
51 additions
and
27 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
12 changes: 12 additions & 0 deletions
12
src/test/ui/nll/do-not-ignore-lifetime-bounds-in-copy-proj.rs
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,12 @@ | ||
// Test that the 'static bound from the Copy impl is respected. Regression test for #29149. | ||
|
||
#[derive(Clone)] | ||
struct Foo<'a>(&'a u32); | ||
impl Copy for Foo<'static> {} | ||
|
||
fn main() { | ||
let s = 2; | ||
let a = (Foo(&s),); //~ ERROR `s` does not live long enough [E0597] | ||
drop(a.0); | ||
drop(a.0); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/nll/do-not-ignore-lifetime-bounds-in-copy-proj.stderr
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,14 @@ | ||
error[E0597]: `s` does not live long enough | ||
--> $DIR/do-not-ignore-lifetime-bounds-in-copy-proj.rs:9:18 | ||
| | ||
LL | let a = (Foo(&s),); | ||
| ^^ borrowed value does not live long enough | ||
LL | drop(a.0); | ||
| --- copying this value requires that `s` is borrowed for `'static` | ||
LL | drop(a.0); | ||
LL | } | ||
| - `s` dropped here while still borrowed | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0597`. |