Skip to content

Commit 0f97048

Browse files
committed
Deduplicate all the ~~things~~ errors
1 parent d34232b commit 0f97048

26 files changed

+133
-199
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use rustc::mir;
2323
use rustc::ty::{self, Ty, TyCtxt, Instance, query::TyCtxtAt};
2424
use rustc::ty::layout::{self, Size, LayoutOf, TyLayout};
2525
use rustc::ty::subst::Subst;
26+
use rustc::traits::Reveal;
2627
use rustc::util::nodemap::FxHashSet;
2728
use rustc_data_structures::indexed_vec::IndexVec;
2829
use rustc_data_structures::fx::FxHashMap;
@@ -576,6 +577,16 @@ pub fn const_eval_provider<'a, 'tcx>(
576577
tcx: TyCtxt<'a, 'tcx, 'tcx>,
577578
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
578579
) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
580+
if key.param_env.reveal == Reveal::All {
581+
let mut key = key.clone();
582+
key.param_env.reveal = Reveal::UserFacing;
583+
match tcx.const_eval(key) {
584+
// try again with reveal all as requested
585+
Err(ErrorHandled::TooGeneric) => {},
586+
// dedupliate calls
587+
other => return other,
588+
}
589+
}
579590
tcx.const_eval_raw(key).and_then(|val| {
580591
validate_const(tcx, val, key)
581592
})
@@ -585,6 +596,16 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
585596
tcx: TyCtxt<'a, 'tcx, 'tcx>,
586597
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
587598
) -> ::rustc::mir::interpret::ConstEvalResult<'tcx> {
599+
if key.param_env.reveal == Reveal::All {
600+
let mut key = key.clone();
601+
key.param_env.reveal = Reveal::UserFacing;
602+
match tcx.const_eval_raw(key) {
603+
// try again with reveal all as requested
604+
Err(ErrorHandled::TooGeneric) => {},
605+
// dedupliate calls
606+
other => return other,
607+
}
608+
}
588609
trace!("const eval: {:?}", key);
589610
let cid = key.value;
590611
let def_id = cid.instance.def.def_id();

src/test/ui/array_const_index-0.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const A: &'static [i32] = &[];
1212
const B: i32 = (&A)[1];
1313
//~^ index out of bounds: the len is 0 but the index is 1
1414
//~| ERROR any use of this value will cause an error
15-
//~| ERROR any use of this value will cause an error
1615

