Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E0158 explanation refers to statics, when it should be talking about associated consts #105585

Closed
kpreid opened this issue Dec 12, 2022 · 2 comments · Fixed by #105744
Closed
Assignees
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools

Comments

@kpreid
Copy link
Contributor

kpreid commented Dec 12, 2022

Location

https://doc.rust-lang.org/nightly/error_codes/E0158.html

Summary

The introduction says that this error is about using an associated const in a pattern, and a user encountered it in that context. However, every paragraph after the erroneous code example talks about why you can't match a static, not why you can't match an associated const.

This seems like it might have been accidentally copied without edits from some other error, but there is no other copy of that text. (Was E0158 repurposed, perhaps?)

Proposed improvement

  • E0158 should explain why associated consts may not be matched, and
  • The text discussing static should be moved to E0530, which is the code actually produced by trying to use a static in a pattern, and which currently has only erroneous code samples and not an explanation of why.
@kpreid kpreid added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Dec 12, 2022
@Ezrashaw
Copy link
Contributor

Ezrashaw commented Dec 12, 2022

To add onto this, I think that both the statics and associated constants in patterns are covered under E0158 (not just associated constants). It seems however that only statics are covered in the docs while associated constants are left out.

Relevant rustc code:
compiler/rustc_mir_build/src/thir/pattern/check_match.rs:109

PatternError::StaticInPattern(span) => { // EDIT: this code seems redundant?
    self.span_e0158(span, "statics cannot be referenced in patterns")
}
PatternError::AssocConstInPattern(span) => {
    self.span_e0158(span, "associated consts cannot be referenced in patterns")
}
PatternError::ConstParamInPattern(span) => {
    self.span_e0158(span, "const parameters cannot be referenced in patterns")
}

EDIT: Turns out that PatternError::StaticInPattern is redundant, I think? The code just fails with E0530 or E0532, as OP noted 🤦. I think that this really needs more than just docs changes, so I aren't going to just write a PR, although I still am happy to work on this. So I'll keep the rustbot claim?

@Ezrashaw
Copy link
Contributor

Umm, if nobody minds I might claim this and write a PR.

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants