From 1eeb5dcb677d281e3dd2483a47b7cb30d8c8c31f Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 3 Jul 2018 12:03:47 +0200 Subject: [PATCH] Deduplicate error reports for statics --- src/librustc_mir/monomorphize/collector.rs | 11 ++--------- src/test/compile-fail/issue-14227.rs | 2 -- src/test/compile-fail/issue-28324.rs | 2 -- src/test/ui/const-eval/index_out_of_bounds.rs | 1 - src/test/ui/const-eval/index_out_of_bounds.stderr | 12 ++---------- 5 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 3a046cd800a3e..09c5df0005260 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -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) => { diff --git a/src/test/compile-fail/issue-14227.rs b/src/test/compile-fail/issue-14227.rs index 95f017061a257..250e78ce24640 100644 --- a/src/test/compile-fail/issue-14227.rs +++ b/src/test/compile-fail/issue-14227.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-28324.rs b/src/test/compile-fail/issue-28324.rs index 8512238dd31ca..af73db2b4d211 100644 --- a/src/test/compile-fail/issue-28324.rs +++ b/src/test/compile-fail/issue-28324.rs @@ -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() {} diff --git a/src/test/ui/const-eval/index_out_of_bounds.rs b/src/test/ui/const-eval/index_out_of_bounds.rs index 55c64d2b04e45..f3578bcef6e41 100644 --- a/src/test/ui/const-eval/index_out_of_bounds.rs +++ b/src/test/ui/const-eval/index_out_of_bounds.rs @@ -10,7 +10,6 @@ static FOO: i32 = [][0]; //~^ ERROR E0080 -//~| ERROR E0080 fn main() { let array = [std::env::args().len()]; diff --git a/src/test/ui/const-eval/index_out_of_bounds.stderr b/src/test/ui/const-eval/index_out_of_bounds.stderr index 828fba55a3afe..464ba8ff92723 100644 --- a/src/test/ui/const-eval/index_out_of_bounds.stderr +++ b/src/test/ui/const-eval/index_out_of_bounds.stderr @@ -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`.