Skip to content
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

thread 'rustc' panicked at 'unexpected components in a float token #90728

Closed
Badel2 opened this issue Nov 9, 2021 · 1 comment · Fixed by #90927
Closed

thread 'rustc' panicked at 'unexpected components in a float token #90728

Badel2 opened this issue Nov 9, 2021 · 1 comment · Fixed by #90927
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Badel2
Copy link
Contributor

Badel2 commented Nov 9, 2021

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:

// 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.

@Badel2 Badel2 added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 9, 2021
@terrarier2111
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants