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 ConstPropLint lint run on promoteds #119432

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions compiler/rustc_mir_transform/src/const_prop_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ impl<'tcx> MirLint<'tcx> for ConstPropLint {
return;
}

// will be evaluated by miri and produce its errors there
if body.source.promoted.is_some() {
return;
}

let def_id = body.source.def_id().expect_local();
let def_kind = tcx.def_kind(def_id);
let is_fn_like = def_kind.is_fn_like();
Expand Down
7 changes: 6 additions & 1 deletion src/tools/miri/tests/pass/overflow_checks_off.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
//@compile-flags: -C overflow-checks=off

// Check that we correctly implement the intended behavior of these operators
// when they are not being overflow-checked.
// when they are not being overflow-checked at runtime.

// FIXME: if we call the functions in `std::ops`, we still get the panics.
// Miri does not implement the codegen-time hack that backs `#[rustc_inherit_overflow_checks]`.
// use std::ops::*;


// Disable _compile-time_ overflow linting
// so that we can test runtime overflow checks
#![allow(arithmetic_overflow)]

fn main() {
assert_eq!(-{ -0x80i8 }, -0x80);

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-consts/defaults-cyclic-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ note: ...which requires const-evaluating + checking `Tr::B`...
LL | const B: u8 = Self::A;
| ^^^^^^^
= note: ...which again requires simplifying constant for the type system `Tr::A`, completing the cycle
note: cycle used when const-evaluating + checking `main::promoted[1]`
note: cycle used when optimizing promoted MIR for `main`
--> $DIR/defaults-cyclic-fail.rs:16:16
|
LL | assert_eq!(<() as Tr>::A, 0);
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/associated-consts/defaults-not-assumed-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ note: erroneous constant encountered
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
| ^^^^^^^^^^^^^

note: erroneous constant encountered
--> $DIR/defaults-not-assumed-fail.rs:33:16
|
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
| ^^^^^^^^^^^^^
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

note: erroneous constant encountered
--> $DIR/defaults-not-assumed-fail.rs:33:5
|
Expand Down
48 changes: 0 additions & 48 deletions tests/ui/consts/const-err2.noopt.stderr

This file was deleted.

48 changes: 0 additions & 48 deletions tests/ui/consts/const-err2.opt.stderr

This file was deleted.

48 changes: 0 additions & 48 deletions tests/ui/consts/const-err2.opt_with_overflow_checks.stderr

This file was deleted.

39 changes: 0 additions & 39 deletions tests/ui/consts/const-err2.rs

This file was deleted.

8 changes: 8 additions & 0 deletions tests/ui/consts/const-eval/issue-44578.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ note: erroneous constant encountered
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

note: erroneous constant encountered
--> $DIR/issue-44578.rs:25:20
|
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

note: erroneous constant encountered
--> $DIR/issue-44578.rs:25:20
|
Expand Down
1 change: 1 addition & 0 deletions tests/ui/consts/const-eval/issue-50814.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct Sum<A, B>(A, B);
impl<A: Unsigned, B: Unsigned> Unsigned for Sum<A, B> {
const MAX: u8 = A::MAX + B::MAX;
//~^ ERROR evaluation of `<Sum<U8, U8> as Unsigned>::MAX` failed
//~| ERROR evaluation of `<Sum<U8, U8> as Unsigned>::MAX` failed
}

fn foo<T>(_: T) -> &'static u8 {
Expand Down
22 changes: 19 additions & 3 deletions tests/ui/consts/const-eval/issue-50814.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,33 @@ LL | const MAX: u8 = A::MAX + B::MAX;
| ^^^^^^^^^^^^^^^ attempt to compute `u8::MAX + u8::MAX`, which would overflow

note: erroneous constant encountered
--> $DIR/issue-50814.rs:20:6
--> $DIR/issue-50814.rs:21:6
|
LL | &Sum::<U8, U8>::MAX
| ^^^^^^^^^^^^^^^^^^

error[E0080]: evaluation of `<Sum<U8, U8> as Unsigned>::MAX` failed
--> $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: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

note: erroneous constant encountered
--> $DIR/issue-50814.rs:21:6
|
LL | &Sum::<U8, U8>::MAX
| ^^^^^^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

note: the above error was encountered while instantiating `fn foo::<i32>`
--> $DIR/issue-50814.rs:25:5
--> $DIR/issue-50814.rs:26:5
|
LL | foo(0);
| ^^^^^^

error: aborting due to 1 previous error
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0080`.
Loading
Loading