Skip to content

Error message for invalid pattern with ref/mut bindings points inprecisely and supriously mentions paths #15914

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

Closed
huonw opened this issue Jul 23, 2014 · 0 comments · Fixed by #17215
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@huonw
Copy link
Member

huonw commented Jul 23, 2014

$ rustc - <<< 'fn main() { let ref (); }'
<anon>:1:17: 1:20 error: expected identifier, found path
<anon>:1 fn main() { let ref (); }
                         ^~~

$ rustc - <<< 'fn main() { let mut _; }'
<anon>:1:17: 1:20 error: expected identifier, found path
<anon>:1 fn main() { let mut _; }
                         ^~~

$ rustc - <<< 'fn main() { let ref mut 1; }'
<anon>:1:21: 1:24 error: expected identifier, found path
<anon>:1 fn main() { let ref mut 1; }
                             ^~~

The error snake isn't on the right token (since the problem is the ()/_/1 not being an identifier, not the ref/mut), and there's no path in any of the examples, but all the error messages complain about it.

In contrast, a different pattern gives a reasonable error message:

$ rustc - <<< 'fn main() { let ref mut A(_); }'
<anon>:1:25: 1:26 error: expected identifier, found enum pattern
<anon>:1 fn main() { let ref mut A(_); }
                                 ^

(although theoretically the error snake should cover the whole enum pattern, given it's actually pointing at an identifier there.)

ftxqxd added a commit to ftxqxd/rust that referenced this issue Sep 22, 2014
bors added a commit that referenced this issue Sep 22, 2014
This updates the `unused` lint group to include more lints, updates the `non_snake_case` lint to give better suggestions, adds a note explaining why a lifetime cannot be elided, and tweaks various error messages. This also updates the `non_uppercase_statics` lint to be warn-by-default to match the other naming lints. For statics, this lint is particularly useful, because a non-uppercase static can easily collide with a pattern binding, resulting in very confusing errors.

Closes #15914.
Closes #15657.
Closes #17337.
ftxqxd added a commit to ftxqxd/rust that referenced this issue Oct 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant