forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#131656 - richard-uk1:move_empty_exponent_to_r…
…ustc_session, r=<try> move some invalid exponent detection into rustc_session This PR moves part of the exponent checks from `rustc_lexer`/`rustc_parser` into `rustc_session`. This change does not affect which programs are accepted by the complier, or the diagnostics that are reported, with one main exception. That exception is that floats or ints with suffixes beginning with `e` are rejected *after* the token stream is passed to proc macros, rather than being rejected by the parser as was the case. This gives proc macro authors more consistent access to numeric literals: currently a proc macro could interpret `1m` or `30s` but not `7eggs` or `3em`. After this change all are handled the same. The lexer will still reject input if it contains `e` followed by a number, `+`/`-`, or `_` if they are not followed by a valid integer literal (number + `_`), but this doesn't affect macro authors who just want to access alpha suffixes. This PR is a continuation of rust-lang#79912. It is also solving exactly the same problem as [rust-lang#111628](rust-lang#111628). Exponents that contain arbitrarily long underscore suffixes are handled without read-ahead by tracking the exponent start in case of invalid exponent, so the suffix start is correct. This is very much an edge-case (the user would have to write something like `1e_______________23`) but nevertheless it is handled correctly. Also adds tests for various edge cases and improves diagnostics marginally. r: `@petrochenkov,` since they reviewed rust-lang#79912.
- Loading branch information
Showing
9 changed files
with
208 additions
and
77 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
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
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
error: expected at least one digit in exponent | ||
--> $DIR/issue-91434.rs:2:11 | ||
| | ||
LL | [9; [[9E; h]]]; | ||
| ^^ | ||
|
||
error[E0425]: cannot find value `h` in this scope | ||
--> $DIR/issue-91434.rs:2:15 | ||
| | ||
LL | [9; [[9E; h]]]; | ||
| ^ not found in this scope | ||
|
||
error: expected at least one digit in exponent | ||
--> $DIR/issue-91434.rs:2:11 | ||
| | ||
LL | [9; [[9E; h]]]; | ||
| ^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0425`. |
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,16 @@ | ||
const _A: f64 = 1em; | ||
//~^ ERROR invalid suffix `em` for number literal | ||
const _B: f64 = 1e0m; | ||
//~^ ERROR invalid suffix `m` for float literal | ||
const _C: f64 = 1e_______________0m; | ||
//~^ ERROR invalid suffix `m` for float literal | ||
const _D: f64 = 1e_______________m; | ||
//~^ ERROR invalid suffix `e_______________m` for number literal | ||
|
||
// All the above patterns should not generate an error when used in a macro | ||
macro_rules! do_nothing { | ||
($($toks:tt)*) => {}; | ||
} | ||
do_nothing!(1em 1e0m 1e_______________0m 1e_______________m); | ||
|
||
fn main() {} |
Oops, something went wrong.