Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure that promoteds which fail to evaluate in dead const code behave correctly #80696

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/test/ui/consts/promotion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@

fn foo(_: &'static [&'static str]) {}
fn bar(_: &'static [&'static str; 3]) {}
fn baz_i32(_: &'static i32) {}
fn baz_u32(_: &'static u32) {}
const fn baz_i32(_: &'static i32) {}
const fn baz_u32(_: &'static u32) {}

const fn fail() -> i32 { 1/0 }
const C: i32 = {
// Promoted that fails to evaluate in dead code -- this must work
// (for backwards compatibility reasons).
if false {
baz_i32(&fail());
}
42
};

fn main() {
foo(&["a", "b", "c"]);
bar(&["d", "e", "f"]);
assert_eq!(C, 42);

// make sure that these do not cause trouble despite overflowing
baz_u32(&(0-1));
Expand Down