diff options
| author | bors <bors@rust-lang.org> | 2022-02-12 05:19:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-02-12 05:19:33 +0000 |
| commit | 9cdefd763b910ffd1d42233a8c752ab5fd84ca4d (patch) | |
| tree | 5609a6af2043d0103323f5b77e32fcb286a4dd18 /src/test/ui/consts | |
| parent | fc323035ac49b8d834fc2a0f580af8fd45e90b30 (diff) | |
| parent | 67ad0ffdf8a979535eac7da6bec8626a87fb2843 (diff) | |
| download | rust-9cdefd763b910ffd1d42233a8c752ab5fd84ca4d.tar.gz rust-9cdefd763b910ffd1d42233a8c752ab5fd84ca4d.zip | |
Auto merge of #93691 - compiler-errors:mir-tainted-by-errors, r=oli-obk
Implement `tainted_by_errors` in MIR borrowck, use it to skip CTFE Putting this up for initial review. The issue that I found is when we're evaluating a const, we're doing borrowck, but doing nothing with the fact that borrowck fails. This implements a `tainted_by_errors` field for MIR borrowck like we have in infcx, so we can use that information to return an `Err` during const eval if our const fails to borrowck. This PR needs some cleaning up. I should probably just use `Result` in more places, instead of `.expect`ing in the places I am, but I just wanted it to compile so I could see if it worked! Fixes #93646 r? `@oli-obk` feel free to reassign
Diffstat (limited to 'src/test/ui/consts')
| -rw-r--r-- | src/test/ui/consts/const-fn-error.rs | 1 | ||||
| -rw-r--r-- | src/test/ui/consts/const-fn-error.stderr | 18 | ||||
| -rw-r--r-- | src/test/ui/consts/const-mut-refs/issue-76510.32bit.stderr | 17 | ||||
| -rw-r--r-- | src/test/ui/consts/const-mut-refs/issue-76510.64bit.stderr | 17 | ||||
| -rw-r--r-- | src/test/ui/consts/const-mut-refs/issue-76510.rs | 1 | ||||
| -rw-r--r-- | src/test/ui/consts/issue-78655.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/consts/issue-78655.stderr | 11 |
7 files changed, 11 insertions, 56 deletions
diff --git a/src/test/ui/consts/const-fn-error.rs b/src/test/ui/consts/const-fn-error.rs index 948c162e894..065944ea7ea 100644 --- a/src/test/ui/consts/const-fn-error.rs +++ b/src/test/ui/consts/const-fn-error.rs @@ -6,7 +6,6 @@ const fn f(x: usize) -> usize { //~^ ERROR mutable references //~| ERROR calls in constant functions //~| ERROR calls in constant functions - //~| ERROR E0080 //~| ERROR `for` is not allowed in a `const fn` sum += i; } diff --git a/src/test/ui/consts/const-fn-error.stderr b/src/test/ui/consts/const-fn-error.stderr index df24585e555..e4b62f20a33 100644 --- a/src/test/ui/consts/const-fn-error.stderr +++ b/src/test/ui/consts/const-fn-error.stderr @@ -5,7 +5,7 @@ LL | / for i in 0..x { LL | | LL | | LL | | -... | +LL | | LL | | sum += i; LL | | } | |_____^ @@ -34,19 +34,7 @@ error[E0015]: calls in constant functions are limited to constant functions, tup LL | for i in 0..x { | ^^^^ -error[E0080]: evaluation of constant value failed - --> $DIR/const-fn-error.rs:5:14 - | -LL | for i in 0..x { - | ^^^^ - | | - | calling non-const function `<std::ops::Range<usize> as IntoIterator>::into_iter` - | inside `f` at $DIR/const-fn-error.rs:5:14 -... -LL | let a : [i32; f(X)]; - | ---- inside `main::{constant#0}` at $DIR/const-fn-error.rs:18:19 - -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0015, E0080, E0658. +Some errors have detailed explanations: E0015, E0658. For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/consts/const-mut-refs/issue-76510.32bit.stderr b/src/test/ui/consts/const-mut-refs/issue-76510.32bit.stderr index a9411fb0e3d..61b00be345f 100644 --- a/src/test/ui/consts/const-mut-refs/issue-76510.32bit.stderr +++ b/src/test/ui/consts/const-mut-refs/issue-76510.32bit.stderr @@ -19,18 +19,7 @@ error[E0596]: cannot borrow data in a `&` reference as mutable LL | const S: &'static mut str = &mut " hello "; | ^^^^^^^^^^^^^^ cannot borrow as mutable -error[E0080]: it is undefined behavior to use this value - --> $DIR/issue-76510.rs:5:1 - | -LL | const S: &'static mut str = &mut " hello "; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered mutable reference in a `const` - | - = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. - = note: the raw bytes of the constant (size: 8, align: 4) { - ╾─alloc3──╼ 07 00 00 00 │ ╾──╼.... - } - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0080, E0596, E0658, E0764. -For more information about an error, try `rustc --explain E0080`. +Some errors have detailed explanations: E0596, E0658, E0764. +For more information about an error, try `rustc --explain E0596`. diff --git a/src/test/ui/consts/const-mut-refs/issue-76510.64bit.stderr b/src/test/ui/consts/const-mut-refs/issue-76510.64bit.stderr index 9ad5f20d57c..61b00be345f 100644 --- a/src/test/ui/consts/const-mut-refs/issue-76510.64bit.stderr +++ b/src/test/ui/consts/const-mut-refs/issue-76510.64bit.stderr @@ -19,18 +19,7 @@ error[E0596]: cannot borrow data in a `&` reference as mutable LL | const S: &'static mut str = &mut " hello "; | ^^^^^^^^^^^^^^ cannot borrow as mutable -error[E0080]: it is undefined behavior to use this value - --> $DIR/issue-76510.rs:5:1 - | -LL | const S: &'static mut str = &mut " hello "; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered mutable reference in a `const` - | - = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. - = note: the raw bytes of the constant (size: 16, align: 8) { - ╾───────alloc3────────╼ 07 00 00 00 00 00 00 00 │ ╾──────╼........ - } - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0080, E0596, E0658, E0764. -For more information about an error, try `rustc --explain E0080`. +Some errors have detailed explanations: E0596, E0658, E0764. +For more information about an error, try `rustc --explain E0596`. diff --git a/src/test/ui/consts/const-mut-refs/issue-76510.rs b/src/test/ui/consts/const-mut-refs/issue-76510.rs index 892f6c98116..143d2fb6b9a 100644 --- a/src/test/ui/consts/const-mut-refs/issue-76510.rs +++ b/src/test/ui/consts/const-mut-refs/issue-76510.rs @@ -6,7 +6,6 @@ const S: &'static mut str = &mut " hello "; //~^ ERROR: mutable references are not allowed in the final value of constants //~| ERROR: mutation through a reference is not allowed in constants //~| ERROR: cannot borrow data in a `&` reference as mutable -//~| ERROR: it is undefined behavior to use this value const fn trigger() -> [(); unsafe { let s = transmute::<(*const u8, usize), &ManuallyDrop<str>>((S.as_ptr(), 3)); diff --git a/src/test/ui/consts/issue-78655.rs b/src/test/ui/consts/issue-78655.rs index 066764bc46f..b85e6129925 100644 --- a/src/test/ui/consts/issue-78655.rs +++ b/src/test/ui/consts/issue-78655.rs @@ -1,4 +1,4 @@ -const FOO: *const u32 = { //~ ERROR encountered dangling pointer in final constant +const FOO: *const u32 = { let x; &x //~ ERROR borrow of possibly-uninitialized variable: `x` }; diff --git a/src/test/ui/consts/issue-78655.stderr b/src/test/ui/consts/issue-78655.stderr index cf3fe18f802..734266a3453 100644 --- a/src/test/ui/consts/issue-78655.stderr +++ b/src/test/ui/consts/issue-78655.stderr @@ -4,15 +4,6 @@ error[E0381]: borrow of possibly-uninitialized variable: `x` LL | &x | ^^ use of possibly-uninitialized `x` -error: encountered dangling pointer in final constant - --> $DIR/issue-78655.rs:1:1 - | -LL | / const FOO: *const u32 = { -LL | | let x; -LL | | &x -LL | | }; - | |__^ - error: could not evaluate constant pattern --> $DIR/issue-78655.rs:7:9 | @@ -25,6 +16,6 @@ error: could not evaluate constant pattern LL | let FOO = FOO; | ^^^ -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0381`. |
