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 to run all mir analyses in check mode #108730

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 9 additions & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,15 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
return Err(reported);
}

// FIXME: move this before the `sess.has_errors()` above or just remove the early abort,
// it is causing too much confusion
sess.time("MIR_effect_checking2", || {
for def_id in tcx.hir().body_owners() {
tcx.ensure()
.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(def_id));
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty similar to the existing MIR_effect_checking above. Please add comments explaining why there are two of these blocks and what each of them is doing.


sess.time("misc_checking_3", || {
parallel!(
{
Expand Down
22 changes: 9 additions & 13 deletions src/doc/rustc/src/lints/levels.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,24 @@ level is capped via cap-lints.
## deny

A 'deny' lint produces an error if you violate it. For example, this code
runs into the `exceeding_bitshifts` lint.
runs into the `arithmetic_overflow` lint.

```rust,no_run
#![warn(arithmetic_overflow)]
fn main() {
100u8 << 10;
}
```

```bash
$ rustc main.rs
error: bitshift exceeds the type's number of bits
error: this arithmetic operation will overflow
--> main.rs:2:13
|
2 | 100u8 << 10;
| ^^^^^^^^^^^
| ^^^^^^^^^^^ attempt to shift left by `10_i32`, which would overflow
|
= note: `#[deny(exceeding_bitshifts)]` on by default
= note: `#[deny(arithmetic_overflow)]` on by default
```

What's the difference between an error from a lint and a regular old error?
Expand Down Expand Up @@ -247,6 +248,7 @@ This is the maximum level for all lints. So for example, if we take our
code sample from the "deny" lint level above:

```rust,no_run
##![allow(arithmetic_overflow)]
fn main() {
100u8 << 10;
}
Expand All @@ -256,19 +258,13 @@ And we compile it, capping lints to warn:

```bash
$ rustc lib.rs --cap-lints warn
warning: bitshift exceeds the type's number of bits
warning: this arithmetic operation will overflow
--> lib.rs:2:5
|
2 | 100u8 << 10;
| ^^^^^^^^^^^
| ^^^^^^^^^^^ attempt to shift left by `10_i32`, which would overflow
|
= note: `#[warn(exceeding_bitshifts)]` on by default

warning: this expression will panic at run-time
--> lib.rs:2:5
|
2 | 100u8 << 10;
| ^^^^^^^^^^^ attempt to shift left with overflow
= note: `#[warn(arithmetic_overflow)]` on by default
```

It now only warns, rather than errors. We can go further and allow all lints:
Expand Down
24 changes: 12 additions & 12 deletions src/tools/clippy/tests/ui/indexing_slicing_index.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
error[E0080]: evaluation of `main::{constant#3}` failed
--> $DIR/indexing_slicing_index.rs:31:14
|
LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4

note: erroneous constant used
--> $DIR/indexing_slicing_index.rs:31:5
|
LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
| ^^^^^^^^^^^^^^^^^^^^^^

error: indexing may panic
--> $DIR/indexing_slicing_index.rs:9:20
|
Expand All @@ -17,18 +29,6 @@ LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
= help: consider using `.get(n)` or `.get_mut(n)` instead
= note: the suggestion might not be applicable in constant blocks

error[E0080]: evaluation of `main::{constant#3}` failed
--> $DIR/indexing_slicing_index.rs:31:14
|
LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4

note: erroneous constant used
--> $DIR/indexing_slicing_index.rs:31:5
|
LL | const { &ARR[idx4()] }; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
| ^^^^^^^^^^^^^^^^^^^^^^

error: indexing may panic
--> $DIR/indexing_slicing_index.rs:22:5
|
Expand Down
6 changes: 6 additions & 0 deletions src/tools/miri/tests/fail/const-ub-checks.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ error[E0080]: evaluation of constant value failed
LL | ptr.read();
| ^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required

note: erroneous constant used
--> $DIR/const-ub-checks.rs:LL:CC
|
LL | let _x = UNALIGNED_READ;
| ^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
14 changes: 14 additions & 0 deletions src/tools/miri/tests/fail/erroneous_const2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ error[E0080]: evaluation of constant value failed
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
| ^^^^^ attempt to compute `5_u32 - 6_u32`, which would overflow

note: erroneous constant used
--> $DIR/erroneous_const2.rs:LL:CC
|
LL | println!("{}", FOO);
| ^^^

note: erroneous constant used
--> $DIR/erroneous_const2.rs:LL:CC
|
LL | println!("{}", FOO);
| ^^^
|
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
5 changes: 0 additions & 5 deletions src/tools/miri/tests/pass/track-alloc-1.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion src/tools/tidy/src/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
const ENTRY_LIMIT: usize = 1000;
// FIXME: The following limits should be reduced eventually.
const ROOT_ENTRY_LIMIT: usize = 940;
const ISSUES_ENTRY_LIMIT: usize = 1978;
const ISSUES_ENTRY_LIMIT: usize = 1979;

fn check_entries(tests_path: &Path, bad: &mut bool) {
let mut directories: HashMap<PathBuf, usize> = HashMap::new();
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/array-slice-vec/array_const_index-0.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ error[E0080]: evaluation of constant value failed
LL | const B: i32 = (&A)[1];
| ^^^^^^^ index out of bounds: the length is 0 but the index is 1

note: erroneous constant used
--> $DIR/array_const_index-0.rs:7:13
|
LL | let _ = B;
| ^

note: erroneous constant used
--> $DIR/array_const_index-0.rs:7:13
|
LL | let _ = B;
| ^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
12 changes: 12 additions & 0 deletions tests/ui/array-slice-vec/array_const_index-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ error[E0080]: evaluation of constant value failed
LL | const B: i32 = A[1];
| ^^^^ index out of bounds: the length is 0 but the index is 1

note: erroneous constant used
--> $DIR/array_const_index-1.rs:7:13
|
LL | let _ = B;
| ^

note: erroneous constant used
--> $DIR/array_const_index-1.rs:7:13
|
LL | let _ = B;
| ^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
2 changes: 0 additions & 2 deletions tests/ui/associated-consts/defaults-cyclic-fail.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// build-fail

// Cyclic assoc. const defaults don't error unless *used*
trait Tr {
const A: u8 = Self::B;
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/associated-consts/defaults-cyclic-fail.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0391]: cycle detected when const-evaluating + checking `Tr::A`
--> $DIR/defaults-cyclic-fail.rs:5:19
--> $DIR/defaults-cyclic-fail.rs:3:19
|
LL | const A: u8 = Self::B;
| ^^^^^^^
|
note: ...which requires const-evaluating + checking `Tr::B`...
--> $DIR/defaults-cyclic-fail.rs:8:19
--> $DIR/defaults-cyclic-fail.rs:6:19
|
LL | const B: u8 = Self::A;
| ^^^^^^^
= note: ...which again requires const-evaluating + checking `Tr::A`, completing the cycle
note: cycle used when const-evaluating + checking `main::promoted[1]`
--> $DIR/defaults-cyclic-fail.rs:16:16
--> $DIR/defaults-cyclic-fail.rs:14:16
|
LL | assert_eq!(<() as Tr>::A, 0);
| ^^^^^^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/associated-consts/defaults-not-assumed-fail.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// build-fail

trait Tr {
const A: u8 = 255;

Expand Down
16 changes: 4 additions & 12 deletions tests/ui/associated-consts/defaults-not-assumed-fail.stderr
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
error[E0080]: evaluation of `<() as Tr>::B` failed
--> $DIR/defaults-not-assumed-fail.rs:8:19
--> $DIR/defaults-not-assumed-fail.rs:6:19
|
LL | const B: u8 = Self::A + 1;
| ^^^^^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow

note: erroneous constant used
--> $DIR/defaults-not-assumed-fail.rs:33:16
--> $DIR/defaults-not-assumed-fail.rs:31:16
|
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
| ^^^^^^^^^^^^^

note: erroneous constant used
--> $DIR/defaults-not-assumed-fail.rs:33:5
--> $DIR/defaults-not-assumed-fail.rs:31:5
|
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant used
--> $DIR/defaults-not-assumed-fail.rs:33:5
|
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant used
--> $DIR/defaults-not-assumed-fail.rs:33:5
--> $DIR/defaults-not-assumed-fail.rs:31:5
|
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-36082.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::cell::RefCell;
fn main() {
let mut r = 0;
let s = 0;
let x = RefCell::new((&mut r,s));
let x = RefCell::new((&mut r, s));

let binding = x.borrow();
let val: &_ = binding.0;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-36082.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::cell::RefCell;
fn main() {
let mut r = 0;
let s = 0;
let x = RefCell::new((&mut r,s));
let x = RefCell::new((&mut r, s));

let val: &_ = x.borrow().0;
//~^ ERROR temporary value dropped while borrowed [E0716]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/issues/issue-100313.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
--> $DIR/issue-100313.rs:10:13
|
LL | *(B as *const bool as *mut bool) = false;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ writing to alloc7 which is read-only
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ writing to alloc8 which is read-only
|
note: inside `T::<&true>::set_false`
--> $DIR/issue-100313.rs:10:13
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/const-ptr/out_of_bounds_read.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
= note: dereferencing pointer failed: alloc5 has size 4, so pointer to 4 bytes starting at offset 4 is out-of-bounds
= note: dereferencing pointer failed: alloc6 has size 4, so pointer to 4 bytes starting at offset 4 is out-of-bounds
|
note: inside `std::ptr::read::<u32>`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
Expand All @@ -14,7 +14,7 @@ LL | const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) };
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
= note: dereferencing pointer failed: alloc5 has size 4, so pointer to 4 bytes starting at offset 4 is out-of-bounds
= note: dereferencing pointer failed: alloc6 has size 4, so pointer to 4 bytes starting at offset 4 is out-of-bounds
|
note: inside `std::ptr::read::<u32>`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
Expand All @@ -29,7 +29,7 @@ LL | const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() };
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
= note: dereferencing pointer failed: alloc5 has size 4, so pointer to 4 bytes starting at offset 4 is out-of-bounds
= note: dereferencing pointer failed: alloc6 has size 4, so pointer to 4 bytes starting at offset 4 is out-of-bounds
|
note: inside `std::ptr::read::<u32>`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
Expand Down
1 change: 1 addition & 0 deletions tests/ui/consts/const-err-early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ fn main() {
let _d = D;
let _e = E;
let _e = [6u8][1];
//~^ ERROR: this operation will panic at runtime
}
Loading