forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#92507 - chordtoll:suggest-single-quotes, r=…
…petrochenkov Suggest single quotes when char expected, str provided If a type mismatch occurs where a char is expected and a string literal is provided, suggest changing the double quotes to single quotes. We already provide this suggestion in the other direction ( ' -> " ). Especially useful for new rust devs used to a language in which single/double quotes are interchangeable. Fixes rust-lang#92479.
- Loading branch information
Showing
10 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// When a MULTI-character string literal is used where a char should be, | ||
// DO NOT suggest changing to single quotes. | ||
|
||
fn main() { | ||
let _: char = "foo"; //~ ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/char-as-str-multi.rs:5:19 | ||
| | ||
LL | let _: char = "foo"; | ||
| ---- ^^^^^ expected `char`, found `&str` | ||
| | | ||
| expected due to this | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// When a SINGLE-character string literal is used where a char should be, | ||
// suggest changing to single quotes. | ||
|
||
// Testing both single-byte and multi-byte characters, as we should handle both. | ||
|
||
// run-rustfix | ||
|
||
fn main() { | ||
let _: char = 'a'; //~ ERROR mismatched types | ||
let _: char = '人'; //~ ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// When a SINGLE-character string literal is used where a char should be, | ||
// suggest changing to single quotes. | ||
|
||
// Testing both single-byte and multi-byte characters, as we should handle both. | ||
|
||
// run-rustfix | ||
|
||
fn main() { | ||
let _: char = "a"; //~ ERROR mismatched types | ||
let _: char = "人"; //~ ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/char-as-str-single.rs:9:19 | ||
| | ||
LL | let _: char = "a"; | ||
| ---- ^^^ expected `char`, found `&str` | ||
| | | ||
| expected due to this | ||
| | ||
help: if you meant to write a `char` literal, use single quotes | ||
| | ||
LL | let _: char = 'a'; | ||
| ~~~ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/char-as-str-single.rs:10:19 | ||
| | ||
LL | let _: char = "人"; | ||
| ---- ^^^^ expected `char`, found `&str` | ||
| | | ||
| expected due to this | ||
| | ||
help: if you meant to write a `char` literal, use single quotes | ||
| | ||
LL | let _: char = '人'; | ||
| ~~~~ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// When a char literal is used where a str should be, | ||
// suggest changing to double quotes. | ||
|
||
// run-rustfix | ||
|
||
fn main() { | ||
let _: &str = "a"; //~ ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// When a char literal is used where a str should be, | ||
// suggest changing to double quotes. | ||
|
||
// run-rustfix | ||
|
||
fn main() { | ||
let _: &str = 'a'; //~ ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/str-as-char.rs:7:19 | ||
| | ||
LL | let _: &str = 'a'; | ||
| ---- ^^^ expected `&str`, found `char` | ||
| | | ||
| expected due to this | ||
| | ||
help: if you meant to write a `str` literal, use double quotes | ||
| | ||
LL | let _: &str = "a"; | ||
| ~~~ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters