diff options
| author | bors <bors@rust-lang.org> | 2021-06-11 10:25:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-06-11 10:25:53 +0000 |
| commit | dddebf94bccddaa7b8836380c1d90b34553d79d0 (patch) | |
| tree | 791e02b5df88211ddfaa1131936691bf4818c5db /compiler/rustc_codegen_llvm/src | |
| parent | 66ba81059e15b3466c71fe5b5bf2418702dd1fd1 (diff) | |
| parent | 6206247335619ac83550fae2013ead4e66b454d1 (diff) | |
| download | rust-dddebf94bccddaa7b8836380c1d90b34553d79d0.tar.gz rust-dddebf94bccddaa7b8836380c1d90b34553d79d0.zip | |
Auto merge of #86116 - FabianWolff:issue-86100, r=varkor
Suggest a trailing comma if a 1-tuple is expected and a parenthesized expression is found
This pull request fixes #86100. The following code:
```rust
fn main() {
let t: (i32,) = (1);
}
```
currently produces:
```
warning: unnecessary parentheses around assigned value
--> test.rs:2:21
|
2 | let t: (i32,) = (1);
| ^^^ help: remove these parentheses
|
= note: `#[warn(unused_parens)]` on by default
error[E0308]: mismatched types
--> test.rs:2:21
|
2 | let t: (i32,) = (1);
| ------ ^^^ expected tuple, found integer
| |
| expected due to this
|
= note: expected tuple `(i32,)`
found type `{integer}`
error: aborting due to previous error; 1 warning emitted
```
With my changes, I get the same warning and the following error:
```
error[E0308]: mismatched types
--> test.rs:2:21
|
2 | let t: (i32,) = (1);
| ------ ^^^ expected tuple, found integer
| |
| expected due to this
|
= note: expected tuple `(i32,)`
found type `{integer}`
help: use a trailing comma to create a tuple with one element
|
2 | let t: (i32,) = (1,);
| ^^^^
```
i.e. I have added a suggestion to add a trailing comma to create a 1-tuple. This suggestion is only issued if a 1-tuple is expected and the expression (`(1)` in the example above) is surrounded by parentheses and does not already have a tuple type. In this situation, I'd say that it is pretty likely that the user meant to create a tuple.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions
