From ddc74d352459c63f27a8b52edc83d34b4a7dc281 Mon Sep 17 00:00:00 2001 From: b-naber Date: Thu, 23 Jun 2022 16:45:17 +0200 Subject: [PATCH 1/5] always evaluate constant operands in const-prop --- .../rustc_mir_transform/src/const_prop.rs | 5 ---- src/test/ui/consts/const-eval/issue-50814.rs | 3 +++ .../ui/consts/const-eval/issue-50814.stderr | 23 ++++++++++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 85ad6b8f2feff..d3f9c5493aace 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -468,11 +468,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { /// Returns the value, if any, of evaluating `c`. fn eval_constant(&mut self, c: &Constant<'tcx>) -> Option> { - // FIXME we need to revisit this for #67176 - if c.needs_subst() { - return None; - } - self.ecx.mir_const_to_op(&c.literal, None).ok() } diff --git a/src/test/ui/consts/const-eval/issue-50814.rs b/src/test/ui/consts/const-eval/issue-50814.rs index 98229f919dd13..56091045916fb 100644 --- a/src/test/ui/consts/const-eval/issue-50814.rs +++ b/src/test/ui/consts/const-eval/issue-50814.rs @@ -14,12 +14,15 @@ struct Sum(A,B); impl Unsigned for Sum { const MAX: u8 = A::MAX + B::MAX; //~^ ERROR any use of this value will cause an error [const_err] + //~| ERROR any use of this value will cause an error //~| WARN this was previously accepted by the compiler but is being phased out + //~| WARNING this was previously accepted by the compiler } fn foo(_: T) -> &'static u8 { &Sum::::MAX //~^ ERROR E0080 + //~| ERROR evaluation of `foo::` failed } fn main() { diff --git a/src/test/ui/consts/const-eval/issue-50814.stderr b/src/test/ui/consts/const-eval/issue-50814.stderr index 6ceef91a042aa..8d0c0ea9bac82 100644 --- a/src/test/ui/consts/const-eval/issue-50814.stderr +++ b/src/test/ui/consts/const-eval/issue-50814.stderr @@ -8,19 +8,36 @@ LL | const MAX: u8 = A::MAX + B::MAX; = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 +error[E0080]: evaluation of `foo::` failed + --> $DIR/issue-50814.rs:23:6 + | +LL | &Sum::::MAX + | ^^^^^^^^^^^^^^^^^ referenced constant has errors + +error: any use of this value will cause an error + --> $DIR/issue-50814.rs:15:21 + | +LL | const MAX: u8 = A::MAX + B::MAX; + | ----------------^^^^^^^^^^^^^^^- + | | + | attempt to compute `u8::MAX + u8::MAX`, which would overflow + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #71800 + error[E0080]: evaluation of `foo::` failed - --> $DIR/issue-50814.rs:21:6 + --> $DIR/issue-50814.rs:23:6 | LL | &Sum::::MAX | ^^^^^^^^^^^^^^^^^ referenced constant has errors note: the above error was encountered while instantiating `fn foo::` - --> $DIR/issue-50814.rs:26:5 + --> $DIR/issue-50814.rs:29:5 | LL | foo(0); | ^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0080`. Future incompatibility report: Future breakage diagnostic: From 9704893bcfb079f99b0d1289fe93034fb63a1b95 Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 24 Jun 2022 13:23:20 +0200 Subject: [PATCH 2/5] fix nit --- src/test/ui/consts/const-eval/issue-50814.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/consts/const-eval/issue-50814.rs b/src/test/ui/consts/const-eval/issue-50814.rs index 56091045916fb..5554d7dc3edce 100644 --- a/src/test/ui/consts/const-eval/issue-50814.rs +++ b/src/test/ui/consts/const-eval/issue-50814.rs @@ -16,7 +16,7 @@ impl Unsigned for Sum { //~^ ERROR any use of this value will cause an error [const_err] //~| ERROR any use of this value will cause an error //~| WARN this was previously accepted by the compiler but is being phased out - //~| WARNING this was previously accepted by the compiler + //~| WARN this was previously accepted by the compiler but is being phased out } fn foo(_: T) -> &'static u8 { From d10dccf65a70b0a6c9f31bc886120cb43f6dd813 Mon Sep 17 00:00:00 2001 From: b-naber Date: Thu, 4 Aug 2022 10:10:07 +0200 Subject: [PATCH 3/5] ci --- .github/workflows/ci.yml | 3 +++ src/ci/github-actions/ci.yml | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5410613548c05..ce841cdbad78b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,9 @@ jobs: - name: x86_64-gnu-llvm-12 os: ubuntu-20.04-xl env: {} + - name: dist-i586-gnu-i586-i686-musl + os: ubuntu-20.04-xl + env: {} - name: x86_64-gnu-tools env: CI_ONLY_WHEN_SUBMODULES_CHANGED: 1 diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 3ad4e3f97a3bc..9d2f0d60c6c6b 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -286,7 +286,10 @@ jobs: - name: x86_64-gnu-llvm-12 <<: *job-linux-xl - + + - name: dist-i586-gnu-i586-i686-musl + <<: *job-linux-xl + - name: x86_64-gnu-tools env: CI_ONLY_WHEN_SUBMODULES_CHANGED: 1 From 5726ed77123634caaf16dca426e8a57ff2fd2ac2 Mon Sep 17 00:00:00 2001 From: b-naber Date: Thu, 4 Aug 2022 10:10:16 +0200 Subject: [PATCH 4/5] same thing in const-prop-lint --- compiler/rustc_mir_transform/src/const_prop_lint.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 3ae6a88a140ea..ecc437dd67059 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -514,11 +514,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { | Rvalue::NullaryOp(..) => {} } - // FIXME we need to revisit this for #67176 - if rvalue.needs_subst() { - return None; - } - self.use_ecx(source_info, |this| this.ecx.eval_rvalue_into_place(rvalue, place)) } } From 4e43e3a698b3e94507251199e2f26919a1dceda5 Mon Sep 17 00:00:00 2001 From: b-naber Date: Thu, 4 Aug 2022 11:51:22 +0200 Subject: [PATCH 5/5] bless tests --- .../ui/consts/const-eval/erroneous-const.rs | 2 ++ .../consts/const-eval/erroneous-const.stderr | 32 ++++++++++++++++--- .../ui/consts/const-eval/issue-50814.stderr | 15 +++++++-- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/test/ui/consts/const-eval/erroneous-const.rs b/src/test/ui/consts/const-eval/erroneous-const.rs index bee5a7cb3ba72..65bfe7cc0eca5 100644 --- a/src/test/ui/consts/const-eval/erroneous-const.rs +++ b/src/test/ui/consts/const-eval/erroneous-const.rs @@ -6,6 +6,8 @@ impl PrintName { const VOID: () = [()][2]; //~WARN any use of this value will cause an error //~^ WARN this operation will panic at runtime //~| WARN this was previously accepted by the compiler but is being phased out + //~| WARN this was previously accepted by the compiler but is being phased out + //~| WARN any use of this value will cause an error } const fn no_codegen() { diff --git a/src/test/ui/consts/const-eval/erroneous-const.stderr b/src/test/ui/consts/const-eval/erroneous-const.stderr index adfb4cc61cc62..e9539507fb5a2 100644 --- a/src/test/ui/consts/const-eval/erroneous-const.stderr +++ b/src/test/ui/consts/const-eval/erroneous-const.stderr @@ -24,19 +24,28 @@ LL | #![warn(const_err, unconditional_panic)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 +warning: any use of this value will cause an error + --> $DIR/erroneous-const.rs:6:22 + | +LL | const VOID: () = [()][2]; + | -------------- ^^^^^^^ index out of bounds: the length is 1 but the index is 2 + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #71800 + error[E0080]: could not evaluate static initializer - --> $DIR/erroneous-const.rs:15:17 + --> $DIR/erroneous-const.rs:17:17 | LL | let _ = PrintName::::VOID; | ^^^^^^^^^^^^^^^^^^^^ | | | referenced constant has errors - | inside `no_codegen::` at $DIR/erroneous-const.rs:15:17 + | inside `no_codegen::` at $DIR/erroneous-const.rs:17:17 ... LL | pub static FOO: () = no_codegen::(); - | ------------------- inside `FOO` at $DIR/erroneous-const.rs:19:22 + | ------------------- inside `FOO` at $DIR/erroneous-const.rs:21:22 -error: aborting due to previous error; 2 warnings emitted +error: aborting due to previous error; 3 warnings emitted For more information about this error, try `rustc --explain E0080`. Future incompatibility report: Future breakage diagnostic: @@ -54,3 +63,18 @@ LL | #![warn(const_err, unconditional_panic)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 +Future breakage diagnostic: +warning: any use of this value will cause an error + --> $DIR/erroneous-const.rs:6:22 + | +LL | const VOID: () = [()][2]; + | -------------- ^^^^^^^ index out of bounds: the length is 1 but the index is 2 + | +note: the lint level is defined here + --> $DIR/erroneous-const.rs:2:9 + | +LL | #![warn(const_err, unconditional_panic)] + | ^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #71800 + diff --git a/src/test/ui/consts/const-eval/issue-50814.stderr b/src/test/ui/consts/const-eval/issue-50814.stderr index 8d0c0ea9bac82..bd92bf484d8e5 100644 --- a/src/test/ui/consts/const-eval/issue-50814.stderr +++ b/src/test/ui/consts/const-eval/issue-50814.stderr @@ -18,9 +18,7 @@ error: any use of this value will cause an error --> $DIR/issue-50814.rs:15:21 | LL | const MAX: u8 = A::MAX + B::MAX; - | ----------------^^^^^^^^^^^^^^^- - | | - | attempt to compute `u8::MAX + u8::MAX`, which would overflow + | ------------- ^^^^^^^^^^^^^^^ attempt to compute `u8::MAX + u8::MAX`, which would overflow | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 @@ -51,3 +49,14 @@ LL | const MAX: u8 = A::MAX + B::MAX; = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 +Future breakage diagnostic: +error: any use of this value will cause an error + --> $DIR/issue-50814.rs:15:21 + | +LL | const MAX: u8 = A::MAX + B::MAX; + | ------------- ^^^^^^^^^^^^^^^ attempt to compute `u8::MAX + u8::MAX`, which would overflow + | + = note: `#[deny(const_err)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #71800 +