-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Suggest to take and ignore args while closure args count mismatching #52647
Conversation
This comment has been minimized.
This comment has been minimized.
r? @estebank |
This comment has been minimized.
This comment has been minimized.
4f9f845
to
6ff4353
Compare
I think this could benefit from a ui test (maybe even a rustfix one?) |
6ff4353
to
a701870
Compare
This comment has been minimized.
This comment has been minimized.
a701870
to
a71deb2
Compare
| ^^^^^^^ -- | ||
| | | | ||
| | takes 0 arguments | ||
| | help: change the closure to take and ignore the arguments: `|_, _|` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estebank the position of this help message is a bit weird since I span_suggestion_with_applicability
the same way as the tuple-args do. what I want:
|
help: change the closure to take multiple arguments instead of a single tuple
|
LL | [1, 2, 3].sort_by(|tuple, tuple2| panic!());
| ^^^^^^^^^^^^^^^
How to fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions that have fewer than 10 words (among other things) are emitted as above, inline. Making the message longer is one of the ways of ensuring the separate suggestion line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicks aside, r=me.
.join(", "); | ||
err.span_suggestion_with_applicability( | ||
found_span, | ||
&format!("change the closure to take and ignore the expected argument{}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I feel that this would read better as "you can change the closure...". That way we don't imply to the user that this is what they must do, only something they can do.
@@ -1050,6 +1050,29 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { | |||
if let Some(found_span) = found_span { | |||
err.span_label(found_span, format!("takes {}", found_str)); | |||
|
|||
// Suggest to take and ignore the arguments with expected_args_length `_`s if | |||
// found arguments is empty(Suppose the user just wants to ignore args in this case). | |||
// like `|_, _|` for closure with 2 expected args. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Suggest to take and ignore the arguments with expected_args_length `_`s if
// found arguments is empty (assume the user just wants to ignore args in this case).
// For example, if `expected_args_length` is 2, suggest `|_, _|`.
@bors r+ |
📌 Commit 1d79588 has been approved by |
🌲 The tree is currently closed for pull requests below priority 99, this pull request will be tested once the tree is reopened |
Suggest to take and ignore args while closure args count mismatching Closes rust-lang#52473
Rollup of 16 pull requests Successful merges: - #52558 (Add tests for ICEs which no longer repro) - #52610 (Clarify what a task is) - #52617 (Don't match on region kinds when reporting NLL errors) - #52635 (Fix #[linkage] propagation though generic functions) - #52647 (Suggest to take and ignore args while closure args count mismatching) - #52649 (Point spans to inner elements of format strings) - #52654 (Format linker args in a way that works for gcc and ld) - #52667 (update the stdsimd submodule) - #52674 (Impl Executor for Box<E: Executor>) - #52690 (ARM: expose `rclass` and `dsp` target features) - #52692 (Improve readability in a few sorts) - #52695 (Hide some lints which are not quite right the way they are reported to the user) - #52718 (State default capacity for BufReader/BufWriter) - #52721 (std::ops::Try impl for std::task::Poll) - #52723 (rustc: Register crates under their real names) - #52734 (sparc ABI issue - structure returning from function is returned in 64bit registers (with tests)) Failed merges: - #52678 ([NLL] Use better spans in some errors) r? @ghost
Closes #52473