Skip to content

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

Closed

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

Activity

  1. added
    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.
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    on Mar 15, 2019
  2. estebank commented on Mar 15, 2019

    @estebank
    Contributor

    Wouldn't using track_errors cause the compiler to stop at const evaluation? Ideally we would want the compiler to choose a reasonable recovery value (just a binding of TyErr?) and continue to minimize the loop of "fix 5 errors, get 300 errors" (#39275).

  3. oli-obk commented on Mar 15, 2019

    @oli-obk
    ContributorAuthor

    track_errors doesn't actually stop anything. It just gives you a Result::Err if new errors occured and a Result::Ok otherwise.

  4. JohnTitor commented on Mar 21, 2019

    @JohnTitor
    Member

    @oli-obk I want to solve this, could I open a PR(and ask you to review)?

  5. oli-obk commented on Mar 22, 2019

    @oli-obk
    ContributorAuthor

    Jup! It's all yours!

  6. added a commit that references this issue on Mar 29, 2019
    97927da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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