Skip to content

Remove visit_subpats parameter from check_pat #60043

Closed
@varkor

Description

@varkor

The visit_subpats parameter is a hack (to fix a problem with range patterns) that should be refactored. The idea is that the state should be contained in EllipsisInclusiveRangePatterns instead.

This should be straightforward to fix.

  1. Remove the &mut bool parameter from
    fn check_pat(a: &ast::Pat, b: &mut bool); // FIXME: &mut bool looks just broken

    (You'll also need to update the signature of check_pat in src/librustc_lint/unused.rs.
  2. Add a check_pat_post method with an identical signature below it.
  3. Remove the visit_subpats condition from
    fn visit_pat(&mut self, p: &'a ast::Pat) {
    let mut visit_subpats = true;
    run_early_pass!(self, check_pat, p, &mut visit_subpats);
    self.check_id(p.id);
    if visit_subpats {
    ast_visit::walk_pat(self, p);
    }
    }
  4. Run an early lint pass for check_pat_post at the end.
  5. Add a Option<NodeId> field to EllipsisInclusiveRangePatterns in
    declare_lint_pass!(EllipsisInclusiveRangePatterns => [ELLIPSIS_INCLUSIVE_RANGE_PATTERNS]);

    (Look at DeprecatedAttr for an example of a lint with fields.)
    You'll also need to initialise it with None here:
    EllipsisInclusiveRangePatterns: EllipsisInclusiveRangePatterns,
  6. This should be replaced with an assignment of the new field in EllipsisInclusiveRangePatterns to pat.id:
    *visit_subpats = false;
  7. check_pat should be early-exited if the field is Some(..).
  8. Add a check_pat_post implementation to EllipsisInclusiveRangePatterns and reset the field to None if the pattern ID matches the field ID.
  9. Make sure the UI tests still pass with no changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions