-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #69145 - matthewjasper:mir-typeck-static-ty, r=nikomats…
…akis Fix MIR typeck soundness holes * Check types of static items * Always check lifetime bounds of `Copy` impls r? @nikomatsakis closes #69114
- Loading branch information
Showing
7 changed files
with
148 additions
and
29 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`. |
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,30 @@ | ||
// Check that borrowck ensures that `static mut` items have the expected type. | ||
|
||
static FOO: u8 = 42; | ||
static mut BAR: &'static u8 = &FOO; | ||
static mut BAR_ELIDED: &u8 = &FOO; | ||
|
||
fn main() { | ||
unsafe { | ||
println!("{} {}", BAR, BAR_ELIDED); | ||
set_bar(); | ||
set_bar_elided(); | ||
println!("{} {}", BAR, BAR_ELIDED); | ||
} | ||
} | ||
|
||
fn set_bar() { | ||
let n = 42; | ||
unsafe { | ||
BAR = &n; | ||
//~^ ERROR does not live long enough | ||
} | ||
} | ||
|
||
fn set_bar_elided() { | ||
let n = 42; | ||
unsafe { | ||
BAR_ELIDED = &n; | ||
//~^ ERROR does not live long enough | ||
} | ||
} |
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,27 @@ | ||
error[E0597]: `n` does not live long enough | ||
--> $DIR/issue-69114-static-mut-ty.rs:19:15 | ||
| | ||
LL | BAR = &n; | ||
| ------^^ | ||
| | | | ||
| | borrowed value does not live long enough | ||
| assignment requires that `n` is borrowed for `'static` | ||
... | ||
LL | } | ||
| - `n` dropped here while still borrowed | ||
|
||
error[E0597]: `n` does not live long enough | ||
--> $DIR/issue-69114-static-mut-ty.rs:27:22 | ||
| | ||
LL | BAR_ELIDED = &n; | ||
| -------------^^ | ||
| | | | ||
| | borrowed value does not live long enough | ||
| assignment requires that `n` is borrowed for `'static` | ||
... | ||
LL | } | ||
| - `n` dropped here while still borrowed | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0597`. |
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,9 @@ | ||
// Check that borrowck ensures that `static` items have the expected type. | ||
|
||
static FOO: &'static (dyn Fn(&'static u8) + Send + Sync) = &drop; | ||
|
||
fn main() { | ||
let n = 42; | ||
FOO(&n); | ||
//~^ ERROR does not live long enough | ||
} |
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[E0597]: `n` does not live long enough | ||
--> $DIR/issue-69114-static-ty.rs:7:9 | ||
| | ||
LL | FOO(&n); | ||
| ----^^- | ||
| | | | ||
| | borrowed value does not live long enough | ||
| argument requires that `n` is borrowed for `'static` | ||
LL | | ||
LL | } | ||
| - `n` dropped here while still borrowed | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0597`. |