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

Continue parsing after parent type args and suggest using angle brackets #57768

Merged
merged 4 commits into from
Jan 21, 2019

Conversation

estebank
Copy link
Contributor

error[E0214]: parenthesized parameters may only be used with a trait
--> $DIR/E0214.rs:2:15
   |
LL |     let v: Vec(&str) = vec!["foo"];
   |               ^^^^^^
   |               |
   |               only traits may use parentheses
   |               help: use angle brackets instead: `<&str>`

r? @zackmdavis

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 20, 2019
.emit();
(hir::GenericArgs::none(), true)
let mut err = struct_span_err!(self.sess, data.span, E0214, "{}", msg);
err.span_label(data.span, "only traits may use parentheses");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No time to dig into it now, but I'm mildly curious about the history of this rule. Offhand, I don't seem to recall seeing traits use parentheses for type argum—oh, never mind, I just read --explain 214, and it points out that it's for Fn(T) types.

This does seem sufficiently remote from the crux of the error at hand that we might want to reword the top-line error message to emphasize "parameters use brackets, generally" rather than highlighting the unusual case of traits? I don't have a crisp alternative wording to propose at the moment, though.

src/librustc/hir/lowering.rs Show resolved Hide resolved
@zackmdavis
Copy link
Member

@estebank My only suggestion is, can we check if GenericArgs::Parenthesized data.inputs is empty and avoid suggesting the empty parameter list <>? I won't insist on it if it's too annoying or too much complexity for a rare case, so r=me

@estebank
Copy link
Contributor Author

My only suggestion is, can we check if GenericArgs::Parenthesized data.inputs is empty and avoid suggesting the empty parameter list <>?

It makes sense to do so and should be easy enough to add.

I won't insist on it if it's too annoying or too much complexity for a rare case

I feel this is already quite a rare case to begin with, we might as well do it right :)

@estebank
Copy link
Contributor Author

@bors r=zackmdavis

@bors
Copy link
Contributor

bors commented Jan 20, 2019

📌 Commit 2ab6cef has been approved by zackmdavis

@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 Jan 20, 2019
Centril added a commit to Centril/rust that referenced this pull request Jan 21, 2019
Continue parsing after parent type args and suggest using angle brackets

```
error[E0214]: parenthesized parameters may only be used with a trait
--> $DIR/E0214.rs:2:15
   |
LL |     let v: Vec(&str) = vec!["foo"];
   |               ^^^^^^
   |               |
   |               only traits may use parentheses
   |               help: use angle brackets instead: `<&str>`
```

r? @zackmdavis
bors added a commit that referenced this pull request Jan 21, 2019
Rollup of 5 pull requests

Successful merges:

 - #56796 (Change bounds on `TryFrom` blanket impl to use `Into` instead of `From`)
 - #57768 (Continue parsing after parent type args and suggest using angle brackets)
 - #57769 (Suggest correct cast for struct fields with shorthand syntax)
 - #57783 (Add "dereference boxed value" suggestion.)
 - #57784 (Add span for bad doc comment)

Failed merges:

r? @ghost
@bors bors merged commit 2ab6cef into rust-lang:master Jan 21, 2019
@estebank estebank deleted the type-args-sugg branch November 9, 2023 05:20
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.

4 participants