]> git.lizzy.rs Git - rust.git/blob - tests/ui/consts/promoted_const_call5.rs
Rollup merge of #106962 - compiler-errors:use-sugg-span, r=oli-obk
[rust.git] / tests / ui / consts / promoted_const_call5.rs
1 #![feature(rustc_attrs)]
2 #![feature(staged_api)]
3 #![stable(feature = "a", since = "1.0.0")]
4
5 #[rustc_promotable]
6 #[stable(feature = "a", since = "1.0.0")]
7 #[rustc_const_stable(feature = "a", since = "1.0.0")]
8 pub const fn id<T>(x: &'static T) -> &'static T { x }
9
10 #[rustc_promotable]
11 #[stable(feature = "a", since = "1.0.0")]
12 #[rustc_const_stable(feature = "a", since = "1.0.0")]
13 pub const fn new_string() -> String {
14     String::new()
15 }
16
17 #[rustc_promotable]
18 #[stable(feature = "a", since = "1.0.0")]
19 #[rustc_const_stable(feature = "a", since = "1.0.0")]
20 pub const fn new_manually_drop<T>(t: T) -> std::mem::ManuallyDrop<T>  {
21     std::mem::ManuallyDrop::new(t)
22 }
23
24
25 const C: () = {
26     let _: &'static _ = &id(&new_string());
27     //~^ ERROR destructor of `String` cannot be evaluated at compile-time
28     //~| ERROR: temporary value dropped while borrowed
29     //~| ERROR: temporary value dropped while borrowed
30
31     let _: &'static _ = &new_manually_drop(new_string());
32     //~^ ERROR: temporary value dropped while borrowed
33 };
34
35 fn main() {
36     let _: &'static _ = &id(&new_string());
37     //~^ ERROR: temporary value dropped while borrowed
38     //~| ERROR: temporary value dropped while borrowed
39
40     let _: &'static _ = &new_manually_drop(new_string());
41     //~^ ERROR: temporary value dropped while borrowed
42 }