-
Notifications
You must be signed in to change notification settings - Fork 13.3k
customize error message in the case where user supplies erroneous type annotation on closure argument #45727
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
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
WG-diagnostics
Working group: Diagnostics
Comments
For the given test case, the output would be closer to (as there are multiple arguments with incorrect type):
Update:
|
This sort of thing gave me a head-scratcher in my code (before i added the fn main() {
let _ = (-10..=10).find(|x: i32| x.signum() == 0);
} erroring as:
but I would much prefer a direct suggestion to replace the closure parameter with |
Current output for the original report:
And for the recent comment:
|
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Jan 20, 2023
Tweak "borrow closure argument" suggestion Fix rust-lang#45727.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Jan 20, 2023
Tweak "borrow closure argument" suggestion Fix rust-lang#45727.
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
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
WG-diagnostics
Working group: Diagnostics
As discussed in https://github.com/rust-lang/rust/pull/45072, we have a newer approach to handling type annotations on closure arguments that should allow us to give clearer errors in many cases. Currently, if the user annotations would yield a unification error, we wind up falling back to some more general code. So for example in the
ui/anonymous-higher-ranked-lifetime.rs
test, for code like:we generate
but we could now generate something specific to one of the parameter types, rather like:
To do this, we would want to search around for the
FIXME(#45727)
-- this identifies the newer code, which is currently running in a transaction and falling back to the older strategy in the event of error.The text was updated successfully, but these errors were encountered: