Skip to content

Commit b806b91

Browse files
committed
Auto merge of #119432 - gurry:117949-make-lint-run-on-promoteds, r=oli-obk
Make `ConstPropLint` lint run on promoteds Fixes #117949 wherein the lint didn't fire for the following promoteds: - SHL or SHR operators in a non-optimized build - any arithmetic operator in an optimized build What I have done here is simply enabled `ConstPropLint` to run on promoted bodies by removing the relevant `if` check. After this change _all_ promoted arithmetic operators will lint _in both non-optimized and optimized builds_. On the flip side programs containing the above mentioned overflowing promoteds that were accepted earlier will now be rejected. Hope that is okay from a backward compatibility standpoint. I have added tests covering all overflowing promoted & non-promoted ops for both compile-time and runtime operations and for optimized as well as non-optimized builds. I had to amend some existing tests to make them pass and had to delete a couple that were set to pass despite overflows. This PR increases the number of duplicate diagnostics emitted (because the same operator might get linted in both the promoted MIR and the main MIR). I hope that is an acceptable trade-off given that we now lint overflows much more comprehensively than earlier.
2 parents efa8c32 + 5b1a186 commit b806b91

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tests/pass/overflow_checks_off.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
//@compile-flags: -C overflow-checks=off
22

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

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

10+
11+
// Disable _compile-time_ overflow linting
12+
// so that we can test runtime overflow checks
13+
#![allow(arithmetic_overflow)]
14+
1015
fn main() {
1116
assert_eq!(-{ -0x80i8 }, -0x80);
1217

0 commit comments

Comments
 (0)