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

rustfmt_nightly: query stack during panic: end of query stack #6099

Open
mzacho opened this issue Feb 27, 2024 · 15 comments
Open

rustfmt_nightly: query stack during panic: end of query stack #6099

mzacho opened this issue Feb 27, 2024 · 15 comments

Comments

@mzacho
Copy link

mzacho commented Feb 27, 2024

Hi,

When attempting to run cargo fmt on a the ill-typed (or maybe not even parsable?) library consisting of two files:

lib.rs:

mod foo;

foo.rs

const BAR = 42;

the compiler unexpectedly panics due to a failed assertion:

thread 'main' panicked at compiler/rustc_errors/src/lib.rs:565:9:
assertion failed: self.stashed_diagnostics.is_empty()

with rustc 1.78.0-nightly (fc3800f65 2024-02-26). Full stack-trace:

rustc-ice-2024-02-27T19_28_13-1514879.txt

I'm happy to work on this, but I'm a bit clueless as to what the issue is.

@calebcartwright
Copy link
Member

Thanks for the report, wondering if this is related to (#6082, rust-lang/rust#121487) and fixed by rust-lang/rust#121301

@nnethercote
Copy link
Contributor

rust-lang/rust#121487 should fix this.

@ytmimi
Copy link
Contributor

ytmimi commented Mar 4, 2024

@mzacho when you have a moment could you double check if this is resolved on the latest nightly?

@wmmc88
Copy link

wmmc88 commented Mar 6, 2024

@ytmimi not OP, but i just checked on latest nightly (1.78.0-nightly (b6d2d841b 2024-03-05)) and I still have rustfmt crashing, although the stack is different:

thread 'main' panicked at src\tools\rustfmt\src\parse\session.rs:40:9:
silent emitter attempted to translate a diagnostic
stack backtrace:
   0:     0x7ff8f04d3641 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1e8839368d0f8ea2
   1:     0x7ff8f0505a3b - core::fmt::write_internal::h7df84b0bd19a91fc
   2:     0x7ff8f04c9c8a - <std::io::IoSlice as core::fmt::Debug>::fmt::h40bb585663c296ad
   3:     0x7ff8f04d346a - std::sys_common::backtrace::lock::haaab04a5a6ea97f3
   4:     0x7ff8f04d660f - std::panicking::default_hook::h20b56c3ef0f4d280
   5:     0x7ff8f04d62b9 - std::panicking::default_hook::h20b56c3ef0f4d280
   6:     0x7ff8f4ef90c5 - <wasmparser[386d3e72a2020ab8]::validator::names::ComponentName as core[740ffb2decc37d3]::fmt::Debug>::fmt
   7:     0x7ff8f04d6c33 - std::panicking::rust_panic_with_hook::h3af291445738d743
   8:     0x7ff8f04d6a9b - <std::panicking::begin_panic_handler::StaticStrPayload as core::panic::PanicPayload>::take_box::h3fc74e926739df0e
   9:     0x7ff8f04d3f49 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1e8839368d0f8ea2
  10:     0x7ff8f04d6786 - rust_begin_unwind
  11:     0x7ff8f052c2a7 - core::panicking::panic_fmt::hf6c7b67361c454bc
  12:     0x7ff6910a649e - <unknown>
  13:     0x7ff6910a4108 - <unknown>
  14:     0x7ff8f626154c - <rustc_parse[f5edc4ae78f12cf2]::parser::diagnostics::UnaryFixity as core[740ffb2decc37d3]::fmt::Display>::fmt
  15:     0x7ff8f6208f30 - <rustc_parse[f5edc4ae78f12cf2]::errors::ExpectedIdentifierFound>::new
  16:     0x7ff8f4d0612f - <rustc_parse[f5edc4ae78f12cf2]::parser::expr::CondChecker as rustc_ast[973cc0afb5b54271]::mut_visit::MutVisitor>::visit_expr
  17:     0x7ff8f4bea15e - <rustc_ast_passes[8fab3d9e89b724a7]::ast_validation::AstValidator as rustc_ast[973cc0afb5b54271]::visit::Visitor>::visit_assoc_item
  18:     0x7ff8f4bea2ef - <rustc_ast_passes[8fab3d9e89b724a7]::ast_validation::AstValidator as rustc_ast[973cc0afb5b54271]::visit::Visitor>::visit_assoc_item
  19:     0x7ff8f3c9af20 - rustc_ast_passes[8fab3d9e89b724a7]::ast_validation::check_crate
  20:     0x7ff8f3cc6b99 - rustc_parse[f5edc4ae78f12cf2]::parser::attr_wrapper::has_cfg_or_cfg_attr
  21:     0x7ff8f3c9b98a - rustc_parse[f5edc4ae78f12cf2]::source_file_to_stream
  22:     0x7ff8f3c9b70e - rustc_parse[f5edc4ae78f12cf2]::new_parser_from_file
  23:     0x7ff8f3c9b3b0 - rustc_parse[f5edc4ae78f12cf2]::maybe_new_parser_from_source_str
  24:     0x7ff6910c8380 - <unknown>
  25:     0x7ff690ff8807 - <unknown>
  26:     0x7ff691087508 - <unknown>
  27:     0x7ff690ffbf08 - <unknown>
  28:     0x7ff691073f87 - <unknown>
  29:     0x7ff6910750c5 - <unknown>
  30:     0x7ff69108f1ce - <unknown>
  31:     0x7ff69108bcb1 - <unknown>
  32:     0x7ff6911894f3 - <unknown>
  33:     0x7ff69111638b - <unknown>
  34:     0x7ff6911042e9 - <unknown>
  35:     0x7ff6910ffa9c - <unknown>
  36:     0x7ff6910f6f36 - <unknown>
  37:     0x7ff691100d62 - <unknown>
  38:     0x7ff6910f6f36 - <unknown>
  39:     0x7ff691100d62 - <unknown>
  40:     0x7ff6910f6f36 - <unknown>
  41:     0x7ff6911056ba - <unknown>
  42:     0x7ff690f8258a - <unknown>
  43:     0x7ff690f88253 - <unknown>
  44:     0x7ff690f857b3 - <unknown>
  45:     0x7ff690f7bcfd - <unknown>
  46:     0x7ff690f6afd3 - <unknown>
  47:     0x7ff690f856ef - <unknown>
  48:     0x7ff690f68f0a - <unknown>
  49:     0x7ff690f668d8 - <unknown>
  50:     0x7ff690f8f136 - <unknown>
  51:     0x7ff690f75aac - <unknown>
  52:     0x7ff8f04bbfb2 - std::rt::lang_start_internal::h59f7001875d06b74
  53:     0x7ff690f6becc - <unknown>
  54:     0x7ff6912fa71c - <unknown>
  55:     0x7ff995dd257d - BaseThreadInitThunk
  56:     0x7ff99704aa58 - RtlUserThreadStart

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

note: we would appreciate a bug report: https://github.com/rust-lang/rustfmt/issues/new?labels=bug

note: please attach the file at `D:\git-repos\github\windows-drivers-rs.git\worktrees-folder\better-macro-must-use\rustc-ice-2024-03-06T01_42_41-10216.txt` to your bug report

query stack during panic:
end of query stack

rustc-ice-2024-03-06T01_42_41-10216.txt:

thread 'main' panicked at src\tools\rustfmt\src\parse\session.rs:40:9:
silent emitter attempted to translate a diagnostic
stack backtrace:
   0:     0x7ff8f04bd764 - std::backtrace::Backtrace::force_capture::h7ea177fe0a8bf95d
   1:     0x7ff8f04bd6c4 - std::backtrace::Backtrace::force_capture::h7ea177fe0a8bf95d
   2:     0x7ff8f4ef9233 - <wasmparser[386d3e72a2020ab8]::validator::names::ComponentName as core[740ffb2decc37d3]::fmt::Debug>::fmt
   3:     0x7ff8f04d6c33 - std::panicking::rust_panic_with_hook::h3af291445738d743
   4:     0x7ff8f04d6a9b - <std::panicking::begin_panic_handler::StaticStrPayload as core::panic::PanicPayload>::take_box::h3fc74e926739df0e
   5:     0x7ff8f04d3f49 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1e8839368d0f8ea2
   6:     0x7ff8f04d6786 - rust_begin_unwind
   7:     0x7ff8f052c2a7 - core::panicking::panic_fmt::hf6c7b67361c454bc
   8:     0x7ff6910a649e - <unknown>
   9:     0x7ff6910a4108 - <unknown>
  10:     0x7ff8f626154c - <rustc_parse[f5edc4ae78f12cf2]::parser::diagnostics::UnaryFixity as core[740ffb2decc37d3]::fmt::Display>::fmt
  11:     0x7ff8f6208f30 - <rustc_parse[f5edc4ae78f12cf2]::errors::ExpectedIdentifierFound>::new
  12:     0x7ff8f4d0612f - <rustc_parse[f5edc4ae78f12cf2]::parser::expr::CondChecker as rustc_ast[973cc0afb5b54271]::mut_visit::MutVisitor>::visit_expr
  13:     0x7ff8f4bea15e - <rustc_ast_passes[8fab3d9e89b724a7]::ast_validation::AstValidator as rustc_ast[973cc0afb5b54271]::visit::Visitor>::visit_assoc_item
  14:     0x7ff8f4bea2ef - <rustc_ast_passes[8fab3d9e89b724a7]::ast_validation::AstValidator as rustc_ast[973cc0afb5b54271]::visit::Visitor>::visit_assoc_item
  15:     0x7ff8f3c9af20 - rustc_ast_passes[8fab3d9e89b724a7]::ast_validation::check_crate
  16:     0x7ff8f3cc6b99 - rustc_parse[f5edc4ae78f12cf2]::parser::attr_wrapper::has_cfg_or_cfg_attr
  17:     0x7ff8f3c9b98a - rustc_parse[f5edc4ae78f12cf2]::source_file_to_stream
  18:     0x7ff8f3c9b70e - rustc_parse[f5edc4ae78f12cf2]::new_parser_from_file
  19:     0x7ff8f3c9b3b0 - rustc_parse[f5edc4ae78f12cf2]::maybe_new_parser_from_source_str
  20:     0x7ff6910c8380 - <unknown>
  21:     0x7ff690ff8807 - <unknown>
  22:     0x7ff691087508 - <unknown>
  23:     0x7ff690ffbf08 - <unknown>
  24:     0x7ff691073f87 - <unknown>
  25:     0x7ff6910750c5 - <unknown>
  26:     0x7ff69108f1ce - <unknown>
  27:     0x7ff69108bcb1 - <unknown>
  28:     0x7ff6911894f3 - <unknown>
  29:     0x7ff69111638b - <unknown>
  30:     0x7ff6911042e9 - <unknown>
  31:     0x7ff6910ffa9c - <unknown>
  32:     0x7ff6910f6f36 - <unknown>
  33:     0x7ff691100d62 - <unknown>
  34:     0x7ff6910f6f36 - <unknown>
  35:     0x7ff691100d62 - <unknown>
  36:     0x7ff6910f6f36 - <unknown>
  37:     0x7ff6911056ba - <unknown>
  38:     0x7ff690f8258a - <unknown>
  39:     0x7ff690f88253 - <unknown>
  40:     0x7ff690f857b3 - <unknown>
  41:     0x7ff690f7bcfd - <unknown>
  42:     0x7ff690f6afd3 - <unknown>
  43:     0x7ff690f856ef - <unknown>
  44:     0x7ff690f68f0a - <unknown>
  45:     0x7ff690f668d8 - <unknown>
  46:     0x7ff690f8f136 - <unknown>
  47:     0x7ff690f75aac - <unknown>
  48:     0x7ff8f04bbfb2 - std::rt::lang_start_internal::h59f7001875d06b74
  49:     0x7ff690f6becc - <unknown>
  50:     0x7ff6912fa71c - <unknown>
  51:     0x7ff995dd257d - BaseThreadInitThunk
  52:     0x7ff99704aa58 - RtlUserThreadStart


rustc version: 1.78.0-nightly (b6d2d841b 2024-03-05)
platform: x86_64-pc-windows-msvc

@ytmimi
Copy link
Contributor

ytmimi commented Mar 6, 2024

@wmmc88 thanks for taking the time to look into this. I believe we're still waiting on #6082 to be resolved. I'm hopeful that rust-lang/rust#121301 will fix the issue on nightly once it's merged 🤞🏼

@ytmimi
Copy link
Contributor

ytmimi commented Mar 7, 2024

@mzacho or @wmmc88 when either of you have a moment can you confirm if this is resolved with the latest nightly. I've been testing with the latest nightly (rustfmt 1.7.0-nightly (7d3702e4 2024-03-06)) and I think the panic is resolved 🎉. Would love some confirmation from someone on that as well.

steps to verify:

  1. rustup install nightly or rustup install nightly-2024-03-07
  2. rustfmt +nightly

@wmmc88
Copy link

wmmc88 commented Mar 7, 2024

@ytmimi Latest nightly cargo fmt works for me again. Thanks!

@ytmimi
Copy link
Contributor

ytmimi commented Mar 7, 2024

@namanlp since you reached out on Zulip I was wondering if you'd want to get a little hands on experience adding a quick test case for this issue to close it out? I can explain more of the details of what I'm thinking on Zulip if you're interested.

@namanlp
Copy link

namanlp commented Mar 10, 2024

Hi there,

I do understand the issue as well as the fix. Can you please tell me what to include in the test?

( I did see a few other tests to know how the tests should look in general )

Thank You

@ytmimi
Copy link
Contributor

ytmimi commented Mar 11, 2024

@namanlp normally test cases are added to the tests/source directory, and formatted code is added to tests/target with the same name.

This one is a little different because const BAR = 42; will be rejected by the parser. You should see a similar error message if you run rustfmt on that input:

error: missing type for `const` item
 --> <stdin>:1:10
  |
1 | const BAR = 42;
  |          ^ help: provide a type for the item: `: <type>`

You should be able to add another parser error test to src/test/parser.rs

@namanlp
Copy link

namanlp commented Mar 11, 2024

Hi @ytmimi ,

Yes, I can see that error.

So, as per my understanding, I have to add the test files to tests/parser , and then, add a similar driver code here src/test/parser.rs

Is that ok?

@mzacho
Copy link
Author

mzacho commented Mar 11, 2024

@mzacho when you have a moment could you double check if this is resolved on the latest nightly?

Confirmed on nightly-2024-03-10.

@namanlp I think you can do something similar to the test that's in place for issue-4126 (in tests/parser/issue-4126 and src/test/parser.rs, yes)

@ytmimi
Copy link
Contributor

ytmimi commented Mar 12, 2024

@mzacho thanks for confirming!


So, as per my understanding, I have to add the test files to tests/parser , and then, add a similar driver code here src/test/parser.rs

Is that ok?

@namanlp Yup, that should be it. I'd take a similar approach to the other tests in src/test/parser.rs

If you want, you can also add the code snippet from #6082 (comment) as a separate test case, which deals with the same issue and contains a complete code snippet without any parse errors. No problem if not. If you choose to also include that code snippet all you'd need to do is add it to a file in the tests/target directory, which is typically what you'd do when adding test cases to rustfmt.

@mzacho
Copy link
Author

mzacho commented Mar 31, 2024

@namanlp are you still working on this? Otherwise I'd like to pick it up

@namanlp
Copy link

namanlp commented Apr 1, 2024

Hi, Sorry, this issue completely skipped out of my mind 😅

I will make a PR today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants