-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement new literal type Err
#57651
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d19294f
Add new literal type Err
JohnTitor ec8db2a
Cancel process
JohnTitor d33ee3f
Fix tests
JohnTitor 32662c2
Change from error to invalid
JohnTitor bde3795
Continue cheking
JohnTitor 7e2e61c
Change from mk_lit! to cx.expr
JohnTitor 8bbb63c
Add token::Err
JohnTitor b721c1a
Fix tests
JohnTitor c502a79
[WIP] Improve error behavior
JohnTitor e9af312
[WIP] Fix tests
JohnTitor a4ff1dc
Mark incorrect recovered `char` literals as `TyErr` to avoid type errors
JohnTitor 6e59c64
Revert change
JohnTitor 7ce2514
Fix tests
JohnTitor 4005d3a
Remove whitespace
JohnTitor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// This test needs to the last one appearing in this file as it kills the parser | ||
static c: char = | ||
'nope' //~ ERROR: character literal may only contain one codepoint: 'nope' | ||
'nope' //~ ERROR: character literal may only contain one codepoint | ||
; |
This file contains hidden or 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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
error: character literal may only contain one codepoint: 'nope' | ||
error: character literal may only contain one codepoint | ||
--> $DIR/lex-bad-char-literals-2.rs:3:5 | ||
| | ||
LL | 'nope' //~ ERROR: character literal may only contain one codepoint: 'nope' | ||
LL | 'nope' //~ ERROR: character literal may only contain one codepoint | ||
| ^^^^^^ | ||
|
||
error: aborting due to previous error | ||
error[E0601]: `main` function not found in crate `lex_bad_char_literals_2` | ||
| | ||
= note: consider adding a `main` function to `$DIR/lex-bad-char-literals-2.rs` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0601`. |
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// This test needs to the last one appearing in this file as it kills the parser | ||
static c: char = | ||
'●●' //~ ERROR: character literal may only contain one codepoint | ||
//~| ERROR: mismatched types | ||
; | ||
static c: char = '●●'; | ||
//~^ ERROR: character literal may only contain one codepoint | ||
|
||
fn main() {} | ||
fn main() { | ||
let ch: &str = '●●'; | ||
//~^ ERROR: character literal may only contain one codepoint | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
error: character literal may only contain one codepoint | ||
--> $DIR/lex-bad-char-literals-3.rs:3:5 | ||
--> $DIR/lex-bad-char-literals-3.rs:1:18 | ||
| | ||
LL | '●●' //~ ERROR: character literal may only contain one codepoint | ||
| ^^^^ | ||
LL | static c: char = '●●'; | ||
| ^^^^ | ||
help: if you meant to write a `str` literal, use double quotes | ||
| | ||
LL | "●●" //~ ERROR: character literal may only contain one codepoint | ||
| ^^^^ | ||
LL | static c: char = "●●"; | ||
| ^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/lex-bad-char-literals-3.rs:3:5 | ||
error: character literal may only contain one codepoint | ||
--> $DIR/lex-bad-char-literals-3.rs:5:20 | ||
| | ||
LL | '●●' //~ ERROR: character literal may only contain one codepoint | ||
| ^^^^ expected char, found reference | ||
LL | let ch: &str = '●●'; | ||
| ^^^^ | ||
help: if you meant to write a `str` literal, use double quotes | ||
| | ||
= note: expected type `char` | ||
found type `&'static str` | ||
LL | let ch: &str = "●●"; | ||
| ^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains hidden or 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// This test needs to the last one appearing in this file as it kills the parser | ||
static c: char = | ||
'● //~ ERROR: character literal may only contain one codepoint: '● | ||
'● //~ ERROR: character literal may only contain one codepoint | ||
; |
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
// | ||
// This test needs to the last one appearing in this file as it kills the parser | ||
static c: char = | ||
'\x10\x10' //~ ERROR: character literal may only contain one codepoint | ||
//~| ERROR: mismatched types | ||
; | ||
static c: char = '\x10\x10'; | ||
//~^ ERROR: character literal may only contain one codepoint | ||
|
||
fn main() {} | ||
fn main() { | ||
let ch: &str = '\x10\x10'; | ||
//~^ ERROR: character literal may only contain one codepoint | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
error: character literal may only contain one codepoint | ||
--> $DIR/lex-bad-char-literals-5.rs:4:5 | ||
--> $DIR/lex-bad-char-literals-5.rs:1:18 | ||
| | ||
LL | '/x10/x10' //~ ERROR: character literal may only contain one codepoint | ||
| ^^^^^^^^^^ | ||
LL | static c: char = '/x10/x10'; | ||
| ^^^^^^^^^^ | ||
help: if you meant to write a `str` literal, use double quotes | ||
| | ||
LL | "/x10/x10" //~ ERROR: character literal may only contain one codepoint | ||
| ^^^^^^^^^^ | ||
LL | static c: char = "/x10/x10"; | ||
| ^^^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/lex-bad-char-literals-5.rs:4:5 | ||
error: character literal may only contain one codepoint | ||
--> $DIR/lex-bad-char-literals-5.rs:5:20 | ||
| | ||
LL | '/x10/x10' //~ ERROR: character literal may only contain one codepoint | ||
| ^^^^^^^^^^ expected char, found reference | ||
LL | let ch: &str = '/x10/x10'; | ||
| ^^^^^^^^^^ | ||
help: if you meant to write a `str` literal, use double quotes | ||
| | ||
= note: expected type `char` | ||
found type `&'static str` | ||
LL | let ch: &str = "/x10/x10"; | ||
| ^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains hidden or 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,17 @@ | ||
fn main() { | ||
let x: &str = 'ab'; | ||
//~^ ERROR: character literal may only contain one codepoint | ||
let y: char = 'cd'; | ||
//~^ ERROR: character literal may only contain one codepoint | ||
let z = 'ef'; | ||
//~^ ERROR: character literal may only contain one codepoint | ||
|
||
if x == y {} | ||
//~^ ERROR: can't compare `&str` with `char` | ||
if y == z {} // no error here | ||
if x == z {} | ||
//~^ ERROR: can't compare `&str` with `char` | ||
|
||
let a: usize = ""; | ||
//~^ ERROR: mismatched types | ||
} |
This file contains hidden or 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,47 @@ | ||
error: character literal may only contain one codepoint | ||
--> $DIR/lex-bad-char-literals-6.rs:2:19 | ||
| | ||
LL | let x: &str = 'ab'; | ||
| ^^^^ | ||
|
||
error: character literal may only contain one codepoint | ||
--> $DIR/lex-bad-char-literals-6.rs:4:19 | ||
| | ||
LL | let y: char = 'cd'; | ||
| ^^^^ | ||
|
||
error: character literal may only contain one codepoint | ||
--> $DIR/lex-bad-char-literals-6.rs:6:13 | ||
| | ||
LL | let z = 'ef'; | ||
| ^^^^ | ||
|
||
error[E0277]: can't compare `&str` with `char` | ||
--> $DIR/lex-bad-char-literals-6.rs:9:10 | ||
| | ||
LL | if x == y {} | ||
| ^^ no implementation for `&str == char` | ||
| | ||
= help: the trait `std::cmp::PartialEq<char>` is not implemented for `&str` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/lex-bad-char-literals-6.rs:15:20 | ||
| | ||
LL | let a: usize = ""; | ||
| ^^ expected usize, found reference | ||
| | ||
= note: expected type `usize` | ||
found type `&'static str` | ||
|
||
error[E0277]: can't compare `&str` with `char` | ||
--> $DIR/lex-bad-char-literals-6.rs:12:10 | ||
| | ||
LL | if x == z {} | ||
| ^^ no implementation for `&str == char` | ||
| | ||
= help: the trait `std::cmp::PartialEq<char>` is not implemented for `&str` | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
Some errors occurred: E0277, E0308. | ||
For more information about an error, try `rustc --explain E0277`. |
This file contains hidden or 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// run-rustfix | ||
|
||
fn main() { | ||
println!("●●"); | ||
//~^ ERROR character literal may only contain one codepoint | ||
println!("{}", "●●"); //~ ERROR character literal may only contain one codepoint | ||
//~^ ERROR format argument must be a string literal | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// run-rustfix | ||
|
||
fn main() { | ||
println!('●●'); | ||
//~^ ERROR character literal may only contain one codepoint | ||
println!('●●'); //~ ERROR character literal may only contain one codepoint | ||
//~^ ERROR format argument must be a string literal | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.