Skip to content

Commit

Permalink
ty: convert ErrorHandled::Reported to ConstKind::Error.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Apr 16, 2020
1 parent d7c4081 commit 77f38dc
Show file tree
Hide file tree
Showing 29 changed files with 54 additions and 295 deletions.
9 changes: 7 additions & 2 deletions src/librustc_middle/ty/sty.rs
Expand Up @@ -18,6 +18,7 @@ use crate::ty::{List, ParamEnv, ParamEnvAnd, TyS};
use polonius_engine::Atom;
use rustc_ast::ast::{self, Ident};
use rustc_data_structures::captures::Captures;
use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_index::vec::Idx;
Expand Down Expand Up @@ -2340,6 +2341,8 @@ impl<'tcx> Const<'tcx> {
/// unevaluated constant.
pub fn eval(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> &Const<'tcx> {
if let ConstKind::Unevaluated(did, substs, promoted) = self.val {
use crate::mir::interpret::ErrorHandled;

let param_env_and_substs = param_env.with_reveal_all().and(substs);

// HACK(eddyb) this erases lifetimes even though `const_eval_resolve`
Expand Down Expand Up @@ -2369,8 +2372,10 @@ impl<'tcx> Const<'tcx> {
// (which may be identity substs, see above),
// can leak through `val` into the const we return.
Ok(val) => Const::from_value(tcx, val, self.ty),

Err(_) => self,
Err(ErrorHandled::TooGeneric | ErrorHandled::Linted) => self,
Err(ErrorHandled::Reported(ErrorReported)) => {
tcx.mk_const(ty::Const { val: ty::ConstKind::Error, ty: self.ty })
}
}
} else {
self
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/array-break-length.rs
@@ -1,11 +1,9 @@
fn main() {
loop {
|_: [_; break]| {} //~ ERROR: `break` outside of a loop
//~^ ERROR mismatched types
}

loop {
|_: [_; continue]| {} //~ ERROR: `continue` outside of a loop
//~^ ERROR mismatched types
}
}
25 changes: 3 additions & 22 deletions src/test/ui/array-break-length.stderr
Expand Up @@ -5,30 +5,11 @@ LL | |_: [_; break]| {}
| ^^^^^ cannot `break` outside of a loop

error[E0268]: `continue` outside of a loop
--> $DIR/array-break-length.rs:8:17
--> $DIR/array-break-length.rs:7:17
|
LL | |_: [_; continue]| {}
| ^^^^^^^^ cannot `continue` outside of a loop

error[E0308]: mismatched types
--> $DIR/array-break-length.rs:3:9
|
LL | |_: [_; break]| {}
| ^^^^^^^^^^^^^^^^^^ expected `()`, found closure
|
= note: expected unit type `()`
found closure `[closure@$DIR/array-break-length.rs:3:9: 3:27]`

error[E0308]: mismatched types
--> $DIR/array-break-length.rs:8:9
|
LL | |_: [_; continue]| {}
| ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found closure
|
= note: expected unit type `()`
found closure `[closure@$DIR/array-break-length.rs:8:9: 8:30]`

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

Some errors have detailed explanations: E0268, E0308.
For more information about an error, try `rustc --explain E0268`.
For more information about this error, try `rustc --explain E0268`.
2 changes: 0 additions & 2 deletions src/test/ui/closures/closure-array-break-length.rs
Expand Up @@ -2,8 +2,6 @@ fn main() {
|_: [_; continue]| {}; //~ ERROR: `continue` outside of a loop

while |_: [_; continue]| {} {} //~ ERROR: `continue` outside of a loop
//~^ ERROR mismatched types

while |_: [_; break]| {} {} //~ ERROR: `break` outside of a loop
//~^ ERROR mismatched types
}
25 changes: 3 additions & 22 deletions src/test/ui/closures/closure-array-break-length.stderr
Expand Up @@ -11,30 +11,11 @@ LL | while |_: [_; continue]| {} {}
| ^^^^^^^^ cannot `continue` outside of a loop

error[E0268]: `break` outside of a loop
--> $DIR/closure-array-break-length.rs:7:19
--> $DIR/closure-array-break-length.rs:6:19
|
LL | while |_: [_; break]| {} {}
| ^^^^^ cannot `break` outside of a loop

error[E0308]: mismatched types
--> $DIR/closure-array-break-length.rs:4:11
|
LL | while |_: [_; continue]| {} {}
| ^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found closure
|
= note: expected type `bool`
found closure `[closure@$DIR/closure-array-break-length.rs:4:11: 4:32]`

error[E0308]: mismatched types
--> $DIR/closure-array-break-length.rs:7:11
|
LL | while |_: [_; break]| {} {}
| ^^^^^^^^^^^^^^^^^^ expected `bool`, found closure
|
= note: expected type `bool`
found closure `[closure@$DIR/closure-array-break-length.rs:7:11: 7:29]`

error: aborting due to 5 previous errors
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0268, E0308.
For more information about an error, try `rustc --explain E0268`.
For more information about this error, try `rustc --explain E0268`.
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/const-eval-overflow-3.rs
Expand Up @@ -19,7 +19,6 @@ const A_I8_I
: [u32; (i8::MAX as usize) + 1]
= [0; (i8::MAX + 1) as usize];
//~^ ERROR evaluation of constant value failed
//~| ERROR mismatched types

fn main() {
foo(&A_I8_I[..]);
Expand Down
14 changes: 2 additions & 12 deletions src/test/ui/consts/const-eval/const-eval-overflow-3.stderr
Expand Up @@ -4,16 +4,6 @@ error[E0080]: evaluation of constant value failed
LL | = [0; (i8::MAX + 1) as usize];
| ^^^^^^^^^^^^^ attempt to add with overflow

error[E0308]: mismatched types
--> $DIR/const-eval-overflow-3.rs:20:7
|
LL | = [0; (i8::MAX + 1) as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `128usize`, found `(i8::MAX + 1) as usize`
|
= note: expected array `[u32; 128]`
found array `[u32; _]`

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

Some errors have detailed explanations: E0080, E0308.
For more information about an error, try `rustc --explain E0080`.
For more information about this error, try `rustc --explain E0080`.
1 change: 0 additions & 1 deletion src/test/ui/consts/const-eval/const-eval-overflow-3b.rs
Expand Up @@ -18,7 +18,6 @@ const A_I8_I
= [0; (i8::MAX + 1u8) as usize];
//~^ ERROR mismatched types
//~| ERROR cannot add `u8` to `i8`
//~| ERROR mismatched types

fn main() {
foo(&A_I8_I[..]);
Expand Down
11 changes: 1 addition & 10 deletions src/test/ui/consts/const-eval/const-eval-overflow-3b.stderr
Expand Up @@ -12,16 +12,7 @@ LL | = [0; (i8::MAX + 1u8) as usize];
|
= help: the trait `std::ops::Add<u8>` is not implemented for `i8`

error[E0308]: mismatched types
--> $DIR/const-eval-overflow-3b.rs:18:7
|
LL | = [0; (i8::MAX + 1u8) as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `128usize`, found `(i8::MAX + 1u8) as usize`
|
= note: expected array `[u32; 128]`
found array `[u32; _]`

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

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
2 changes: 1 addition & 1 deletion src/test/ui/consts/const-eval/match-test-ptr-null.rs
Expand Up @@ -2,7 +2,7 @@ fn main() {
// Make sure match uses the usual pointer comparison code path -- i.e., it should complain
// that pointer comparison is disallowed, not that parts of a pointer are accessed as raw
// bytes.
let _: [u8; 0] = [4; { //~ ERROR mismatched types
let _: [u8; 0] = [4; {
match &1 as *const i32 as usize {
//~^ ERROR casting pointers to integers in constants
//~| ERROR `match` is not allowed in a `const`
Expand Down
27 changes: 2 additions & 25 deletions src/test/ui/consts/const-eval/match-test-ptr-null.stderr
Expand Up @@ -28,30 +28,7 @@ error[E0080]: evaluation of constant value failed
LL | match &1 as *const i32 as usize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants

error[E0308]: mismatched types
--> $DIR/match-test-ptr-null.rs:5:22
|
LL | let _: [u8; 0] = [4; {
| ____________-------___^
| | |
| | expected due to this
LL | | match &1 as *const i32 as usize {
LL | |
LL | |
... |
LL | | }
LL | | }];
| |______^ expected `0usize`, found `{
match &1 as *const i32 as usize {
0 => 42,
n => n,
}
}`
|
= note: expected array `[u8; 0]`
found array `[u8; _]`

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0080, E0308, E0658.
Some errors have detailed explanations: E0080, E0658.
For more information about an error, try `rustc --explain E0080`.
10 changes: 0 additions & 10 deletions src/test/ui/consts/const-integer-bool-ops.rs
Expand Up @@ -6,7 +6,6 @@ const X: usize = 42 && 39;
//~| ERROR mismatched types
//~| expected `usize`, found `bool`
const ARR: [i32; X] = [99; 34];
//~^ ERROR evaluation of constant value failed

const X1: usize = 42 || 39;
//~^ ERROR mismatched types
Expand All @@ -16,7 +15,6 @@ const X1: usize = 42 || 39;
//~| ERROR mismatched types
//~| expected `usize`, found `bool`
const ARR1: [i32; X1] = [99; 47];
//~^ ERROR evaluation of constant value failed

const X2: usize = -42 || -39;
//~^ ERROR mismatched types
Expand All @@ -26,7 +24,6 @@ const X2: usize = -42 || -39;
//~| ERROR mismatched types
//~| expected `usize`, found `bool`
const ARR2: [i32; X2] = [99; 18446744073709551607];
//~^ ERROR evaluation of constant value failed

const X3: usize = -42 && -39;
//~^ ERROR mismatched types
Expand All @@ -36,43 +33,36 @@ const X3: usize = -42 && -39;
//~| ERROR mismatched types
//~| expected `usize`, found `bool`
const ARR3: [i32; X3] = [99; 6];
//~^ ERROR evaluation of constant value failed

const Y: usize = 42.0 == 42.0;
//~^ ERROR mismatched types
//~| expected `usize`, found `bool`
const ARRR: [i32; Y] = [99; 1];
//~^ ERROR evaluation of constant value failed

const Y1: usize = 42.0 >= 42.0;
//~^ ERROR mismatched types
//~| expected `usize`, found `bool`
const ARRR1: [i32; Y1] = [99; 1];
//~^ ERROR evaluation of constant value failed

const Y2: usize = 42.0 <= 42.0;
//~^ ERROR mismatched types
//~| expected `usize`, found `bool`
const ARRR2: [i32; Y2] = [99; 1];
//~^ ERROR evaluation of constant value failed

const Y3: usize = 42.0 > 42.0;
//~^ ERROR mismatched types
//~| expected `usize`, found `bool`
const ARRR3: [i32; Y3] = [99; 0];
//~^ ERROR evaluation of constant value failed

const Y4: usize = 42.0 < 42.0;
//~^ ERROR mismatched types
//~| expected `usize`, found `bool`
const ARRR4: [i32; Y4] = [99; 0];
//~^ ERROR evaluation of constant value failed

const Y5: usize = 42.0 != 42.0;
//~^ ERROR mismatched types
//~| expected `usize`, found `bool`
const ARRR5: [i32; Y5] = [99; 0];
//~^ ERROR evaluation of constant value failed

fn main() {
let _ = ARR;
Expand Down

0 comments on commit 77f38dc

Please sign in to comment.