-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I'm seeing an internal compiler error on the following input, found by fuzz-rustc:
Code
fn main() {
a.5.2E+
}
Error output
error: expected at least one digit in exponent
--> src/main.rs:2:7
|
2 | a.5.2E+
| ^^^^^
thread 'rustc' panicked at 'unexpected components in a float token: [IdentLike("5"), Punct('.'), IdentLike("2E"), Punct('+')]', compiler/rustc_parse/src/parser/expr.rs:1041:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
The ICE happens after correctly reporting a malformed float error, so low priority. Affected versions: probably all versions since that panic was introduced, I tried nightly 2021-11-07 and stable 1.56.1 and they both show the same ICE.
Backtrace
thread 'rustc' panicked at 'unexpected components in a float token: [IdentLike("5"), Punct('.'), IdentLike("2E"), Punct('+')]', compiler/rustc_parse/src/parser/expr.rs:1041:18
stack backtrace:
0: rust_begin_unwind
at /rustc/46b8e7488eae116722196e8390c1bd2ea2e396cf/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/46b8e7488eae116722196e8390c1bd2ea2e396cf/library/core/src/panicking.rs:106:14
2: <rustc_parse::parser::Parser>::parse_dot_or_call_expr_with_
3: <rustc_parse::parser::Parser>::parse_stmt_path_start
4: <rustc_parse::parser::Parser>::parse_stmt_without_recovery
5: <rustc_parse::parser::Parser>::parse_block_tail
6: <rustc_parse::parser::Parser>::parse_fn_body
7: <rustc_parse::parser::Parser>::parse_item_common
8: <rustc_parse::parser::Parser>::parse_mod
9: rustc_parse::parse_crate_from_file
10: <rustc_session::session::Session>::time::<core::result::Result<rustc_ast::ast::Crate, rustc_errors::diagnostic_builder::DiagnosticBuilder>, rustc_interface::passes::parse::{closure#0}>
11: rustc_interface::passes::parse
12: <rustc_interface::queries::Queries>::parse
13: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
14: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}>
15: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
A quick inspection of the code shows that the similar case 1e+
is handled the same as 1e+2
:
rust/compiler/rustc_parse/src/parser/expr.rs
Lines 1031 to 1041 in 87df4dd
// 1e+ | 1e- (recovered) | |
[IdentLike(_), Punct('+' | '-')] | | |
// 1e+2 | 1e-2 | |
[IdentLike(_), Punct('+' | '-'), IdentLike(_)] | | |
// 1.2e+3 | 1.2e-3 | |
[IdentLike(_), Punct('.'), IdentLike(_), Punct('+' | '-'), IdentLike(_)] => { | |
// See the FIXME about `TokenCursor` above. | |
self.error_unexpected_after_dot(); | |
base | |
} | |
_ => panic!("unexpected components in a float token: {:?}", components), |
So if I had to guess I would say that the match is missing this one case, so 1.2e+
should be handled the same as 1.2e+3
:
// 1.2e+ | 1.2e- (recovered)
[IdentLike(_), Punct('+' | '-'), IdentLike(_), Punct('+' | '-')] |
But no idea what does that code even do, it has a FIXME by @petrochenkov so maybe he knows better.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.