From 3ba7454152e65beb7519580d8f74cf433f20b724 Mon Sep 17 00:00:00 2001 From: Yuki OKUSHI Date: Fri, 22 Mar 2019 04:38:22 +0900 Subject: [PATCH 1/7] Use track_errors --- src/librustc_mir/const_eval.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 6ab89f80ef528..0cf6c4593e8dd 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -645,10 +645,14 @@ pub fn const_eval_raw_provider<'a, 'tcx>( "could not evaluate static initializer"); // Ensure that if the above error was either `TooGeneric` or `Reported` // an error must be reported. - if tcx.sess.err_count() == 0 { - tcx.sess.delay_span_bug(err.span, + let errs = tcx.sess.track_errors(|| { + tcx.sess.err_count(); + }); + match errs { + Ok(_) => tcx.sess.delay_span_bug(err.span, &format!("static eval failure did not emit an error: {:#?}", - reported_err)); + reported_err)), + Err(_) => (), } reported_err } else if def_id.is_local() { From 526b3558581187c87ca8ca533254c1cbb6275e7b Mon Sep 17 00:00:00 2001 From: Yuki OKUSHI Date: Sat, 23 Mar 2019 00:03:50 +0900 Subject: [PATCH 2/7] Remove err_count --- src/librustc_mir/const_eval.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 0cf6c4593e8dd..80076c6f03533 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -645,13 +645,14 @@ pub fn const_eval_raw_provider<'a, 'tcx>( "could not evaluate static initializer"); // Ensure that if the above error was either `TooGeneric` or `Reported` // an error must be reported. - let errs = tcx.sess.track_errors(|| { - tcx.sess.err_count(); + let tracked_err = tcx.sess.track_errors(|| { + err.report_as_error(ecx.tcx, + "could not evaluate static initializer"); }); - match errs { + match tracked_err { Ok(_) => tcx.sess.delay_span_bug(err.span, &format!("static eval failure did not emit an error: {:#?}", - reported_err)), + tracked_err)), Err(_) => (), } reported_err From ee0e1b7615b92103fa2f4ca280d5b5f189e8def9 Mon Sep 17 00:00:00 2001 From: Yuki OKUSHI Date: Sat, 23 Mar 2019 00:51:08 +0900 Subject: [PATCH 3/7] Set ok value --- src/librustc_mir/const_eval.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 80076c6f03533..9f73c2aa06e6b 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -650,9 +650,9 @@ pub fn const_eval_raw_provider<'a, 'tcx>( "could not evaluate static initializer"); }); match tracked_err { - Ok(_) => tcx.sess.delay_span_bug(err.span, + Ok(reported_err) => tcx.sess.delay_span_bug(err.span, &format!("static eval failure did not emit an error: {:#?}", - tracked_err)), + reported_err)), Err(_) => (), } reported_err From 0e76b34aa7021265630cc9933f1c918f184ba8d8 Mon Sep 17 00:00:00 2001 From: Yuki OKUSHI Date: Sun, 24 Mar 2019 14:45:27 +0900 Subject: [PATCH 4/7] WIP: remove report_as_error --- src/librustc_mir/const_eval.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 9f73c2aa06e6b..964f721508832 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -641,19 +641,17 @@ pub fn const_eval_raw_provider<'a, 'tcx>( let err = error_to_const_error(&ecx, error); // errors in statics are always emitted as fatal errors if tcx.is_static(def_id).is_some() { - let reported_err = err.report_as_error(ecx.tcx, - "could not evaluate static initializer"); // Ensure that if the above error was either `TooGeneric` or `Reported` // an error must be reported. - let tracked_err = tcx.sess.track_errors(|| { + let reported_err = tcx.sess.track_errors(|| { err.report_as_error(ecx.tcx, "could not evaluate static initializer"); }); - match tracked_err { - Ok(reported_err) => tcx.sess.delay_span_bug(err.span, + match reported_err { + Ok(v) => tcx.sess.delay_span_bug(err.span, &format!("static eval failure did not emit an error: {:#?}", - reported_err)), - Err(_) => (), + v)), + Err(err) => err, } reported_err } else if def_id.is_local() { From f0de8e82b868f7f4484b6e3e42543791c8b24b7f Mon Sep 17 00:00:00 2001 From: Yuki OKUSHI Date: Mon, 25 Mar 2019 03:19:48 +0900 Subject: [PATCH 5/7] Return correct values --- src/librustc_mir/const_eval.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 964f721508832..1542cdf1e3e77 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -645,15 +645,17 @@ pub fn const_eval_raw_provider<'a, 'tcx>( // an error must be reported. let reported_err = tcx.sess.track_errors(|| { err.report_as_error(ecx.tcx, - "could not evaluate static initializer"); + "could not evaluate static initializer") }); match reported_err { - Ok(v) => tcx.sess.delay_span_bug(err.span, + Ok(v) => { + tcx.sess.delay_span_bug(err.span, &format!("static eval failure did not emit an error: {:#?}", - v)), - Err(err) => err, + v)); + v + }, + Err(ErrorReported) => ErrorHandled::Reported, } - reported_err } else if def_id.is_local() { // constant defined in this crate, we can figure out a lint level! match tcx.describe_def(def_id) { From 6c8e3a5378e41e08a323139bb7aaa8a8823ec9bc Mon Sep 17 00:00:00 2001 From: Yuki OKUSHI Date: Mon, 25 Mar 2019 03:55:13 +0900 Subject: [PATCH 6/7] Remove unused variable --- src/librustc_mir/const_eval.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 1542cdf1e3e77..1c3f7882b9fcf 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -654,7 +654,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>( v)); v }, - Err(ErrorReported) => ErrorHandled::Reported, + Err(_) => ErrorHandled::Reported, } } else if def_id.is_local() { // constant defined in this crate, we can figure out a lint level! From 07788478332d645293a81686d5d225b8aafabe90 Mon Sep 17 00:00:00 2001 From: Yuki OKUSHI Date: Fri, 29 Mar 2019 04:42:03 +0900 Subject: [PATCH 7/7] Use ErrorReported --- src/librustc_mir/const_eval.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 1c3f7882b9fcf..2268568c5f82d 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -14,6 +14,7 @@ use rustc::ty::{self, TyCtxt, query::TyCtxtAt}; use rustc::ty::layout::{self, LayoutOf, VariantIdx}; use rustc::ty::subst::Subst; use rustc::traits::Reveal; +use rustc::util::common::ErrorReported; use rustc_data_structures::fx::FxHashMap; use syntax::ast::Mutability; @@ -654,7 +655,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>( v)); v }, - Err(_) => ErrorHandled::Reported, + Err(ErrorReported) => ErrorHandled::Reported, } } else if def_id.is_local() { // constant defined in this crate, we can figure out a lint level!