Rollup merge of #54702 - RalfJung:fn-ptr-promotion, r=oli-obk
do not promote comparing function pointers This *could* break existing code that relied on fn ptr comparison getting promoted to `'static` lifetime. Fixes https://github.com/rust-lang/rust/issues/54696
This commit is contained in:
commit
d9d96637d4
6 changed files with 37 additions and 6 deletions
8
src/test/run-pass/issues/issue-54696.rs
Normal file
8
src/test/run-pass/issues/issue-54696.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// run-pass
|
||||
|
||||
fn main() {
|
||||
// We shouldn't promote this
|
||||
&(main as fn() == main as fn());
|
||||
// Also check nested case
|
||||
&(&(main as fn()) == &(main as fn()));
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ error[E0716]: temporary value dropped while borrowed
|
|||
|
|
||||
LL | let y: &'static usize = &(&1 as *const i32 as usize + 1); //~ ERROR does not live long enough
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
LL | let z: &'static i32 = &(unsafe { *(42 as *const i32) }); //~ ERROR does not live long enough
|
||||
...
|
||||
LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
|
||||
|
|
@ -25,11 +25,22 @@ error[E0716]: temporary value dropped while borrowed
|
|||
|
|
||||
LL | let z: &'static i32 = &(unsafe { *(42 as *const i32) }); //~ ERROR does not live long enough
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
LL | let a: &'static bool = &(main as fn() == main as fn()); //~ ERROR does not live long enough
|
||||
LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
|
||||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_raw_ptr_ops.rs:18:29
|
||||
|
|
||||
LL | let a: &'static bool = &(main as fn() == main as fn()); //~ ERROR does not live long enough
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
|
||||
LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
|
||||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0716`.
|
||||
|
|
|
|||
|
|
@ -15,4 +15,5 @@ fn main() {
|
|||
//~^ ERROR does not live long enough
|
||||
let y: &'static usize = &(&1 as *const i32 as usize + 1); //~ ERROR does not live long enough
|
||||
let z: &'static i32 = &(unsafe { *(42 as *const i32) }); //~ ERROR does not live long enough
|
||||
let a: &'static bool = &(main as fn() == main as fn()); //~ ERROR does not live long enough
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ error[E0597]: borrowed value does not live long enough
|
|||
|
|
||||
LL | let y: &'static usize = &(&1 as *const i32 as usize + 1); //~ ERROR does not live long enough
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
|
||||
LL | let z: &'static i32 = &(unsafe { *(42 as *const i32) }); //~ ERROR does not live long enough
|
||||
...
|
||||
LL | }
|
||||
| - temporary value only lives until here
|
||||
|
|
||||
|
|
@ -25,11 +25,22 @@ error[E0597]: borrowed value does not live long enough
|
|||
|
|
||||
LL | let z: &'static i32 = &(unsafe { *(42 as *const i32) }); //~ ERROR does not live long enough
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
|
||||
LL | let a: &'static bool = &(main as fn() == main as fn()); //~ ERROR does not live long enough
|
||||
LL | }
|
||||
| - temporary value only lives until here
|
||||
|
|
||||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error[E0597]: borrowed value does not live long enough
|
||||
--> $DIR/promoted_raw_ptr_ops.rs:18:29
|
||||
|
|
||||
LL | let a: &'static bool = &(main as fn() == main as fn()); //~ ERROR does not live long enough
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
|
||||
LL | }
|
||||
| - temporary value only lives until here
|
||||
|
|
||||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0597`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue