Update tests.

This commit is contained in:
Mara Bos 2025-06-13 09:20:48 +02:00
parent 99929fa9e6
commit ff5ba7aa74
11 changed files with 69 additions and 132 deletions

View file

@ -754,7 +754,6 @@ ui/consts/issue-46553.rs
ui/consts/issue-47789.rs
ui/consts/issue-50439.rs
ui/consts/issue-52023-array-size-pointer-cast.rs
ui/consts/issue-54224.rs
ui/consts/issue-54348.rs
ui/consts/issue-54387.rs
ui/consts/issue-54582.rs

View file

@ -18,7 +18,7 @@ const B: *mut i32 = &mut 4; //~ ERROR mutable references are not allowed
const B2: Option<&mut i32> = None;
// Not ok, can't prove that no mutable allocation ends up in final value
const B3: Option<&mut i32> = Some(&mut 42); //~ ERROR temporary value dropped while borrowed
const B3: Option<&mut i32> = Some(&mut 42); //~ ERROR mutable references are not allowed
const fn helper(x: &mut i32) -> Option<&mut i32> { Some(x) }
const B4: Option<&mut i32> = helper(&mut 42); //~ ERROR temporary value dropped while borrowed

View file

@ -4,15 +4,11 @@ error[E0764]: mutable references are not allowed in the final value of constants
LL | const B: *mut i32 = &mut 4;
| ^^^^^^
error[E0716]: temporary value dropped while borrowed
--> $DIR/mut_ref_in_final.rs:21:40
error[E0764]: mutable references are not allowed in the final value of constants
--> $DIR/mut_ref_in_final.rs:21:35
|
LL | const B3: Option<&mut i32> = Some(&mut 42);
| ----------^^-
| | | |
| | | temporary value is freed at the end of this statement
| | creates a temporary value which is freed while still in use
| using this value as a constant requires that borrow lasts for `'static`
| ^^^^^^^
error[E0716]: temporary value dropped while borrowed
--> $DIR/mut_ref_in_final.rs:24:42

View file

@ -1,12 +0,0 @@
const FOO: Option<&[[u8; 3]]> = Some(&[*b"foo"]); //~ ERROR temporary value dropped while borrowed
use std::borrow::Cow;
pub const X: [u8; 3] = *b"ABC";
pub const Y: Cow<'static, [ [u8; 3] ]> = Cow::Borrowed(&[X]);
pub const Z: Cow<'static, [ [u8; 3] ]> = Cow::Borrowed(&[*b"ABC"]);
//~^ ERROR temporary value dropped while borrowed
fn main() {}

View file

@ -1,23 +0,0 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/issue-54224.rs:1:39
|
LL | const FOO: Option<&[[u8; 3]]> = Some(&[*b"foo"]);
| ------^^^^^^^^^-
| | | |
| | | temporary value is freed at the end of this statement
| | creates a temporary value which is freed while still in use
| using this value as a constant requires that borrow lasts for `'static`
error[E0716]: temporary value dropped while borrowed
--> $DIR/issue-54224.rs:9:57
|
LL | pub const Z: Cow<'static, [ [u8; 3] ]> = Cow::Borrowed(&[*b"ABC"]);
| ---------------^^^^^^^^^-
| | | |
| | | temporary value is freed at the end of this statement
| | creates a temporary value which is freed while still in use
| using this value as a constant requires that borrow lasts for `'static`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0716`.

View file

@ -3,10 +3,11 @@
#![allow(unconditional_panic)]
use std::cell::Cell;
use std::convert::identity;
use std::mem::ManuallyDrop;
// We do not promote mutable references.
static mut TEST1: Option<&mut [i32]> = Some(&mut [1, 2, 3]); //~ ERROR temporary value dropped while borrowed
static mut TEST1: &mut [i32] = identity(&mut [1, 2, 3]); //~ ERROR temporary value dropped while borrowed
static mut TEST2: &'static mut [i32] = {
let x = &mut [1,2,3]; //~ ERROR temporary value dropped while borrowed

View file

@ -1,15 +1,15 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:9:50
--> $DIR/promote-not.rs:10:46
|
LL | static mut TEST1: Option<&mut [i32]> = Some(&mut [1, 2, 3]);
| ----------^^^^^^^^^-
| | | |
| | | temporary value is freed at the end of this statement
| | creates a temporary value which is freed while still in use
| using this value as a static requires that borrow lasts for `'static`
LL | static mut TEST1: &mut [i32] = identity(&mut [1, 2, 3]);
| --------------^^^^^^^^^-
| | | |
| | | temporary value is freed at the end of this statement
| | creates a temporary value which is freed while still in use
| using this value as a static requires that borrow lasts for `'static`
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:12:18
--> $DIR/promote-not.rs:13:18
|
LL | let x = &mut [1,2,3];
| ^^^^^^^ creates a temporary value which is freed while still in use
@ -19,7 +19,7 @@ LL | };
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:34:29
--> $DIR/promote-not.rs:35:29
|
LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x };
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -29,7 +29,7 @@ LL | };
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:40:29
--> $DIR/promote-not.rs:41:29
|
LL | let _val: &'static _ = &(Cell::new(1), 2).1;
| ---------- ^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -39,7 +39,7 @@ LL | };
| - temporary value is freed at the end of this statement
error[E0493]: destructor of `String` cannot be evaluated at compile-time
--> $DIR/promote-not.rs:47:14
--> $DIR/promote-not.rs:48:14
|
LL | let x = &String::new();
| ^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants
@ -48,7 +48,7 @@ LL | };
| - value is dropped here
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:59:33
--> $DIR/promote-not.rs:60:33
|
LL | let _x: &'static u32 = &mk_panic();
| ------------ ^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -58,7 +58,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:21:32
--> $DIR/promote-not.rs:22:32
|
LL | let _x: &'static () = &foo();
| ----------- ^^^^^ creates a temporary value which is freed while still in use
@ -68,7 +68,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:29:29
--> $DIR/promote-not.rs:30:29
|
LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x };
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -78,7 +78,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:65:29
--> $DIR/promote-not.rs:66:29
|
LL | let _val: &'static _ = &(Cell::new(1), 2).0;
| ---------- ^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -89,7 +89,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:66:29
--> $DIR/promote-not.rs:67:29
|
LL | let _val: &'static _ = &(Cell::new(1), 2).1;
| ---------- ^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -100,7 +100,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:69:29
--> $DIR/promote-not.rs:70:29
|
LL | let _val: &'static _ = &(1/0);
| ---------- ^^^^^ creates a temporary value which is freed while still in use
@ -111,7 +111,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:70:29
--> $DIR/promote-not.rs:71:29
|
LL | let _val: &'static _ = &(1/(1-1));
| ---------- ^^^^^^^^^ creates a temporary value which is freed while still in use
@ -122,7 +122,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:71:29
--> $DIR/promote-not.rs:72:29
|
LL | let _val: &'static _ = &((1+1)/(1-1));
| ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -133,7 +133,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:72:29
--> $DIR/promote-not.rs:73:29
|
LL | let _val: &'static _ = &(i32::MIN/-1);
| ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -144,7 +144,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:73:29
--> $DIR/promote-not.rs:74:29
|
LL | let _val: &'static _ = &(i32::MIN/(0-1));
| ---------- ^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -155,7 +155,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:74:29
--> $DIR/promote-not.rs:75:29
|
LL | let _val: &'static _ = &(-128i8/-1);
| ---------- ^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -166,7 +166,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:75:29
--> $DIR/promote-not.rs:76:29
|
LL | let _val: &'static _ = &(1%0);
| ---------- ^^^^^ creates a temporary value which is freed while still in use
@ -177,7 +177,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:76:29
--> $DIR/promote-not.rs:77:29
|
LL | let _val: &'static _ = &(1%(1-1));
| ---------- ^^^^^^^^^ creates a temporary value which is freed while still in use
@ -188,7 +188,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:77:29
--> $DIR/promote-not.rs:78:29
|
LL | let _val: &'static _ = &([1,2,3][4]+1);
| ---------- ^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -199,7 +199,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:81:29
--> $DIR/promote-not.rs:82:29
|
LL | let _val: &'static _ = &TEST_DROP;
| ---------- ^^^^^^^^^ creates a temporary value which is freed while still in use
@ -210,7 +210,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:83:29
--> $DIR/promote-not.rs:84:29
|
LL | let _val: &'static _ = &&TEST_DROP;
| ---------- ^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -221,7 +221,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:83:30
--> $DIR/promote-not.rs:84:30
|
LL | let _val: &'static _ = &&TEST_DROP;
| ---------- ^^^^^^^^^ creates a temporary value which is freed while still in use
@ -232,7 +232,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:86:29
--> $DIR/promote-not.rs:87:29
|
LL | let _val: &'static _ = &(&TEST_DROP,);
| ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -243,7 +243,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:86:31
--> $DIR/promote-not.rs:87:31
|
LL | let _val: &'static _ = &(&TEST_DROP,);
| ---------- ^^^^^^^^^ creates a temporary value which is freed while still in use
@ -254,7 +254,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:89:29
--> $DIR/promote-not.rs:90:29
|
LL | let _val: &'static _ = &[&TEST_DROP; 1];
| ---------- ^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
@ -265,7 +265,7 @@ LL | }
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:89:31
--> $DIR/promote-not.rs:90:31
|
LL | let _val: &'static _ = &[&TEST_DROP; 1];
| ---------- ^^^^^^^^^ - temporary value is freed at the end of this statement
@ -274,7 +274,7 @@ LL | let _val: &'static _ = &[&TEST_DROP; 1];
| type annotation requires that borrow lasts for `'static`
error[E0716]: temporary value dropped while borrowed
--> $DIR/promote-not.rs:98:26
--> $DIR/promote-not.rs:99:26
|
LL | let x: &'static _ = &UnionWithCell { f1: 0 };
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use

View file

@ -43,8 +43,8 @@ fn main() {
// Disallow impls which relates lifetimes in the coroutine interior
let gen = #[coroutine] move || {
let a = A(&mut true, &mut true, No);
//~^ ERROR temporary value dropped while borrowed
//~| ERROR temporary value dropped while borrowed
//~^ ERROR borrow may still be in use when coroutine yields
//~| ERROR borrow may still be in use when coroutine yields
yield;
assert_foo(a);
};

View file

@ -1,36 +1,34 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/auto-trait-regions.rs:45:24
error[E0626]: borrow may still be in use when coroutine yields
--> $DIR/auto-trait-regions.rs:45:19
|
LL | let gen = #[coroutine] move || {
| ------- within this coroutine
LL | let a = A(&mut true, &mut true, No);
| ^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
| ^^^^^^^^^
...
LL | assert_foo(a);
| - borrow later used here
LL | yield;
| ----- possible yield occurs here
|
help: consider using a `let` binding to create a longer lived value
|
LL ~ let mut binding = true;
LL ~ let a = A(&mut binding, &mut true, No);
help: add `static` to mark this coroutine as unmovable
|
LL | let gen = #[coroutine] static move || {
| ++++++
error[E0716]: temporary value dropped while borrowed
--> $DIR/auto-trait-regions.rs:45:35
error[E0626]: borrow may still be in use when coroutine yields
--> $DIR/auto-trait-regions.rs:45:30
|
LL | let gen = #[coroutine] move || {
| ------- within this coroutine
LL | let a = A(&mut true, &mut true, No);
| ^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
| ^^^^^^^^^
...
LL | assert_foo(a);
| - borrow later used here
LL | yield;
| ----- possible yield occurs here
|
help: consider using a `let` binding to create a longer lived value
|
LL ~ let mut binding = true;
LL ~ let a = A(&mut true, &mut binding, No);
help: add `static` to mark this coroutine as unmovable
|
LL | let gen = #[coroutine] static move || {
| ++++++
error: implementation of `Foo` is not general enough
--> $DIR/auto-trait-regions.rs:31:5
@ -52,4 +50,4 @@ LL | assert_foo(gen);
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0716`.
For more information about this error, try `rustc --explain E0626`.

View file

@ -4,12 +4,6 @@ impl Drop for WithDtor {
fn drop(&mut self) {}
}
static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
//~^ ERROR destructor of
const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
//~^ ERROR destructor of
static EARLY_DROP_S: i32 = (WithDtor, 0).1;
//~^ ERROR destructor of

View file

@ -1,21 +1,5 @@
error[E0493]: destructor of `WithDtor` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:7:60
|
LL | static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
| ^^^^^^^^- value is dropped here
| |
| the destructor for this type cannot be evaluated in statics
error[E0493]: destructor of `WithDtor` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:10:59
|
LL | const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
| ^^^^^^^^- value is dropped here
| |
| the destructor for this type cannot be evaluated in constants
error[E0493]: destructor of `(WithDtor, i32)` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:13:28
--> $DIR/static-drop-scope.rs:7:28
|
LL | static EARLY_DROP_S: i32 = (WithDtor, 0).1;
| ^^^^^^^^^^^^^ - value is dropped here
@ -23,7 +7,7 @@ LL | static EARLY_DROP_S: i32 = (WithDtor, 0).1;
| the destructor for this type cannot be evaluated in statics
error[E0493]: destructor of `(WithDtor, i32)` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:16:27
--> $DIR/static-drop-scope.rs:10:27
|
LL | const EARLY_DROP_C: i32 = (WithDtor, 0).1;
| ^^^^^^^^^^^^^ - value is dropped here
@ -31,7 +15,7 @@ LL | const EARLY_DROP_C: i32 = (WithDtor, 0).1;
| the destructor for this type cannot be evaluated in constants
error[E0493]: destructor of `(Option<WithDtor>, i32)` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:27:34
--> $DIR/static-drop-scope.rs:21:34
|
LL | const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1;
| ^^^^^^^^^^^^^^^^^^^ - value is dropped here
@ -39,7 +23,7 @@ LL | const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1;
| the destructor for this type cannot be evaluated in constants
error[E0493]: destructor of `(Option<WithDtor>, i32)` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:32:43
--> $DIR/static-drop-scope.rs:26:43
|
LL | const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;
| ^^^^^^^^^^^ - value is dropped here
@ -47,7 +31,7 @@ LL | const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;
| the destructor for this type cannot be evaluated in constants
error[E0493]: destructor of `T` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:19:24
--> $DIR/static-drop-scope.rs:13:24
|
LL | const fn const_drop<T>(_: T) {}
| ^ - value is dropped here
@ -55,7 +39,7 @@ LL | const fn const_drop<T>(_: T) {}
| the destructor for this type cannot be evaluated in constant functions
error[E0493]: destructor of `(T, ())` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:23:5
--> $DIR/static-drop-scope.rs:17:5
|
LL | (x, ()).1
| ^^^^^^^ the destructor for this type cannot be evaluated in constant functions
@ -63,6 +47,6 @@ LL |
LL | }
| - value is dropped here
error: aborting due to 8 previous errors
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0493`.