diff options
| author | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2019-11-06 07:09:16 -0800 |
|---|---|---|
| committer | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2019-11-06 07:09:16 -0800 |
| commit | ec5ba54ed2f0db8dae06f0f89b183bbfd0306238 (patch) | |
| tree | fbcb4ec6fd630e404cb2023d34fffcccaec77135 | |
| parent | a9b1abe6ea96f77ea7fc1761b3cd39c309eb7fcd (diff) | |
| download | rust-ec5ba54ed2f0db8dae06f0f89b183bbfd0306238.tar.gz rust-ec5ba54ed2f0db8dae06f0f89b183bbfd0306238.zip | |
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.
| -rw-r--r-- | src/test/ui/consts/const_let_promote.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/ui/consts/const_let_promote.rs b/src/test/ui/consts/const_let_promote.rs new file mode 100644 index 00000000000..f4661e9e425 --- /dev/null +++ b/src/test/ui/consts/const_let_promote.rs @@ -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; +} |
