forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#112145 - wesleywiser:backport_112070, r=Mark-…
…Simulacrum Backport of rust-lang#112070 Backports rust-lang#112070 to stable r? `@Mark-Simulacrum`
- Loading branch information
Showing
13 changed files
with
92 additions
and
19 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
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
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
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
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
18 changes: 18 additions & 0 deletions
18
tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-1.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,18 @@ | ||
// edition:2021 | ||
|
||
// regression test for #112056 | ||
|
||
fn extend_lifetime<'a, 'b>(x: &mut (&'a str,), y: &'b str) { | ||
let mut closure = |input| x.0 = input; | ||
//~^ ERROR: lifetime may not live long enough | ||
closure(y); | ||
} | ||
|
||
fn main() { | ||
let mut tuple = ("static",); | ||
{ | ||
let x = String::from("temporary"); | ||
extend_lifetime(&mut tuple, &x); | ||
} | ||
println!("{}", tuple.0); | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-1.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: lifetime may not live long enough | ||
--> $DIR/unique-borrows-are-invariant-1.rs:6:31 | ||
| | ||
LL | fn extend_lifetime<'a, 'b>(x: &mut (&'a str,), y: &'b str) { | ||
| -- -- lifetime `'b` defined here | ||
| | | ||
| lifetime `'a` defined here | ||
LL | let mut closure = |input| x.0 = input; | ||
| ^^^^^^^^^^^ assignment requires that `'b` must outlive `'a` | ||
| | ||
= help: consider adding the following bound: `'b: 'a` | ||
|
||
error: aborting due to previous error | ||
|
31 changes: 31 additions & 0 deletions
31
tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-2.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,31 @@ | ||
// edition:2021 | ||
|
||
// regression test for #112056 | ||
|
||
struct Spooky<'b> { | ||
owned: Option<&'static u32>, | ||
borrowed: &'b &'static u32, | ||
} | ||
|
||
impl<'b> Spooky<'b> { | ||
fn create_self_reference<'a>(&'a mut self) { | ||
let mut closure = || { | ||
if let Some(owned) = &self.owned { | ||
let borrow: &'a &'static u32 = owned; | ||
self.borrowed = borrow; | ||
//~^ ERROR: lifetime may not live long enough | ||
} | ||
}; | ||
closure(); | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut spooky: Spooky<'static> = Spooky { | ||
owned: Some(&1), | ||
borrowed: &&1, | ||
}; | ||
spooky.create_self_reference(); | ||
spooky.owned = None; | ||
println!("{}", **spooky.borrowed); | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-2.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,15 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/unique-borrows-are-invariant-2.rs:15:17 | ||
| | ||
LL | impl<'b> Spooky<'b> { | ||
| -- lifetime `'b` defined here | ||
LL | fn create_self_reference<'a>(&'a mut self) { | ||
| -- lifetime `'a` defined here | ||
... | ||
LL | self.borrowed = borrow; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ assignment requires that `'a` must outlive `'b` | ||
| | ||
= help: consider adding the following bound: `'a: 'b` | ||
|
||
error: aborting due to previous error | ||
|