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

meet panic when execute cargo fmt #6448

Closed
atenjin opened this issue Jan 16, 2025 · 8 comments
Closed

meet panic when execute cargo fmt #6448

atenjin opened this issue Jan 16, 2025 · 8 comments

Comments

@atenjin
Copy link

atenjin commented Jan 16, 2025

When I execute cargo fmt in the root for my project, I meet this following error:

My rustfmt.toml is

# Basic
max_width = 100
use_small_heuristics = "Max"
# Imports
imports_granularity = "Crate"
reorder_imports = true
# Consistency
newline_style = "Unix"
# Misc
chain_width = 80
spaces_around_ranges = false
binop_separator = "Front"
reorder_impl_items = false
match_arm_leading_pipes = "Preserve"
match_arm_blocks = true
match_block_trailing_comma = false
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
merge_derives = false
cargo +nightly fmt --all

thread 'main' panicked at src/tools/rustfmt/src/items.rs:562:10:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7f08b9ef7a8a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h2c0c06aa7c9e2add
   1:     0x7f08ba612d66 - core::fmt::write::h9c526b1ea92841e3
   2:     0x7f08bb56c851 - std::io::Write::write_fmt::hdc16e41b79fd4ad2
   3:     0x7f08b9ef78e2 - std::sys::backtrace::BacktraceLock::print::h5ef515fa7ec57ba7
   4:     0x7f08b9ef9e87 - std::panicking::default_hook::{{closure}}::h2ee6ae16a7bfa7c1
   5:     0x7f08b9ef9c70 - std::panicking::default_hook::h1030932e69c8304a
   6:     0x7f08b905def8 - std[933200be1dd485a2]::panicking::update_hook::<alloc[2b6aed300e53d0dc]::boxed::Box<rustc_driver_impl[e473363a427c35f5]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7f08b9efa6d3 - std::panicking::rust_panic_with_hook::h664081a22069a2d8
   8:     0x7f08b9efa396 - std::panicking::begin_panic_handler::{{closure}}::haf56db793df1edb0
   9:     0x7f08b9ef7f59 - std::sys::backtrace::__rust_end_short_backtrace::h4a844f15d95ff9a0
  10:     0x7f08b9efa08d - rust_begin_unwind
  11:     0x7f08b6ba46d0 - core::panicking::panic_fmt::hdddd98bcd9eb12ec
  12:     0x7f08b767efcc - core::panicking::panic::h813fafa00978a35d
  13:     0x7f08b809b939 - core::option::unwrap_failed::h2359442be6ceabba
  14:     0x55644c9b78b3 - <rustfmt_nightly[64cb2d06014deef]::visitor::FmtVisitor>::visit_item
  15:     0x55644c98d9b1 - <rustfmt_nightly[64cb2d06014deef]::visitor::FmtVisitor>::visit_items_with_reordering
  16:     0x55644c9b12bf - <rustfmt_nightly[64cb2d06014deef]::visitor::FmtVisitor>::visit_item
  17:     0x55644c98d9b1 - <rustfmt_nightly[64cb2d06014deef]::visitor::FmtVisitor>::visit_items_with_reordering
  18:     0x55644c9bc9db - <rustfmt_nightly[64cb2d06014deef]::visitor::FmtVisitor>::format_separate_mod
  19:     0x55644c816e1f - <scoped_tls[26100b810e5b4714]::ScopedKey<rustc_span[70591d252facc109]::SessionGlobals>>::with::<<rustfmt_nightly[64cb2d06014deef]::Session<std[933200be1dd485a2]::io::stdio::Stdout>>::format_input_inner::{closure#0}, core[3ec68fd79f849e66]::result::Result<rustfmt_nightly[64cb2d06014deef]::FormatReport, rustfmt_nightly[64cb2d06014deef]::ErrorKind>>
  20:     0x55644c831a7b - rustfmt[56ccc4014d54a22]::format_and_emit_report::<std[933200be1dd485a2]::io::stdio::Stdout>
  21:     0x55644c82f626 - rustfmt[56ccc4014d54a22]::execute
  22:     0x55644c82b673 - rustfmt[56ccc4014d54a22]::main
  23:     0x55644c81fb53 - std[933200be1dd485a2]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  24:     0x55644c8200d9 - std[933200be1dd485a2]::rt::lang_start::<()>::{closure#0}
  25:     0x7f08bb461ec4 - std::rt::lang_start_internal::h67c614368c6ee42e
  26:     0x55644c832cc8 - main
  27:     0x7f08b5719d90 - <unknown>
  28:     0x7f08b5719e40 - __libc_start_main
  29:     0x55644c813379 - <unknown>
  30:                0x0 - <unknown>

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

query stack during

 panic:
end of query stack

rustc version: 1.86.0-nightly (b1a7dfb91 2025-01-10)
platform: x86_64-unknown-linux-gnu

rustc-ice-2025-01-16T15_39_37-1352442.txt

Sorry for my code is private now, can not share with you.

Even I switch to stable toolchain, it still print same error:

-->$ cargo fmt
Warning: can't set `imports_granularity = Crate`, unstable features are only available in nightly channel.
Warning: can't set `reorder_impl_items = false`, unstable features are only available in nightly channel.
Warning: can't set `spaces_around_ranges = false`, unstable features are only available in nightly channel.
Warning: can't set `binop_separator = Front`, unstable features are only available in nightly channel.
Warning: can't set `match_arm_blocks = true`, unstable features are only available in nightly channel.
Warning: can't set `trailing_semicolon = false`, unstable features are only available in nightly channel.
Warning: can't set `trailing_comma = Vertical`, unstable features are only available in nightly channel.
thread 'main' panicked at src/tools/rustfmt/src/items.rs:547:10:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7f6e192ee3e5 - std::backtrace_rs::backtrace::libunwind::trace::h649ab3318d3445c5
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f6e192ee3e5 - std::backtrace_rs::backtrace::trace_unsynchronized::hf4bb60c3387150c3
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f6e192ee3e5 - std::sys::backtrace::_print_fmt::hd9186c800e44bd00
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:65:5
   3:     0x7f6e192ee3e5 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1b9dad2a88e955ff
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:40:26
   4:     0x7f6e1933deeb - core::fmt::rt::Argument::fmt::h351a7824f737a6a0
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/rt.rs:173:76
   5:     0x7f6e1933deeb - core::fmt::write::h4b5a1270214bc4a7
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/mod.rs:1182:21
   6:     0x7f6e192e2f6f - std::io::Write::write_fmt::hd04af345a50c312d
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/io/mod.rs:1827:15
   7:     0x7f6e192f0bd1 - std::sys::backtrace::BacktraceLock::print::h68d41b51481bce5c
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:43:9
   8:     0x7f6e192f0bd1 - std::panicking::default_hook::{{closure}}::h96ab15e9936be7ed
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:269:22
   9:     0x7f6e192f08ac - std::panicking::default_hook::h3cacb9c27561ad33
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:296:9
  10:     0x7f6e15a93420 - std[1f2242ed6435445e]::panicking::update_hook::<alloc[7b1462a1eb55c293]::boxed::Box<rustc_driver_impl[8683aa37472b7dde]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x7f6e192f159f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hce7569f4ca5d1b64
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2084:9
  12:     0x7f6e192f159f - std::panicking::rust_panic_with_hook::hfe205f6954b2c97b
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:808:13
  13:     0x7f6e192f1193 - std::panicking::begin_panic_handler::{{closure}}::h6cb44b3a50f28c44
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:667:13
  14:     0x7f6e192ee8a9 - std::sys::backtrace::__rust_end_short_backtrace::hf1c1f2a92799bb0e
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:168:18
  15:     0x7f6e192f0e54 - rust_begin_unwind
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
  16:     0x7f6e1933a4a3 - core::panicking::panic_fmt::h3d8fc78294164da7
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:74:14
  17:     0x7f6e1933a52c - core::panicking::panic::hec978767ec2d35ff
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:148:5
  18:     0x7f6e1933a299 - core::option::unwrap_failed::hba6b08832f9ce30b
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/option.rs:2020:5
  19:     0x55f367e13120 - <rustfmt_nightly[58d7446b4e209441]::visitor::FmtVisitor>::visit_enum
  20:     0x55f367e751ad - <rustfmt_nightly[58d7446b4e209441]::visitor::FmtVisitor>::visit_item
  21:     0x55f367e57b46 - <rustfmt_nightly[58d7446b4e209441]::visitor::FmtVisitor>::visit_items_with_reordering
  22:     0x55f367e75682 - <rustfmt_nightly[58d7446b4e209441]::visitor::FmtVisitor>::visit_item
  23:     0x55f367e57b46 - <rustfmt_nightly[58d7446b4e209441]::visitor::FmtVisitor>::visit_items_with_reordering
  24:     0x55f367e7937b - <rustfmt_nightly[58d7446b4e209441]::visitor::FmtVisitor>::format_separate_mod
  25:     0x55f367ce4a4e - <rustfmt_nightly[58d7446b4e209441]::Session<std[1f2242ed6435445e]::io::stdio::Stdout>>::format_input_inner::{closure#0}
  26:     0x55f367cf86e2 - rustfmt[e1d275c3c6617f77]::format_and_emit_report::<std[1f2242ed6435445e]::io::stdio::Stdout>
  27:     0x55f367cf6991 - rustfmt[e1d275c3c6617f77]::execute
  28:     0x55f367cf29ae - rustfmt[e1d275c3c6617f77]::main
  29:     0x55f367cde3b3 - std[1f2242ed6435445e]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  30:     0x55f367ce05c9 - std[1f2242ed6435445e]::rt::lang_start::<()>::{closure#0}
  31:     0x7f6e192d37f0 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h2feec6363bd28ad6
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:284:13
  32:     0x7f6e192d37f0 - std::panicking::try::do_call::h71b24ad3a8e797d5
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557:40
  33:     0x7f6e192d37f0 - std::panicking::try::h8412d1bfb4bcbcc1
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521:19
  34:     0x7f6e192d37f0 - std::panic::catch_unwind::h2053d3ee5bd8db53
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350:14
  35:     0x7f6e192d37f0 - std::rt::lang_start_internal::{{closure}}::h82eb98fe4f8e75b8
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/rt.rs:141:48
  36:     0x7f6e192d37f0 - std::panicking::try::do_call::h793dba66a0bbd3de
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557:40
  37:     0x7f6e192d37f0 - std::panicking::try::he09b629b3ba06846
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521:19
  38:     0x7f6e192d37f0 - std::panic::catch_unwind::h7964c913fc871155
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350:14
  39:     0x7f6e192d37f0 - std::rt::lang_start_internal::h5e7c81cecd7f0954
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/rt.rs:141:20
  40:     0x55f367cf98a8 - main
  41:     0x7f6e12519d90 - <unknown>
  42:     0x7f6e12519e40 - __libc_start_main
  43:     0x55f367cccb09 - <unknown>
  44:                0x0 - <unknown>

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: rustc 1.81.0 (eeb90cda1 2024-09-04) running on x86_64-unknown-linux-gnu
@ytmimi
Copy link
Contributor

ytmimi commented Jan 16, 2025

@atenjin if you can't share the code can you at least create a minimal reproduction? If not then there's nothing the team can do to help

@ytmimi ytmimi added the needs-mcve needs a Minimal Complete and Verifiable Example label Jan 16, 2025
@atenjin
Copy link
Author

atenjin commented Jan 17, 2025

@atenjin if you can't share the code can you at least create a minimal reproduction? If not then there's nothing the team can do to help

it's opensouce for now, this is the link, branch refactor.parse_eph_key.
https://github.com/kzero-xyz/kzero/tree/refactor/parse_eph_key

in the root dir, or enter dir frame/zklogin, then execute cargo fmt or cargo +nightly fmt, it will print above error.

@ytmimi
Copy link
Contributor

ytmimi commented Jan 17, 2025

It would be a great help if you could narrow down which file is being formatted when the panic occurs

@atenjin
Copy link
Author

atenjin commented Jan 18, 2025

It would be a great help if you could narrow down which file is being formatted when the panic occurs

I can not ensure which file, but I can ensure in crate frame/zklogin

@atenjin
Copy link
Author

atenjin commented Jan 18, 2025

It would be a great help if you could narrow down which file is being formatted when the panic occurs

I tested, you can enter dir cd ./frame/zklogin, and execute: rustfmt +nightly ./src/lib.rs or rustfmt ./src/lib.rs then you can replay. So the file is ./frame/zklogin/src/lib.rs

@ytmimi
Copy link
Contributor

ytmimi commented Jan 24, 2025

It's possible that the error is in one of the modules that src/lib.rs imports. When you have time, please investigate to make sure the issue is in src/lib.rs. Identifying the file is a good start, but getting this down to a small code snippet that you can post inline would be even better.

@atenjin
Copy link
Author

atenjin commented Jan 29, 2025

It's possible that the error is in one of the modules that src/lib.rs imports. When you have time, please investigate to make sure the issue is in src/lib.rs. Identifying the file is a good start, but getting this down to a small code snippet that you can post inline would be even better.

    #[pallet::event]
    #[pallet::generate_deposit(pub(super) fn deposit_event)]
    pub enum Event<T: Config>
    where
        T::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
        <<T as Config>::Extrinsic as Extrinsic>::SignaturePayload: SignaturePayloadExt,
        <<<T as Config>::Extrinsic as Extrinsic>::SignaturePayload as SignaturePayload>::SignatureAddress: TryIntoEphPubKey,
    {
        ZkLoginExecuted { result: DispatchResult },
    }

This part, I copy it to a empty project and execute format can replay

Especially, this line is the reason to cause this panic:

<<<T as Config>::Extrinsic as Extrinsic>::SignaturePayload as SignaturePayload>::SignatureAddress: TryIntoEphPubKey,

@ytmimi
Copy link
Contributor

ytmimi commented Jan 29, 2025

Thank you for taking the time to look into this. After reviewing the snippet and the panic details this is definitely a duplicate of #5738

@ytmimi ytmimi closed this as completed Jan 29, 2025
@ytmimi ytmimi added duplicate and removed needs-mcve needs a Minimal Complete and Verifiable Example labels Jan 29, 2025
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

2 participants