1716
fn main() {
1817
let _ = B; //~ ERROR erroneous constant used

src/test/ui/array_const_index-0.stderr

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,12 @@ LL | const B: i32 = (&A)[1];
88
|
99
= note: #[deny(const_err)] on by default
1010

11-
error: any use of this value will cause an error
12-
--> $DIR/array_const_index-0.rs:12:1
13-
|
14-
LL | const B: i32 = (&A)[1];
15-
| ^^^^^^^^^^^^^^^-------^
16-
| |
17-
| index out of bounds: the len is 0 but the index is 1
18-
1911
error[E0080]: erroneous constant used
20-
--> $DIR/array_const_index-0.rs:18:13
12+
--> $DIR/array_const_index-0.rs:17:13
2113
|
2214
LL | let _ = B; //~ ERROR erroneous constant used
2315
| ^ referenced constant has errors
2416

25-
error: aborting due to 3 previous errors
17+
error: aborting due to 2 previous errors
2618

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

src/test/ui/array_const_index-1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const A: [i32; 0] = [];
1212
const B: i32 = A[1];
1313
//~^ index out of bounds: the len is 0 but the index is 1
1414
//~| ERROR any use of this value will cause an error
15-
//~| ERROR any use of this value will cause an error
1615

1716
fn main() {
1817
let _ = B; //~ ERROR erroneous constant used

src/test/ui/array_const_index-1.stderr

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,12 @@ LL | const B: i32 = A[1];
88
|
99
= note: #[deny(const_err)] on by default
1010

11-
error: any use of this value will cause an error
12-
--> $DIR/array_const_index-1.rs:12:1
13-
|
14-
LL | const B: i32 = A[1];
15-
| ^^^^^^^^^^^^^^^----^
16-
| |
17-
| index out of bounds: the len is 0 but the index is 1
18-
1911
error[E0080]: erroneous constant used
20-
--> $DIR/array_const_index-1.rs:18:13
12+
--> $DIR/array_const_index-1.rs:17:13
2113
|
2214
LL | let _ = B; //~ ERROR erroneous constant used
2315
| ^ referenced constant has errors
2416

25-
error: aborting due to 3 previous errors
17+
error: aborting due to 2 previous errors
2618

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

src/test/ui/consts/const-err-early.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![deny(const_err)]
1212

1313
pub const A: i8 = -std::i8::MIN; //~ ERROR const_err
14-
//~^ ERROR const_err
1514
pub const B: u8 = 200u8 + 200u8; //~ ERROR const_err
1615
pub const C: u8 = 200u8 * 4; //~ ERROR const_err
1716
pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err

src/test/ui/consts/const-err-early.stderr

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,81 +13,73 @@ LL | #![deny(const_err)]
1313
| ^^^^^^^^^
1414

1515
error: any use of this value will cause an error
16-
--> $DIR/const-err-early.rs:15:1
16+
--> $DIR/const-err-early.rs:14:1
1717
|
1818
LL | pub const B: u8 = 200u8 + 200u8; //~ ERROR const_err
1919
| ^^^^^^^^^^^^^^^^^^-------------^
2020
| |
2121
| attempt to add with overflow
2222

2323
error: any use of this value will cause an error
24-
--> $DIR/const-err-early.rs:16:1
24+
--> $DIR/const-err-early.rs:15:1
2525
|
2626
LL | pub const C: u8 = 200u8 * 4; //~ ERROR const_err
2727
| ^^^^^^^^^^^^^^^^^^---------^
2828
| |
2929
| attempt to multiply with overflow
3030

3131
error: any use of this value will cause an error
32-
--> $DIR/const-err-early.rs:17:1
32+
--> $DIR/const-err-early.rs:16:1
3333
|
3434
LL | pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err
3535
| ^^^^^^^^^^^^^^^^^^-----------------^
3636
| |
3737
| attempt to subtract with overflow
3838

3939
error: any use of this value will cause an error
40-
--> $DIR/const-err-early.rs:18:1
40+
--> $DIR/const-err-early.rs:17:1
4141
|
4242
LL | pub const E: u8 = [5u8][1]; //~ ERROR const_err
4343
| ^^^^^^^^^^^^^^^^^^--------^
4444
| |
4545
| index out of bounds: the len is 1 but the index is 1
4646

47-
error: any use of this value will cause an error
48-
--> $DIR/const-err-early.rs:13:1
49-
|
50-
LL | pub const A: i8 = -std::i8::MIN; //~ ERROR const_err
51-
| ^^^^^^^^^^^^^^^^^^-------------^
52-
| |
53-
| attempt to negate with overflow
54-
5547
error[E0080]: erroneous constant used
56-
--> $DIR/const-err-early.rs:21:14
48+
--> $DIR/const-err-early.rs:20:14
5749
|
5850
LL | let _a = A; //~ ERROR erroneous constant used
5951
| ^ referenced constant has errors
6052

6153
error[E0080]: erroneous constant used
62-
--> $DIR/const-err-early.rs:22:14
54+
--> $DIR/const-err-early.rs:21:14
6355
|
6456
LL | let _b = B; //~ ERROR erroneous constant used
6557
| ^ referenced constant has errors
6658

6759
error[E0080]: erroneous constant used
68-
--> $DIR/const-err-early.rs:23:14
60+
--> $DIR/const-err-early.rs:22:14
6961
|
7062
LL | let _c = C; //~ ERROR erroneous constant used
7163
| ^ referenced constant has errors
7264

7365
error[E0080]: erroneous constant used
74-
--> $DIR/const-err-early.rs:24:14
66+
--> $DIR/const-err-early.rs:23:14
7567
|
7668
LL | let _d = D; //~ ERROR erroneous constant used
7769
| ^ referenced constant has errors
7870

7971
error[E0080]: erroneous constant used
80-
--> $DIR/const-err-early.rs:25:14
72+
--> $DIR/const-err-early.rs:24:14
8173
|
8274
LL | let _e = E; //~ ERROR erroneous constant used
8375
| ^ referenced constant has errors
8476

8577
error: index out of bounds: the len is 1 but the index is 1
86-
--> $DIR/const-err-early.rs:26:14
78+
--> $DIR/const-err-early.rs:25:14
8779
|
8880
LL | let _e = [6u8][1]; //~ ERROR index out of bounds
8981
| ^^^^^^^^
9082

91-
error: aborting due to 12 previous errors
83+
error: aborting due to 11 previous errors
9284

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

src/test/ui/consts/const-err-multi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
pub const A: i8 = -std::i8::MIN;
1414
//~^ ERROR const_err
15-
//~| ERROR const_err
1615
pub const B: i8 = A;
1716
//~^ ERROR const_err
1817
pub const C: u8 = A as u8;

src/test/ui/consts/const-err-multi.stderr

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,35 @@ LL | #![deny(const_err)]
1313
| ^^^^^^^^^
1414

1515
error: any use of this value will cause an error
16-
--> $DIR/const-err-multi.rs:16:1
16+
--> $DIR/const-err-multi.rs:15:1
1717
|
1818
LL | pub const B: i8 = A;
1919
| ^^^^^^^^^^^^^^^^^^-^
2020
| |
2121
| referenced constant has errors
2222

2323
error: any use of this value will cause an error
24-
--> $DIR/const-err-multi.rs:18:1
24+
--> $DIR/const-err-multi.rs:17:1
2525
|
2626
LL | pub const C: u8 = A as u8;
2727
| ^^^^^^^^^^^^^^^^^^-------^
2828
| |
2929
| referenced constant has errors
3030

3131
error: any use of this value will cause an error
32-
--> $DIR/const-err-multi.rs:20:1
32+
--> $DIR/const-err-multi.rs:19:1
3333
|
3434
LL | pub const D: i8 = 50 - A;
3535
| ^^^^^^^^^^^^^^^^^^------^
3636
| |
3737
| referenced constant has errors
3838

39-
error: any use of this value will cause an error
40-
--> $DIR/const-err-multi.rs:13:1
41-
|
42-
LL | pub const A: i8 = -std::i8::MIN;
43-
| ^^^^^^^^^^^^^^^^^^-------------^
44-
| |
45-
| attempt to negate with overflow
46-
4739
error[E0080]: erroneous constant used
48-
--> $DIR/const-err-multi.rs:24:13
40+
--> $DIR/const-err-multi.rs:23:13
4941
|
5042
LL | let _ = (A, B, C, D);
5143
| ^^^^^^^^^^^^ referenced constant has errors
5244

53-
error: aborting due to 6 previous errors
45+
error: aborting due to 5 previous errors
5446

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

src/test/ui/consts/const-err.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ fn black_box<T>(_: T) {
1919

2020
const FOO: u8 = [5u8][1];
2121
//~^ WARN any use of this value will cause an error
22-
//~| WARN any use of this value will cause an error
2322

2423
fn main() {
2524
black_box((FOO, FOO));

0 commit comments

Comments
 (0)