Repository navigation
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Description
Const eval asserts that reporting an error for statics actually worked. This is not only done in a wrong way (checks for no error having happened in the entire compilation), it's also very fragile. We should instead use the track_errors method around the report_as_error call, and in case track_errors returns Ok, we need to do the delay_span_bug.
The relevant code that needs to be changed can be found in
rust/src/librustc_mir/const_eval.rs
Lines 645 to 654 in 16e7e05
| 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. | |
| if tcx.sess.err_count() == 0 { | |
| tcx.sess.delay_span_bug(err.span, | |
| &format!("static eval failure did not emit an error: {:#?}", | |
| reported_err)); | |
| } | |
| reported_err |
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Activity
estebank commentedon Mar 15, 2019
Wouldn't using
track_errorscause the compiler to stop at const evaluation? Ideally we would want the compiler to choose a reasonable recovery value (just a binding ofTyErr?) and continue to minimize the loop of "fix 5 errors, get 300 errors" (#39275).oli-obk commentedon Mar 15, 2019
track_errorsdoesn't actually stop anything. It just gives you aResult::Errif new errors occured and aResult::Okotherwise.JohnTitor commentedon Mar 21, 2019
@oli-obk I want to solve this, could I open a PR(and ask you to review)?
oli-obk commentedon Mar 22, 2019
Jup! It's all yours!
Rollup merge of rust-lang#59358 - JohnTitor:use-track-errors, r=oli-obk