Skip to content

Commit a4846ae

Browse files
committed
Rollup merge of rust-lang#52016 - oli-obk:dedup_static_errors, r=estebank
Deduplicate error reports for statics fixes rust-lang#51970
2 parents 1568b5e + 1eeb5dc commit a4846ae

File tree

5 files changed

+4
-24
lines changed

5 files changed

+4
-24
lines changed

src/librustc_mir/monomorphize/collector.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,8 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
395395
};
396396
let param_env = ty::ParamEnv::reveal_all();
397397

398-
match tcx.const_eval(param_env.and(cid)) {
399-
Ok(val) => collect_const(tcx, val, instance.substs, &mut neighbors),
400-
Err(err) => {
401-
let span = tcx.def_span(def_id);
402-
err.report_as_error(
403-
tcx.at(span),
404-
"could not evaluate static initializer",
405-
);
406-
}
398+
if let Ok(val) = tcx.const_eval(param_env.and(cid)) {
399+
collect_const(tcx, val, instance.substs, &mut neighbors);
407400
}
408401
}
409402
MonoItem::Fn(instance) => {

src/test/compile-fail/issue-14227.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@ extern {
1616
static CRASH: () = symbol;
1717
//~^ ERROR could not evaluate static initializer
1818
//~| tried to read from foreign (extern) static
19-
//~^^^ ERROR could not evaluate static initializer
20-
//~| tried to read from foreign (extern) static
2119

2220
fn main() {}

src/test/compile-fail/issue-28324.rs

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,5 @@ extern {
1717
pub static BAZ: u32 = *&error_message_count;
1818
//~^ ERROR could not evaluate static initializer
1919
//~| tried to read from foreign (extern) static
20-
//~^^^ ERROR could not evaluate static initializer
21-
//~| tried to read from foreign (extern) static
2220

2321
fn main() {}

src/test/ui/const-eval/index_out_of_bounds.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
static FOO: i32 = [][0];
1212
//~^ ERROR E0080
13-
//~| ERROR E0080
1413

1514
fn main() {
1615
let array = [std::env::args().len()];

src/test/ui/const-eval/index_out_of_bounds.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,14 @@ error[E0080]: could not evaluate static initializer
44
LL | static FOO: i32 = [][0];
55
| ^^^^^ index out of bounds: the len is 0 but the index is 0
66

7-
error[E0080]: could not evaluate static initializer
8-
--> $DIR/index_out_of_bounds.rs:11:1
9-
|
10-
LL | static FOO: i32 = [][0];
11-
| ^^^^^^^^^^^^^^^^^^-----^
12-
| |
13-
| index out of bounds: the len is 0 but the index is 0
14-
157
error: index out of bounds: the len is 1 but the index is 1
16-
--> $DIR/index_out_of_bounds.rs:17:5
8+
--> $DIR/index_out_of_bounds.rs:16:5
179
|
1810
LL | array[1]; //~ ERROR index out of bounds
1911
| ^^^^^^^^
2012
|
2113
= note: #[deny(const_err)] on by default
2214

23-
error: aborting due to 3 previous errors
15+
error: aborting due to 2 previous errors
2416

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

0 commit comments

Comments
 (0)