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

ICE: invalid format num when println! with multiple unused formatting arguments(format_args_implicits) #125002

Closed
pymongo opened this issue May 11, 2024 · 3 comments · Fixed by #125004
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

@pymongo
Copy link
Contributor

pymongo commented May 11, 2024

Code

fn main() {
    println!("%65536", 1);
}

Meta

rustc --version --verbose:

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2

Error output

thread 'rustc' panicked at compiler/rustc_builtin_macros/src/format_foreign.rs:272:55:
invalid format num `"65536"`
Backtrace

thread 'rustc' panicked at compiler/rustc_builtin_macros/src/format_foreign.rs:272:55:
invalid format num `"1172797387437666312"`
stack backtrace:
   0:     0x7f824978ee25 - std::backtrace_rs::backtrace::libunwind::trace::h076b7d335d3f5d8e
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7f824978ee25 - std::backtrace_rs::backtrace::trace_unsynchronized::he80fbffb90acdf81
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f824978ee25 - std::backtrace::Backtrace::create::hed86b473a99fdb7c
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/backtrace.rs:331:13
   3:     0x7f824978ed75 - std::backtrace::Backtrace::force_capture::h17f58d3d8d696aca
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/backtrace.rs:312:9
   4:     0x7f824c8ea249 - std[420967f48346b39c]::panicking::update_hook::<alloc[478b9a7ca3809208]::boxed::Box<rustc_driver_impl[9e6d636adc327e66]::install_ice_hook::{closure#0}>>::{closure#0}
   5:     0x7f82497a9a86 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hd12a80ecb6b6cfe8
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/alloc/src/boxed.rs:2036:9
   6:     0x7f82497a9a86 - std::panicking::rust_panic_with_hook::h33d302c7fc861cff
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/panicking.rs:799:13
   7:     0x7f82497a9834 - std::panicking::begin_panic_handler::{{closure}}::hc538f5c218e27dc0
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/panicking.rs:664:13
   8:     0x7f82497a7109 - std::sys_common::backtrace::__rust_end_short_backtrace::habfe9112f9a835c0
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/sys_common/backtrace.rs:171:18
   9:     0x7f82497a9567 - rust_begin_unwind
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/panicking.rs:652:5
  10:     0x7f82497f23d3 - core::panicking::panic_fmt::h36e9ce03408e5254
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/core/src/panicking.rs:72:14
  11:     0x7f824c7350f1 - <rustc_builtin_macros[5110e67ae3fbf1dc]::format_foreign::printf::Num>::from_str
  12:     0x7f824c73604f - <rustc_builtin_macros[5110e67ae3fbf1dc]::format_foreign::printf::Substitutions as core[554a336f897370d5]::iter::traits::iterator::Iterator>::next
  13:     0x7f824e62e0fe - rustc_builtin_macros[5110e67ae3fbf1dc]::format::make_format_args
  14:     0x7f824e7a59cb - rustc_builtin_macros[5110e67ae3fbf1dc]::format::expand_format_args_impl
  15:     0x7f824a7c210c - <rustc_expand[a63df943e9d70b7e]::expand::MacroExpander>::fully_expand_fragment
  16:     0x7f824e90c998 - <rustc_expand[a63df943e9d70b7e]::expand::MacroExpander>::expand_crate
  17:     0x7f824e215741 - rustc_interface[d156b119c0ee28cb]::passes::resolver_for_lowering_raw
  18:     0x7f824e214ccd - rustc_query_impl[afd3850f0842b024]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[afd3850f0842b024]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b29a689460622aa4]::query::erase::Erased<[u8; 16usize]>>
  19:     0x7f824e214caf - <rustc_query_impl[afd3850f0842b024]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[554a336f897370d5]::ops::function::FnOnce<(rustc_middle[b29a689460622aa4]::ty::context::TyCtxt, ())>>::call_once
  20:     0x7f824ec03740 - rustc_query_system[6b56706b6a133fc0]::query::plumbing::try_execute_query::<rustc_query_impl[afd3850f0842b024]::DynamicConfig<rustc_query_system[6b56706b6a133fc0]::query::caches::SingleCache<rustc_middle[b29a689460622aa4]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[afd3850f0842b024]::plumbing::QueryCtxt, true>
  21:     0x7f824ec031b7 - rustc_query_impl[afd3850f0842b024]::query_impl::resolver_for_lowering_raw::get_query_incr::__rust_end_short_backtrace
  22:     0x7f824e81e07e - rustc_interface[d156b119c0ee28cb]::interface::run_compiler::<core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>, rustc_driver_impl[9e6d636adc327e66]::run_compiler::{closure#0}>::{closure#1}
  23:     0x7f824e7fae09 - std[420967f48346b39c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[d156b119c0ee28cb]::util::run_in_thread_with_globals<rustc_interface[d156b119c0ee28cb]::util::run_in_thread_pool_with_globals<rustc_interface[d156b119c0ee28cb]::interface::run_compiler<core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>, rustc_driver_impl[9e6d636adc327e66]::run_compiler::{closure#0}>::{closure#1}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>::{closure#0}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>
  24:     0x7f824e7fabb6 - <<std[420967f48346b39c]::thread::Builder>::spawn_unchecked_<rustc_interface[d156b119c0ee28cb]::util::run_in_thread_with_globals<rustc_interface[d156b119c0ee28cb]::util::run_in_thread_pool_with_globals<rustc_interface[d156b119c0ee28cb]::interface::run_compiler<core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>, rustc_driver_impl[9e6d636adc327e66]::run_compiler::{closure#0}>::{closure#1}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>::{closure#0}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>::{closure#2} as core[554a336f897370d5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7f82497b38cb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h56757e55bbcfa856
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/alloc/src/boxed.rs:2022:9
  26:     0x7f82497b38cb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf230e264012c630a
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/alloc/src/boxed.rs:2022:9
  27:     0x7f82497b38cb - std::sys::pal::unix::thread::Thread::new::thread_start::hfcc46c6a7fe0b042
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/sys/pal/unix/thread.rs:108:17
  28:     0x7f82496bd609 - start_thread
  29:     0x7f82495e0353 - clone
  30:                0x0 - <unknown>


rustc version: 1.80.0-nightly (6e1d94708 2024-05-10)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [resolver_for_lowering_raw] getting the resolver for lowering
end of query stack

@pymongo pymongo 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 May 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 11, 2024
@theemathas
Copy link

theemathas commented May 11, 2024

Minimized code that causes ICE (Note: "%65536" causes an ICE, but "%65535" correctly produces an error, indicating an integer overflow):

fn main() {
    println!("%100000", 1);
}

playground link (stable rust, version 1.78.0)

Error output
   Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at compiler/rustc_builtin_macros/src/format_foreign.rs:272:55:
invalid format num `"100000"`
stack backtrace:
   0:     0x7f2fb89e5892 - std::backtrace_rs::backtrace::libunwind::trace::he4ee80166a02c846
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7f2fb89e5892 - std::backtrace_rs::backtrace::trace_unsynchronized::h476faccf57e88641
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f2fb89e5892 - std::sys_common::backtrace::_print_fmt::h430c922a77e7a59c
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f2fb89e5892 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hffecb437d922f988
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f2fb8a36a6c - core::fmt::rt::Argument::fmt::hf3df69369399bfa9
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/fmt/rt.rs:142:9
   5:     0x7f2fb8a36a6c - core::fmt::write::hd9a8d7d029f9ea1a
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/fmt/mod.rs:1153:17
   6:     0x7f2fb89da78f - std::io::Write::write_fmt::h0e1226b2b8d973fe
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/io/mod.rs:1843:15
   7:     0x7f2fb89e5664 - std::sys_common::backtrace::_print::hd2df4a083f6e69b8
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f2fb89e5664 - std::sys_common::backtrace::print::he907f6ad7eee41cb
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f2fb89e835b - std::panicking::default_hook::{{closure}}::h3926193b61c9ca9b
  10:     0x7f2fb89e80b3 - std::panicking::default_hook::h25ba2457dea68e65
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:292:9
  11:     0x7f2fbb88145d - std[e4dfbc2c3f4b09f1]::panicking::update_hook::<alloc[1adba907b9db1888]::boxed::Box<rustc_driver_impl[24a943716c49befe]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f2fb89e8ac0 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h022ca2c0d8c21c9e
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2034:9
  13:     0x7f2fb89e8ac0 - std::panicking::rust_panic_with_hook::h0ad14d90dcf5224f
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:783:13
  14:     0x7f2fb89e8802 - std::panicking::begin_panic_handler::{{closure}}::h4a1838a06f542647
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:657:13
  15:     0x7f2fb89e5d66 - std::sys_common::backtrace::__rust_end_short_backtrace::h77cc4dc3567ca904
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f2fb89e8534 - rust_begin_unwind
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5
  17:     0x7f2fb8a32f85 - core::panicking::panic_fmt::h940d4fd01a4b4fd1
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:72:14
  18:     0x7f2fbb6e3941 - <rustc_builtin_macros[8796187f5b99b097]::format_foreign::printf::Num>::from_str
  19:     0x7f2fbb6e4117 - <rustc_builtin_macros[8796187f5b99b097]::format_foreign::printf::Substitutions as core[836963c7c1decc11]::iter::traits::iterator::Iterator>::next
  20:     0x7f2fbb6e1391 - rustc_builtin_macros[8796187f5b99b097]::format::report_missing_placeholders
  21:     0x7f2fbd490a79 - rustc_builtin_macros[8796187f5b99b097]::format::make_format_args
  22:     0x7f2fbd46abea - rustc_builtin_macros[8796187f5b99b097]::format::expand_format_args_impl
  23:     0x7f2fbcfcaa01 - <rustc_expand[af7ad4d1f9fa58f8]::expand::MacroExpander>::fully_expand_fragment
  24:     0x7f2fbd76a991 - <rustc_expand[af7ad4d1f9fa58f8]::expand::MacroExpander>::expand_crate
  25:     0x7f2fbcffce12 - rustc_interface[ba2b6dc4c96cb491]::passes::resolver_for_lowering_raw
  26:     0x7f2fbcffc2db - rustc_query_impl[e4152ad88c3d6c78]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e4152ad88c3d6c78]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fda44fdb505d3e7f]::query::erase::Erased<[u8; 16usize]>>
  27:     0x7f2fbcffc2c9 - <rustc_query_impl[e4152ad88c3d6c78]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[836963c7c1decc11]::ops::function::FnOnce<(rustc_middle[fda44fdb505d3e7f]::ty::context::TyCtxt, ())>>::call_once
  28:     0x7f2fbd7d5c7b - rustc_query_system[475239fef39bf53f]::query::plumbing::try_execute_query::<rustc_query_impl[e4152ad88c3d6c78]::DynamicConfig<rustc_query_system[475239fef39bf53f]::query::caches::SingleCache<rustc_middle[fda44fdb505d3e7f]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[e4152ad88c3d6c78]::plumbing::QueryCtxt, false>
  29:     0x7f2fbd7d57a4 - rustc_query_impl[e4152ad88c3d6c78]::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7f2fbd6556d4 - rustc_interface[ba2b6dc4c96cb491]::interface::run_compiler::<core[836963c7c1decc11]::result::Result<(), rustc_span[a4517f2b2e65298c]::ErrorGuaranteed>, rustc_driver_impl[24a943716c49befe]::run_compiler::{closure#0}>::{closure#0}
  31:     0x7f2fbd997b6e - std[e4dfbc2c3f4b09f1]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ba2b6dc4c96cb491]::util::run_in_thread_with_globals<rustc_interface[ba2b6dc4c96cb491]::interface::run_compiler<core[836963c7c1decc11]::result::Result<(), rustc_span[a4517f2b2e65298c]::ErrorGuaranteed>, rustc_driver_impl[24a943716c49befe]::run_compiler::{closure#0}>::{closure#0}, core[836963c7c1decc11]::result::Result<(), rustc_span[a4517f2b2e65298c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[836963c7c1decc11]::result::Result<(), rustc_span[a4517f2b2e65298c]::ErrorGuaranteed>>
  32:     0x7f2fbd9979ca - <<std[e4dfbc2c3f4b09f1]::thread::Builder>::spawn_unchecked_<rustc_interface[ba2b6dc4c96cb491]::util::run_in_thread_with_globals<rustc_interface[ba2b6dc4c96cb491]::interface::run_compiler<core[836963c7c1decc11]::result::Result<(), rustc_span[a4517f2b2e65298c]::ErrorGuaranteed>, rustc_driver_impl[24a943716c49befe]::run_compiler::{closure#0}>::{closure#0}, core[836963c7c1decc11]::result::Result<(), rustc_span[a4517f2b2e65298c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[836963c7c1decc11]::result::Result<(), rustc_span[a4517f2b2e65298c]::ErrorGuaranteed>>::{closure#1} as core[836963c7c1decc11]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7f2fb89f2145 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h19b9e642d37e7272
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2020:9
  34:     0x7f2fb89f2145 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h97265befc434d3ae
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2020:9
  35:     0x7f2fb89f2145 - std::sys::pal::unix::thread::Thread::new::thread_start::h420dad5cf01a9f35
                               at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys/pal/unix/thread.rs:108:17
  36:     0x7f2fb8902609 - start_thread
  37:     0x7f2fb8825353 - clone
  38:                0x0 - <unknown>

error: 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.78.0 (9b00956e5 2024-04-29) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [resolver_for_lowering_raw] getting the resolver for lowering
end of query stack
error: could not compile `playground` (bin "playground")

For context, this code with "%65535" correctly produces the below error

fn main() {
    println!("%65535", 1);
}
   Compiling playground v0.0.1 (/playground)
error: argument never used
 --> src/main.rs:2:24
  |
2 |     println!("%65535", 1);
  |                        ^ argument never used
  |
note: format specifiers use curly braces, and the conversion specifier `
      ` is unknown or unsupported
 --> src/main.rs:2:15
  |
2 |     println!("%65535", 1);
  |               ^^^^^^^
  = note: printf formatting is not supported; see the documentation for `std::fmt`

@conradludgate
Copy link
Contributor

Relevant line of code:

Num::Num(s.parse().unwrap_or_else(|_| panic!("invalid format num `{s:?}`")))

@pymongo
Copy link
Contributor Author

pymongo commented May 11, 2024

Minimized code that causes ICE (Note: "%65536" causes an ICE, but "%65535" correctly produces an error, indicating an integer overflow):

emit compile error

  • format_args!("%65536", 1)
  • format!("%65536", 1)

ICE

  • println!("%65536", 1)
  • println!("% 65536", 1)
  • println!("%100000 % 65536 {:10000$} {2}", 42, 1, 1);

match c {
'1'..='9' => {
let end = at_next_cp_while(next, char::is_ascii_digit);
match end.next_cp() {
// Yes, this *is* the parameter.
Some(('$', end2)) => {
state = Flags;
parameter = Some(at.slice_between(end).unwrap().parse().unwrap());
move_to!(end2);
}
// Wait, no, actually, it's the width.
Some(_) => {
state = Prec;
parameter = None;
flags = "";
width = Some(Num::from_str(at.slice_between(end).unwrap(), None));
move_to!(end);
}
// It's invalid, is what it is.
None => return fallback(),

possible patch is Num::from_str return Option

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 11, 2024
@bors bors closed this as completed in 1c90b9f May 18, 2024
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.

5 participants