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 'assertion failed: !suggestion.is_empty()', compiler/rustc_errors/src/diagnostic.rs:342:9 #91461

Closed
Badel2 opened this issue Dec 2, 2021 · 4 comments · Fixed by #91634
Assignees
Labels
A-frontend Area: frontend (errors, parsing and HIR) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Badel2
Copy link
Contributor

Badel2 commented Dec 2, 2021

I'm seeing an internal compiler error on the following input, found by fuzz-rustc:

Code

#[d=n(_:d:,)]

Error output

error: expected identifier, found reserved identifier `_`
 --> src/lib.rs:1:7
  |
1 | #[d=n(_:d:,)]
  |       ^ expected identifier, found reserved identifier

error: expected type, found `,`
 --> src/lib.rs:1:11
  |
1 | #[d=n(_:d:,)]
  |     -    -^ expected type
  |     |    |
  |     |    tried to parse a type due to this type ascription
  |     while parsing this struct
  |
  = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
  = note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information

thread 'rustc' panicked at 'assertion failed: !suggestion.is_empty()', compiler/rustc_errors/src/diagnostic.rs:342:9

Affected versions: I tried nightly 2021-12-01 and stable 1.57 and they both show the same ICE.

Backtrace

   Compiling playground v0.0.1 (/playground)
error: expected identifier, found reserved identifier `_`
 --> src/lib.rs:1:7
  |
1 | #[d=n(_:d:,)]
  |       ^ expected identifier, found reserved identifier

error: expected type, found `,`
 --> src/lib.rs:1:11
  |
1 | #[d=n(_:d:,)]
  |     -    -^ expected type
  |     |    |
  |     |    tried to parse a type due to this type ascription
  |     while parsing this struct
  |
  = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
  = note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information

thread 'rustc' panicked at 'assertion failed: !suggestion.is_empty()', compiler/rustc_errors/src/diagnostic.rs:342:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/48a5999fceeea84a8971634355287faa349909d4/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/48a5999fceeea84a8971634355287faa349909d4/library/core/src/panicking.rs:107:14
   2: core::panicking::panic
             at /rustc/48a5999fceeea84a8971634355287faa349909d4/library/core/src/panicking.rs:48:5
   3: <rustc_errors::diagnostic::Diagnostic>::multipart_suggestion_with_style
   4: <rustc_errors::diagnostic_builder::DiagnosticBuilder>::multipart_suggestion
   5: <rustc_parse::parser::Parser>::collect_tokens_for_expr::<<rustc_parse::parser::Parser>::parse_dot_or_call_expr::{closure#0}>
   6: <rustc_parse::parser::Parser>::parse_prefix_expr
   7: <rustc_parse::parser::Parser>::parse_assoc_expr_with
   8: <rustc_parse::parser::Parser>::collect_tokens_no_attrs::<rustc_ast::ptr::P<rustc_ast::ast::Expr>, <rustc_parse::parser::Parser>::parse_expr_force_collect::{closure#0}>
   9: <rustc_parse::parser::Parser>::parse_attr_item::{closure#0}
  10: <rustc_parse::parser::Parser>::parse_attribute
  11: <rustc_parse::parser::Parser>::parse_outer_attributes
  12: <rustc_parse::parser::Parser>::parse_mod
  13: rustc_parse::parse_crate_from_file
  14: <rustc_session::session::Session>::time::<core::result::Result<rustc_ast::ast::Crate, rustc_errors::diagnostic_builder::DiagnosticBuilder>, rustc_interface::passes::parse::{closure#0}>
  15: <rustc_interface::queries::Queries>::parse
  16: <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>>
  17: 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#1}>
  18: <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.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.59.0-nightly (48a5999fc 2021-12-01) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `playground` due to 2 previous errors

@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 Dec 2, 2021
@inquisitivecrystal inquisitivecrystal added A-attributes Area: #[attributes(..)] P-low Low priority labels Dec 2, 2021
@asquared31415
Copy link
Contributor

slightly simpler example not using attributes here

the name outside the parentheses and the name between the two colons can be arbitrary, the parentheses, underscore, and comma all appear to matter

@inquisitivecrystal inquisitivecrystal added A-frontend Area: frontend (errors, parsing and HIR) and removed A-attributes Area: #[attributes(..)] labels Dec 3, 2021
@terrarier2111
Copy link
Contributor

terrarier2111 commented Dec 4, 2021

I found a fix for this, but currently i am only emitting a suggestion for transforming the input into a struct:

fn main() {
    a(_:b:,)
}
error: invalid `struct` delimiters or `fn` call arguments
 --> errors.rs:2:5
  |
2 |     a(_:b:,)
  |     ^^^^^^^^
  |
help: if `a` is a struct, use braces as delimiters
  |
2 |     a { _:b:, }
  |       ~       ~

how do you guys think should i do a function suggestion? Should i just remove the parameter? Or should i remove the function suggestion altogether and just emit the struct suggestion? or something completely different?

here is an example how the same diagnostic's output looks like for a more sane input:
https://github.com/rust-lang/rust/blob/master/src/test/ui/parser/recover-from-bad-variant.rs
https://github.com/rust-lang/rust/blob/master/src/test/ui/parser/recover-from-bad-variant.stderr

@Badel2
Copy link
Contributor Author

Badel2 commented Dec 4, 2021

I wouldn't give much thought to suggestions, as it's unlikely that a human will enter this input. So I would just remove the suggestions if they are most likely wrong. For example the struct suggestion is invalid code because structs cannot use _ as a field name (right?). And I'm not sure what kind of code would use two colons :b:, it's most likely a weird typo, so a generic "unexpected token" error should be fine.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 6, 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
A-frontend Area: frontend (errors, parsing and HIR) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority 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.

5 participants