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

Regression: .format from itertools started runtime panicking with rustc 1.71.0 #110717

Closed
flip1995 opened this issue Apr 23, 2023 · 2 comments · Fixed by #110721
Closed

Regression: .format from itertools started runtime panicking with rustc 1.71.0 #110717

flip1995 opened this issue Apr 23, 2023 · 2 comments · Fixed by #110721
Assignees
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@flip1995
Copy link
Member

Code

I tried this code:

use itertools::Itertools;
fn main() {
    let mut v = Vec::new();
    v.push("foo");
    assert!(
        v.is_empty(),
        "{}",
        v.iter().format(", "),
    );
}

Playground

I expected to see this happen: No panic during runtime

Instead, this happened: Panicked during runtime

Format: was already formatted once
thread 'main' panicked at 'thread 'main' panicked at 'Format: was already formatted once', /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/itertools-0.10.5/src/format.rs:81:21
stack backtrace:
   0:     0x55575722e373 - std::backtrace_rs::backtrace::libunwind::trace::hb9265895128f1f9c
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x55575722e373 - std::backtrace_rs::backtrace::trace_unsynchronized::h028901cb3a0224b1
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55575722e373 - std::sys_common::backtrace::_print_fmt::hfa5c37f64d314fee
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x55575722e373 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5b30f1684e8bd3e6
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x55575724982f - core::fmt::write::h997ecd0e22e2af7a
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/core/src/fmt/mod.rs:1247:17
   5:     0x55575722c621 - std::io::Write::write_fmt::h291317e85b978e13
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/io/mod.rs:1698:15
   6:     0x55575722e185 - std::sys_common::backtrace::_print::h0133b24def7b99d9
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x55575722e185 - std::sys_common::backtrace::print::h4a42174c7f3bd207
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x55575722f4ff - std::panicking::default_hook::{{closure}}::h0847452fe926d6e5
   9:     0x55575722f1b7 - std::panicking::default_hook::hbcdd7833994c05d0
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:293:9
  10:     0x55575722fa21 - std::panicking::rust_panic_with_hook::hb55c52c8e21298f0
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:700:13
  11:     0x555757215394 - std::panicking::begin_panic::{{closure}}::hb08efbb470f664d6
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:624:9
  12:     0x5557572152bd - std::sys_common::backtrace::__rust_end_short_backtrace::hbf8634da0334b4e2
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x555757215307 - std::panicking::begin_panic::h61b21b87c2e55e8f
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:623:12
  14:     0x555757214cdb - itertools::format::Format<I>::format::heb0f74abc06f4991
                               at /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/itertools-0.10.5/src/format.rs:81:21
  15:     0x5557572149b3 - <itertools::format::Format<I> as core::fmt::Display>::fmt::h064530a6ea8ffcbf
                               at /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/itertools-0.10.5/src/format.rs:105:21
  16:     0x55575724982f - core::fmt::write::h997ecd0e22e2af7a
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/core/src/fmt/mod.rs:1247:17
  17:     0x55575724982f - core::fmt::write::h997ecd0e22e2af7a
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/core/src/fmt/mod.rs:1247:17
  18:     0x55575722c621 - std::io::Write::write_fmt::h291317e85b978e13
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/io/mod.rs:1698:15
  19:     0x55575722f3b3 - std::panicking::default_hook::{{closure}}::h0847452fe926d6e5
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:255:21
  20:     0x55575722f1b7 - std::panicking::default_hook::hbcdd7833994c05d0
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:293:9
  21:     0x55575722fa21 - std::panicking::rust_panic_with_hook::hb55c52c8e21298f0
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:700:13
  22:     0x55575722f913 - std::panicking::begin_panic_handler::{{closure}}::h51ad0ee3ee1b4d02
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:595:13
  23:     0x55575722e7b6 - std::sys_common::backtrace::__rust_end_short_backtrace::hd1006853c72eedaf
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:150:18
  24:     0x55575722f612 - rust_begin_unwind
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:584:5
  25:     0x555757212ed3 - core::panicking::panic_fmt::h0405aceea833a54b
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/core/src/panicking.rs:67:14
  26:     0x555757213f7f - core::panicking::panic_display::he369e4705b14dda4
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/core/src/panicking.rs:150:5
  27:     0x555757215201 - playground::main::hed8c86f138364518
                               at /playground/src/main.rs:5:5
  28:     0x5557572137db - core::ops::function::FnOnce::call_once::hbebd13fb81ee85e2
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/core/src/ops/function.rs:250:5
  29:     0x5557572134ee - std::sys_common::backtrace::__rust_begin_short_backtrace::h8be5514a066de9a8
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:134:18
  30:     0x555757213561 - std::rt::lang_start::{{closure}}::h283d7d606f728596
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/rt.rs:166:18
  31:     0x55575722a432 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::ha628a292c7e4d1fe
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/core/src/ops/function.rs:284:13
  32:     0x55575722a432 - std::panicking::try::do_call::haef2b0ee78305734
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:490:40
  33:     0x55575722a432 - std::panicking::try::h18b79ccaa1dcd46e
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:454:19
  34:     0x55575722a432 - std::panic::catch_unwind::h44fa38099b98dbce
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panic.rs:140:14
  35:     0x55575722a432 - std::rt::lang_start_internal::{{closure}}::h90d1d020380fa86c
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/rt.rs:148:48
  36:     0x55575722a432 - std::panicking::try::do_call::h96eb402652927015
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:490:40
  37:     0x55575722a432 - std::panicking::try::h9ac5ba472c3806a8
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:454:19
  38:     0x55575722a432 - std::panic::catch_unwind::ha6f72383b6160344
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panic.rs:140:14
  39:     0x55575722a432 - std::rt::lang_start_internal::hc00ff9425137690f
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/rt.rs:148:20
  40:     0x55575721353a - std::rt::lang_start::hf0c3703aafa2e063
                               at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/rt.rs:165:17
  41:     0x55575721523e - main
  42:     0x7f45f2cf9083 - __libc_start_main
  43:     0x55575721340e - _start
  44:                0x0 - <unknown>
thread panicked while panicking. aborting.
timeout: the monitored command dumped core

Version it worked on

It most recently worked on: Rust 1.70 (beta) and Rust 1.69 (stable)

Version with regression

rustc --version --verbose:

rustc 1.71.0-nightly (b628260df 2023-04-22)
binary: rustc
commit-hash: b628260df0587ae559253d8640ecb8738d3de613
commit-date: 2023-04-22
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

Backtrace

None

Other

I also reported this here rust-itertools/itertools#694, but I think this one is on rustc.

@m-ou-se assigning you, because I suspect this has something to do with recent format_args! changes.

@flip1995 flip1995 added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. C-bug Category: This is a bug. labels Apr 23, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 23, 2023
@m-ou-se
Copy link
Member

m-ou-se commented Apr 23, 2023

I'll look into this tomorrow.

Can you check if it also happens with -Zflatten-format-args=no?

@lukas-code
Copy link
Member

This is unrelated to format_args! and was caused by a recent change to the panic runtime. I've posted a fix at #110721.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 24, 2023
format panic message only once

For `panic!` and friends, the `std` panic runtime will always set the `.payload()` of `PanicInfo` to the formatted string. The linked issues show that formatting the message twice can cause problems, so we simply print the already formatted message instead of formatting it again. We can't remove the preformatted payload, because it can be observed by custom panic hooks.

fixes rust-lang#110717
fixes rust-itertools/itertools#694

cc `@Amanieu` who broke this in rust-lang#109507
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 24, 2023
format panic message only once

For `panic!` and friends, the `std` panic runtime will always set the `.payload()` of `PanicInfo` to the formatted string. The linked issues show that formatting the message twice can cause problems, so we simply print the already formatted message instead of formatting it again. We can't remove the preformatted payload, because it can be observed by custom panic hooks.

fixes rust-lang#110717
fixes rust-itertools/itertools#694

cc ``@Amanieu`` who broke this in rust-lang#109507
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 24, 2023
format panic message only once

For `panic!` and friends, the `std` panic runtime will always set the `.payload()` of `PanicInfo` to the formatted string. The linked issues show that formatting the message twice can cause problems, so we simply print the already formatted message instead of formatting it again. We can't remove the preformatted payload, because it can be observed by custom panic hooks.

fixes rust-lang#110717
fixes rust-itertools/itertools#694

cc ```@Amanieu``` who broke this in rust-lang#109507
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 25, 2023
@jyn514 jyn514 assigned lukas-code and unassigned m-ou-se Apr 26, 2023
@jyn514 jyn514 added A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 26, 2023
@bors bors closed this as completed in eea5f8a Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants