diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/consts/promote-not.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/consts/promote-not.stderr | 12 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/test/ui/consts/promote-not.rs b/src/test/ui/consts/promote-not.rs index 8daac758377..30bb9917bf7 100644 --- a/src/test/ui/consts/promote-not.rs +++ b/src/test/ui/consts/promote-not.rs @@ -27,4 +27,9 @@ pub const fn promote_union() { let _x: &'static i32 = &unsafe { U { x: 0 }.x }; //~ ERROR temporary value dropped while borrowed } +// We do not promote union field accesses in `const`, either. +const TEST_UNION: () = { + let _x: &'static i32 = &unsafe { U { x: 0 }.x }; //~ ERROR temporary value dropped while borrowed +}; + fn main() {} diff --git a/src/test/ui/consts/promote-not.stderr b/src/test/ui/consts/promote-not.stderr index efe921b6011..6ca7a4c273e 100644 --- a/src/test/ui/consts/promote-not.stderr +++ b/src/test/ui/consts/promote-not.stderr @@ -38,6 +38,16 @@ LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x }; LL | } | - temporary value is freed at the end of this statement -error: aborting due to 4 previous errors +error[E0716]: temporary value dropped while borrowed + --> $DIR/promote-not.rs:32:29 + | +LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x }; + | ------------ ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +LL | }; + | - temporary value is freed at the end of this statement + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0716`. |
