Skip to content

Remove visit_subpats parameter from check_pat #60043

@varkor

Description

@varkor
Member

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.

Activity

added
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
C-cleanupCategory: PRs that clean code up or issues documenting cleanup.
E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
on Apr 17, 2019
added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Apr 17, 2019
stepnivlk

stepnivlk commented on Apr 17, 2019

@stepnivlk
Contributor

hi @varkor, I'm happy to take care of this one if it's not taken already.

varkor

varkor commented on Apr 17, 2019

@varkor
MemberAuthor

@stepnivlk: go ahead! Let me know if you have any questions or problems with the implementation! :)

added a commit that references this issue on Apr 23, 2019
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

    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

      Participants

      @jonas-schievink@varkor@stepnivlk

      Issue actions

        Remove `visit_subpats` parameter from `check_pat` · Issue #60043 · rust-lang/rust