Skip to content

Commit d779062

Browse files
committed
Extend tests to cover runtime promotion cases, too
1 parent 9ec72df commit d779062

6 files changed

+106
-6
lines changed

src/test/ui/consts/promoted_const_call.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ pub const C: () = {
99
//~| ERROR: temporary value dropped while borrowed
1010
};
1111

12-
fn main() {}
12+
fn main() {
13+
let _: &'static _ = &id(&Panic);
14+
//~^ ERROR: temporary value dropped while borrowed
15+
//~| ERROR: temporary value dropped while borrowed
16+
}

src/test/ui/consts/promoted_const_call.stderr

+21-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ LL | let _: &'static _ = &id(&Panic);
1818
| | creates a temporary value which is freed while still in use
1919
| type annotation requires that borrow lasts for `'static`
2020

21-
error: aborting due to 2 previous errors
21+
error[E0716]: temporary value dropped while borrowed
22+
--> $DIR/promoted_const_call.rs:13:26
23+
|
24+
LL | let _: &'static _ = &id(&Panic);
25+
| ---------- ^^^^^^^^^^ creates a temporary value which is freed while still in use
26+
| |
27+
| type annotation requires that borrow lasts for `'static`
28+
...
29+
LL | }
30+
| - temporary value is freed at the end of this statement
31+
32+
error[E0716]: temporary value dropped while borrowed
33+
--> $DIR/promoted_const_call.rs:13:30
34+
|
35+
LL | let _: &'static _ = &id(&Panic);
36+
| ---------- ^^^^^ - temporary value is freed at the end of this statement
37+
| | |
38+
| | creates a temporary value which is freed while still in use
39+
| type annotation requires that borrow lasts for `'static`
40+
41+
error: aborting due to 4 previous errors
2242

2343
For more information about this error, try `rustc --explain E0716`.

src/test/ui/consts/promoted_const_call2.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ pub const C: () = {
77
//~| ERROR: destructor of `String` cannot be evaluated at compile-time
88
};
99

10-
fn main() {}
10+
fn main() {
11+
let _: &'static _ = &id(&String::new());
12+
//~^ ERROR: temporary value dropped while borrowed
13+
//~| ERROR: temporary value dropped while borrowed
14+
}

src/test/ui/consts/promoted_const_call2.stderr

+21-1
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,33 @@ LL | let _: &'static _ = &id(&String::new());
1818
| | creates a temporary value which is freed while still in use
1919
| type annotation requires that borrow lasts for `'static`
2020

21+
error[E0716]: temporary value dropped while borrowed
22+
--> $DIR/promoted_const_call2.rs:11:26
23+
|
24+
LL | let _: &'static _ = &id(&String::new());
25+
| ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
26+
| |
27+
| type annotation requires that borrow lasts for `'static`
28+
...
29+
LL | }
30+
| - temporary value is freed at the end of this statement
31+
32+
error[E0716]: temporary value dropped while borrowed
33+
--> $DIR/promoted_const_call2.rs:11:30
34+
|
35+
LL | let _: &'static _ = &id(&String::new());
36+
| ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
37+
| | |
38+
| | creates a temporary value which is freed while still in use
39+
| type annotation requires that borrow lasts for `'static`
40+
2141
error[E0493]: destructor of `String` cannot be evaluated at compile-time
2242
--> $DIR/promoted_const_call2.rs:4:30
2343
|
2444
LL | let _: &'static _ = &id(&String::new());
2545
| ^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants
2646

27-
error: aborting due to 3 previous errors
47+
error: aborting due to 5 previous errors
2848

2949
Some errors have detailed explanations: E0493, E0716.
3050
For more information about an error, try `rustc --explain E0493`.

src/test/ui/consts/promoted_const_call3.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@ pub const C: () = {
1313
//~^ ERROR: temporary value dropped while borrowed
1414
};
1515

16-
fn main() {}
16+
fn main() {
17+
let _: &'static _ = &String::new();
18+
//~^ ERROR: temporary value dropped while borrowed
19+
20+
let _: &'static _ = &id(&String::new());
21+
//~^ ERROR: temporary value dropped while borrowed
22+
//~| ERROR: temporary value dropped while borrowed
23+
24+
let _: &'static _ = &std::mem::ManuallyDrop::new(String::new());
25+
//~^ ERROR: temporary value dropped while borrowed
26+
}

src/test/ui/consts/promoted_const_call3.stderr

+43-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,49 @@ LL |
5757
LL | };
5858
| - temporary value is freed at the end of this statement
5959

60-
error: aborting due to 6 previous errors
60+
error[E0716]: temporary value dropped while borrowed
61+
--> $DIR/promoted_const_call3.rs:17:26
62+
|
63+
LL | let _: &'static _ = &String::new();
64+
| ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
65+
| |
66+
| type annotation requires that borrow lasts for `'static`
67+
...
68+
LL | }
69+
| - temporary value is freed at the end of this statement
70+
71+
error[E0716]: temporary value dropped while borrowed
72+
--> $DIR/promoted_const_call3.rs:20:26
73+
|
74+
LL | let _: &'static _ = &id(&String::new());
75+
| ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
76+
| |
77+
| type annotation requires that borrow lasts for `'static`
78+
...
79+
LL | }
80+
| - temporary value is freed at the end of this statement
81+
82+
error[E0716]: temporary value dropped while borrowed
83+
--> $DIR/promoted_const_call3.rs:20:30
84+
|
85+
LL | let _: &'static _ = &id(&String::new());
86+
| ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
87+
| | |
88+
| | creates a temporary value which is freed while still in use
89+
| type annotation requires that borrow lasts for `'static`
90+
91+
error[E0716]: temporary value dropped while borrowed
92+
--> $DIR/promoted_const_call3.rs:24:26
93+
|
94+
LL | let _: &'static _ = &std::mem::ManuallyDrop::new(String::new());
95+
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
96+
| |
97+
| type annotation requires that borrow lasts for `'static`
98+
LL |
99+
LL | }
100+
| - temporary value is freed at the end of this statement
101+
102+
error: aborting due to 10 previous errors
61103

62104
Some errors have detailed explanations: E0493, E0716.
63105
For more information about an error, try `rustc --explain E0493`.

0 commit comments

Comments
 (0)