Skip to content

Deduplicate error reports for statics #52016

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

Merged
merged 1 commit into from
Jul 6, 2018
Merged
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
11 changes: 2 additions & 9 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,8 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
};
let param_env = ty::ParamEnv::reveal_all();

match tcx.const_eval(param_env.and(cid)) {
Ok(val) => collect_const(tcx, val, instance.substs, &mut neighbors),
Err(err) => {
let span = tcx.def_span(def_id);
err.report_as_error(
tcx.at(span),
"could not evaluate static initializer",
);
}
if let Ok(val) = tcx.const_eval(param_env.and(cid)) {
collect_const(tcx, val, instance.substs, &mut neighbors);
}
}
MonoItem::Fn(instance) => {
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/issue-14227.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ extern {
static CRASH: () = symbol;
//~^ ERROR could not evaluate static initializer
//~| tried to read from foreign (extern) static
//~^^^ ERROR could not evaluate static initializer
//~| tried to read from foreign (extern) static

fn main() {}
2 changes: 0 additions & 2 deletions src/test/compile-fail/issue-28324.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ extern {
pub static BAZ: u32 = *&error_message_count;
//~^ ERROR could not evaluate static initializer
//~| tried to read from foreign (extern) static
//~^^^ ERROR could not evaluate static initializer
//~| tried to read from foreign (extern) static

fn main() {}
1 change: 0 additions & 1 deletion src/test/ui/const-eval/index_out_of_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

static FOO: i32 = [][0];
//~^ ERROR E0080
//~| ERROR E0080

fn main() {
let array = [std::env::args().len()];
Expand Down
12 changes: 2 additions & 10 deletions src/test/ui/const-eval/index_out_of_bounds.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@ error[E0080]: could not evaluate static initializer
LL | static FOO: i32 = [][0];
| ^^^^^ index out of bounds: the len is 0 but the index is 0

error[E0080]: could not evaluate static initializer
--> $DIR/index_out_of_bounds.rs:11:1
|
LL | static FOO: i32 = [][0];
| ^^^^^^^^^^^^^^^^^^-----^
| |
| index out of bounds: the len is 0 but the index is 0

error: index out of bounds: the len is 1 but the index is 1
--> $DIR/index_out_of_bounds.rs:17:5
--> $DIR/index_out_of_bounds.rs:16:5
|
LL | array[1]; //~ ERROR index out of bounds
| ^^^^^^^^
|
= note: #[deny(const_err)] on by default

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

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