-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[E0532] Error when using functions in patterns should give an explanation of patterns #97200
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
Comments
What should be linked? Something in Rust by Example or the Rust docs (or something else?) |
@rustbot claim |
@estebank would know better what the precedent for existing errors is, but I'd expect it to link to the reference page for patterns, https://doc.rust-lang.org/reference/patterns.html I'm slightly unsure about this because of the intimidating grammar block at the top if it's gonna end up pointing beginners to that, but it's probably the best reference for understanding all the details of patterns… If not that, then I'd expect the Book chapter on patterns https://doc.rust-lang.org/book/ch18-00-patterns.html |
I'll wait for him to respond before starting. |
@Milo123459, there are a few existing error notes that point to book chapters in the compiler, search for references to I can review a PR attaches such a note to some cases. You might need to be careful about only suggesting it for items that aren't valid in patterns but not* those used incorrectly. For example, E0532 fires if you try to use a unit enum variant as a tuple enum variant. I think we only want to suggest it when we're trying to use, e.g., a function or method name as a pattern variant. |
Hmm, how do we control that / know when it is only invalid? |
You should be able to check the You might need to do some experimentation -- if you can't, then feel free to just fall back to suggesting it always, but leave a FIXME. |
I would likely link at https://doc.rust-lang.org/book/ch18-00-patterns.html, precisely because it is more conversational than the reference, but we could link to both, if that seemed necessary.
The For the wording changes, I would borrow heavily from the reference and book, and at least add a |
@rustbot release-assignment |
…-errors On function and method calls in patterns, link to the book ``` error: expected a pattern, found an expression --> f889.rs:3:13 | 3 | let (x, y.drop()) = (1, 2); | ^^^^^^^^ not a pattern | = note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html> error[E0532]: expected a pattern, found a function call --> f889.rs:2:13 | 2 | let (x, drop(y)) = (1, 2); | ^^^^ not a tuple struct or tuple variant | = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html> ``` Fix rust-lang#97200.
Rollup merge of rust-lang#131312 - estebank:fn-in-pattern, r=compiler-errors On function and method calls in patterns, link to the book ``` error: expected a pattern, found an expression --> f889.rs:3:13 | 3 | let (x, y.drop()) = (1, 2); | ^^^^^^^^ not a pattern | = note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html> error[E0532]: expected a pattern, found a function call --> f889.rs:2:13 | 2 | let (x, drop(y)) = (1, 2); | ^^^^ not a tuple struct or tuple variant | = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html> ``` Fix rust-lang#97200.
Uh oh!
There was an error while loading. Please reload this page.
Given the following code: (Playground)
The current output is:
The error message should give/link to an explanation of what kinds of things are expected in patterns in general, maybe in a note.
(Filed at request of @estebank)
The text was updated successfully, but these errors were encountered: