Skip to content

Use track_errors instead of hand-rolling such a check #59215

Closed
@oli-obk

Description

@oli-obk

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

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

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)E-easyCall 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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions