Add test for promotability in let
The old const-checker conservatively reset qualifs when `IsNotPromotable` was in the return place. Unfortunately, named variables have `IsNotPromotable`, so this could cause promotion to fail. This should work now.
This commit is contained in:
parent
a9b1abe6ea
commit
ec5ba54ed2
1 changed files with 17 additions and 0 deletions
17
src/test/ui/consts/const_let_promote.rs
Normal file
17
src/test/ui/consts/const_let_promote.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// run-pass
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
const X: Option<Cell<i32>> = None;
|
||||
|
||||
const Y: Option<Cell<i32>> = {
|
||||
let x = None;
|
||||
x
|
||||
};
|
||||
|
||||
// Ensure that binding the final value of a `const` to a variable does not affect promotion.
|
||||
#[allow(unused)]
|
||||
fn main() {
|
||||
let x: &'static _ = &X;
|
||||
let y: &'static _ = &Y;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue