From 0c7fd2c6855d9bdb5275537d59f3af525edba330 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 6 Jan 2021 20:11:23 +0100 Subject: [PATCH] expand successful-promotion test a bit --- src/test/ui/consts/promotion.rs | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/test/ui/consts/promotion.rs b/src/test/ui/consts/promotion.rs index e7726dd0a4b5..580c6d62f10a 100644 --- a/src/test/ui/consts/promotion.rs +++ b/src/test/ui/consts/promotion.rs @@ -1,41 +1,43 @@ -// run-pass +// revisions: noopt opt opt_with_overflow_checks +//[noopt]compile-flags: -C opt-level=0 +//[opt]compile-flags: -O +//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O -// compile-flags: -O +// build-pass +#[allow(arithmetic_overflow)] -fn foo(_: &'static [&'static str]) {} -fn bar(_: &'static [&'static str; 3]) {} -const fn baz_i32(_: &'static i32) {} -const fn baz_u32(_: &'static u32) {} +const fn assert_static(_: &'static T) {} 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()); + assert_static(&fail()); } 42 }; fn main() { - foo(&["a", "b", "c"]); - bar(&["d", "e", "f"]); + assert_static(&["a", "b", "c"]); + assert_static(&["d", "e", "f"]); assert_eq!(C, 42); // make sure that these do not cause trouble despite overflowing - baz_u32(&(0-1)); - baz_i32(&-i32::MIN); + assert_static(&(0-1)); + assert_static(&-i32::MIN); // div-by-non-0 is okay - baz_i32(&(1/1)); - baz_i32(&(1%1)); + assert_static(&(1/1)); + assert_static(&(1%1)); // in-bounds array access is okay - baz_i32(&([1,2,3][0] + 1)); + assert_static(&([1,2,3][0] + 1)); + assert_static(&[[1,2][1]]); - // Top-level projections do not get promoted, so no error here. + // Top-level projections are not part of the promoted, so no error here. if false { #[allow(unconditional_panic)] - baz_i32(&[1,2,3][4]); + assert_static(&[1,2,3][4]); } }