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

Suggest to take and ignore args while closure args count mismatching #52647

Merged
merged 7 commits into from
Jul 26, 2018

Conversation

csmoe
Copy link
Member

@csmoe csmoe commented Jul 23, 2018

Closes #52473

@rust-highfive

This comment has been minimized.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 23, 2018
@csmoe
Copy link
Member Author

csmoe commented Jul 23, 2018

r? @estebank

@rust-highfive rust-highfive assigned estebank and unassigned oli-obk Jul 23, 2018
@rust-highfive

This comment has been minimized.

@csmoe csmoe force-pushed the closure_arg_ignore branch 2 times, most recently from 4f9f845 to 6ff4353 Compare July 23, 2018 14:47
@oli-obk
Copy link
Contributor

oli-obk commented Jul 23, 2018

I think this could benefit from a ui test (maybe even a rustfix one?)

@rust-highfive

This comment has been minimized.

| ^^^^^^^ --
| | |
| | takes 0 arguments
| | help: change the closure to take and ignore the arguments: `|_, _|`
Copy link
Member Author

@csmoe csmoe Jul 24, 2018

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?

Copy link
Contributor

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.

Copy link
Contributor

@estebank estebank left a 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{}",
Copy link
Contributor

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.
Copy link
Contributor

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 `|_, _|`.

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jul 25, 2018

📌 Commit 1d79588 has been approved by estebank

@bors
Copy link
Contributor

bors commented Jul 25, 2018

🌲 The tree is currently closed for pull requests below priority 99, this pull request will be tested once the tree is reopened

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 25, 2018
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jul 26, 2018
Suggest to take and ignore args while closure args count mismatching

Closes rust-lang#52473
bors added a commit that referenced this pull request Jul 26, 2018
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
@bors bors merged commit 1d79588 into rust-lang:master Jul 26, 2018
@csmoe csmoe deleted the closure_arg_ignore branch July 27, 2018 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants