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

Say "this enum variant takes"/"this struct takes" instead of "this function takes" #86493

Merged
merged 2 commits into from
Jun 22, 2021

Conversation

syvb
Copy link
Contributor

@syvb syvb commented Jun 20, 2021

This makes error messages for functions with incorrect argument counts adapt if they refer to a struct or enum variant:

error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied
  --> $DIR/struct-enum-wrong-args.rs:7:13
   |
LL |     let _ = Ok();
   |             ^^-- supplied 0 arguments
   |             |
   |             expected 1 argument

error[E0061]: this struct takes 1 argument but 0 arguments were supplied
  --> $DIR/struct-enum-wrong-args.rs:8:13
   |
LL |     let _ = Wrapper();
   |             ^^^^^^^-- supplied 0 arguments
   |             |
   |             expected 1 argument

Fixes #86481.

@rust-highfive
Copy link
Collaborator

r? @davidtwco

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2021
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

Looks good to me, r=me after resolving existing review comments.

@davidtwco
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 21, 2021

📌 Commit b8a7bfb has been approved by davidtwco

@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 Jun 21, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 21, 2021
…twco

Say "this enum variant takes"/"this struct takes" instead of "this function takes"

This makes error messages for functions with incorrect argument counts adapt if they refer to a struct or enum variant:
```
error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied
  --> $DIR/struct-enum-wrong-args.rs:7:13
   |
LL |     let _ = Ok();
   |             ^^-- supplied 0 arguments
   |             |
   |             expected 1 argument

error[E0061]: this struct takes 1 argument but 0 arguments were supplied
  --> $DIR/struct-enum-wrong-args.rs:8:13
   |
LL |     let _ = Wrapper();
   |             ^^^^^^^-- supplied 0 arguments
   |             |
   |             expected 1 argument
```

Fixes rust-lang#86481.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 22, 2021
Rollup of 11 pull requests

Successful merges:

 - rust-lang#85054 (Revert SGX inline asm syntax)
 - rust-lang#85182 (Move `available_concurrency` implementation to `sys`)
 - rust-lang#86037 (Add `io::Cursor::{remaining, remaining_slice, is_empty}`)
 - rust-lang#86114 (Reopen rust-lang#79692 (Format symbols under shared frames))
 - rust-lang#86297 (Allow to pass arguments to rustdoc-gui tool)
 - rust-lang#86334 (Resolve type aliases to the type they point to in intra-doc links)
 - rust-lang#86367 (Fix comment about rustc_inherit_overflow_checks in abs().)
 - rust-lang#86381 (Add regression test for issue rust-lang#39161)
 - rust-lang#86387 (Remove `#[allow(unused_lifetimes)]` which is now unnecessary)
 - rust-lang#86398 (Add regression test for issue rust-lang#54685)
 - rust-lang#86493 (Say "this enum variant takes"/"this struct takes" instead of "this function takes")

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4495ce7 into rust-lang:master Jun 22, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jun 22, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 28, 2022
…=camelid

Suggest tuple-parentheses for enum variants

This follows on from rust-lang#86493 / rust-lang#86481, making the parentheses suggestion. To summarise, given the following code:

```rust
fn f() -> Option<(i32, i8)> {
    Some(1, 2)
}
```

The current output is:

```
error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied
 --> b.rs:2:5
  |
2 |     Some(1, 2)
  |     ^^^^ -  - supplied 2 arguments
  |     |
  |     expected 1 argument

error: aborting due to previous error

For more information about this error, try `rustc --explain E0061`.
```

With this change, `rustc` will now suggest parentheses when:
- The callee is expecting a single tuple argument
- The number of arguments passed matches the element count in the above tuple
- The arguments' types match the tuple's fields

```
error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied
 --> b.rs:2:5
  |
2 |     Some(1, 2)
  |     ^^^^ -  - supplied 2 arguments
  |
help: use parentheses to construct a tuple
  |
2 |     Some((1, 2))
  |          +    +
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 28, 2022
…amelid

Suggest tuple-parentheses for enum variants

This follows on from rust-lang#86493 / rust-lang#86481, making the parentheses suggestion. To summarise, given the following code:

```rust
fn f() -> Option<(i32, i8)> {
    Some(1, 2)
}
```

The current output is:

```
error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied
 --> b.rs:2:5
  |
2 |     Some(1, 2)
  |     ^^^^ -  - supplied 2 arguments
  |     |
  |     expected 1 argument

error: aborting due to previous error

For more information about this error, try `rustc --explain E0061`.
```

With this change, `rustc` will now suggest parentheses when:
- The callee is expecting a single tuple argument
- The number of arguments passed matches the element count in the above tuple
- The arguments' types match the tuple's fields

```
error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied
 --> b.rs:2:5
  |
2 |     Some(1, 2)
  |     ^^^^ -  - supplied 2 arguments
  |
help: use parentheses to construct a tuple
  |
2 |     Some((1, 2))
  |          +    +
```
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.

Missing parenthesis for tuple in enum variant
6 participants