Skip to content

Commit

Permalink
Add test for promotability in let
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ecstatic-morse committed Nov 6, 2019
1 parent a9b1abe commit ec5ba54
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/test/ui/consts/const_let_promote.rs
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit ec5ba54

Please sign in to comment.