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

Format macro causes panic if it is inside closure which result is passed into a function that accepts less args. #94599

Closed
M1ngXU opened this issue Mar 4, 2022 · 4 comments · Fixed by #94636
Assignees
Labels
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@M1ngXU
Copy link

M1ngXU commented Mar 4, 2022

If using format inside a closure (e.g. in iter functions) and the returning String is passed into a function that takes less args, rustc panics.

Code

(||{})(format!("{}", (||format!("{}", "s"))()));

Minimized code snippet: #94599 (comment)

Meta

version: 1.60.0-beta.2 and 1.61.0-nightly

Error output

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/compiler/rustc_errors/src/lib.rs:1106:9
stack backtrace:
   0:     0x7f0a839f682c - std::backtrace_rs::backtrace::libunwind::trace::hf059f7d696f3ddd0
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f0a839f682c - std::backtrace_rs::backtrace::trace_unsynchronized::h686db7ceab9bfd1a
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f0a839f682c - std::sys_common::backtrace::_print_fmt::he4aca9613e5c3637
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f0a839f682c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h080145eaebef7a38
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f0a83a562cc - core::fmt::write::hb73cfe8a4b8d71a9
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/core/src/fmt/mod.rs:1190:17
   5:     0x7f0a839e6aa8 - std::io::Write::write_fmt::h44625064880463d0
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/std/src/io/mod.rs:1657:15
   6:     0x7f0a839fa7f7 - std::sys_common::backtrace::_print::h750dbecb76b2ec9e
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f0a839fa7f7 - std::sys_common::backtrace::print::hd7b9c9e26624b8b6
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f0a839fa7f7 - std::panicking::default_hook::{{closure}}::hcb767bb9dd055c7f
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/std/src/panicking.rs:295:22
   9:     0x7f0a839fa4bf - std::panicking::default_hook::h5c8de2745bf115a6
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/std/src/panicking.rs:314:9
  10:     0x7f0a84186551 - rustc_driver[691b9c2a58b062eb]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f0a839fb0c5 - std::panicking::rust_panic_with_hook::heddcebbadb156565
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/std/src/panicking.rs:702:17
  12:     0x7f0a844c0181 - std[6a13073971966f88]::panicking::begin_panic::<rustc_errors[a9175c9762cc5fd5]::ExplicitBug>::{closure#0}
  13:     0x7f0a844bfc66 - std[6a13073971966f88]::sys_common::backtrace::__rust_end_short_backtrace::<std[6a13073971966f88]::panicking::begin_panic<rustc_errors[a9175c9762cc5fd5]::ExplicitBug>::{closure#0}, !>
  14:     0x7f0a844c00cf - std[6a13073971966f88]::panicking::begin_panic::<rustc_errors[a9175c9762cc5fd5]::ExplicitBug>
  15:     0x7f0a844ebcad - std[6a13073971966f88]::panic::panic_any::<rustc_errors[a9175c9762cc5fd5]::ExplicitBug>
  16:     0x7f0a844e3d08 - <rustc_errors[a9175c9762cc5fd5]::HandlerInner>::span_bug::<rustc_span[6989153e7236b61f]::span_encoding::Span>
  17:     0x7f0a844e3a00 - <rustc_errors[a9175c9762cc5fd5]::Handler>::span_bug::<rustc_span[6989153e7236b61f]::span_encoding::Span>
  18:     0x7f0a8451f3a2 - rustc_middle[5e82cfb5c9ea2479]::ty::context::tls::with_opt::<rustc_middle[5e82cfb5c9ea2479]::util::bug::opt_span_bug_fmt<rustc_span[6989153e7236b61f]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7f0a8451f960 - rustc_middle[5e82cfb5c9ea2479]::util::bug::opt_span_bug_fmt::<rustc_span[6989153e7236b61f]::span_encoding::Span>
  20:     0x7f0a8451f92c - rustc_middle[5e82cfb5c9ea2479]::util::bug::span_bug_fmt::<rustc_span[6989153e7236b61f]::span_encoding::Span>
  21:     0x7f0a8561e629 - <rustc_typeck[e808157a81a43890]::check::writeback::WritebackCx as rustc_hir[b06bc1d5472ce31]::intravisit::Visitor>::visit_local
  22:     0x7f0a8561b98f - <rustc_typeck[e808157a81a43890]::check::writeback::WritebackCx as rustc_hir[b06bc1d5472ce31]::intravisit::Visitor>::visit_expr
  23:     0x7f0a8561a99c - <rustc_typeck[e808157a81a43890]::check::writeback::WritebackCx as rustc_hir[b06bc1d5472ce31]::intravisit::Visitor>::visit_expr
  24:     0x7f0a85619e02 - <rustc_typeck[e808157a81a43890]::check::writeback::WritebackCx as rustc_hir[b06bc1d5472ce31]::intravisit::Visitor>::visit_expr
  25:     0x7f0a85619e25 - <rustc_typeck[e808157a81a43890]::check::writeback::WritebackCx as rustc_hir[b06bc1d5472ce31]::intravisit::Visitor>::visit_expr
  26:     0x7f0a8561b96e - <rustc_typeck[e808157a81a43890]::check::writeback::WritebackCx as rustc_hir[b06bc1d5472ce31]::intravisit::Visitor>::visit_expr
  27:     0x7f0a85554271 - <rustc_typeck[e808157a81a43890]::check::fn_ctxt::FnCtxt>::resolve_type_vars_in_body
  28:     0x7f0a855d0fe9 - <rustc_infer[f86b6e99fd53383b]::infer::InferCtxtBuilder>::enter::<&rustc_middle[5e82cfb5c9ea2479]::ty::context::TypeckResults, <rustc_typeck[e808157a81a43890]::check::inherited::InheritedBuilder>::enter<rustc_typeck[e808157a81a43890]::check::typeck_with_fallback<rustc_typeck[e808157a81a43890]::check::typeck::{closure#0}>::{closure#1}, &rustc_middle[5e82cfb5c9ea2479]::ty::context::TypeckResults>::{closure#0}>
  29:     0x7f0a855abbc3 - rustc_typeck[e808157a81a43890]::check::typeck
  30:     0x7f0a85a4b685 - rustc_query_system[832e6358829a14ea]::query::plumbing::try_execute_query::<rustc_query_impl[36da0ccdccd1cc1e]::plumbing::QueryCtxt, rustc_query_system[832e6358829a14ea]::query::caches::DefaultCache<rustc_span[6989153e7236b61f]::def_id::LocalDefId, &rustc_middle[5e82cfb5c9ea2479]::ty::context::TypeckResults>>
  31:     0x7f0a85aaa67c - <rustc_query_impl[36da0ccdccd1cc1e]::Queries as rustc_middle[5e82cfb5c9ea2479]::ty::query::QueryEngine>::typeck
  32:     0x7f0a855abd92 - rustc_typeck[e808157a81a43890]::check::typeck
  33:     0x7f0a85a4b685 - rustc_query_system[832e6358829a14ea]::query::plumbing::try_execute_query::<rustc_query_impl[36da0ccdccd1cc1e]::plumbing::QueryCtxt, rustc_query_system[832e6358829a14ea]::query::caches::DefaultCache<rustc_span[6989153e7236b61f]::def_id::LocalDefId, &rustc_middle[5e82cfb5c9ea2479]::ty::context::TypeckResults>>
  34:     0x7f0a85aaa67c - <rustc_query_impl[36da0ccdccd1cc1e]::Queries as rustc_middle[5e82cfb5c9ea2479]::ty::query::QueryEngine>::typeck
  35:     0x7f0a8560d73a - <rustc_middle[5e82cfb5c9ea2479]::hir::map::Map>::par_body_owners::<rustc_typeck[e808157a81a43890]::check::typeck_item_bodies::{closure#0}>
  36:     0x7f0a8628715c - rustc_typeck[e808157a81a43890]::check::typeck_item_bodies
  37:     0x7f0a864bb954 - rustc_query_system[832e6358829a14ea]::query::plumbing::try_execute_query::<rustc_query_impl[36da0ccdccd1cc1e]::plumbing::QueryCtxt, rustc_query_system[832e6358829a14ea]::query::caches::DefaultCache<(), ()>>
  38:     0x7f0a864e3548 - rustc_query_system[832e6358829a14ea]::query::plumbing::get_query::<rustc_query_impl[36da0ccdccd1cc1e]::queries::typeck_item_bodies, rustc_query_impl[36da0ccdccd1cc1e]::plumbing::QueryCtxt>
  39:     0x7f0a8628b649 - <rustc_session[9ca8810e328b55b5]::session::Session>::time::<(), rustc_typeck[e808157a81a43890]::check_crate::{closure#7}>
  40:     0x7f0a8627fb43 - rustc_typeck[e808157a81a43890]::check_crate
  41:     0x7f0a8601b587 - rustc_interface[9aa301a3811405e2]::passes::analysis
  42:     0x7f0a864b2383 - rustc_query_system[832e6358829a14ea]::query::plumbing::try_execute_query::<rustc_query_impl[36da0ccdccd1cc1e]::plumbing::QueryCtxt, rustc_query_system[832e6358829a14ea]::query::caches::DefaultCache<(), core[64c76e218c955efd]::result::Result<(), rustc_errors[a9175c9762cc5fd5]::ErrorReported>>>
  43:     0x7f0a864f12e5 - rustc_query_system[832e6358829a14ea]::query::plumbing::get_query::<rustc_query_impl[36da0ccdccd1cc1e]::queries::analysis, rustc_query_impl[36da0ccdccd1cc1e]::plumbing::QueryCtxt>
  44:     0x7f0a85ff9cc8 - <rustc_interface[9aa301a3811405e2]::passes::QueryContext>::enter::<rustc_driver[691b9c2a58b062eb]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[64c76e218c955efd]::result::Result<(), rustc_errors[a9175c9762cc5fd5]::ErrorReported>>
  45:     0x7f0a85fe8094 - rustc_interface[9aa301a3811405e2]::interface::create_compiler_and_run::<core[64c76e218c955efd]::result::Result<(), rustc_errors[a9175c9762cc5fd5]::ErrorReported>, rustc_driver[691b9c2a58b062eb]::run_compiler::{closure#1}>
  46:     0x7f0a85fcd734 - std[6a13073971966f88]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[9aa301a3811405e2]::util::run_in_thread_pool_with_globals<rustc_interface[9aa301a3811405e2]::interface::run_compiler<core[64c76e218c955efd]::result::Result<(), rustc_errors[a9175c9762cc5fd5]::ErrorReported>, rustc_driver[691b9c2a58b062eb]::run_compiler::{closure#1}>::{closure#0}, core[64c76e218c955efd]::result::Result<(), rustc_errors[a9175c9762cc5fd5]::ErrorReported>>::{closure#0}, core[64c76e218c955efd]::result::Result<(), rustc_errors[a9175c9762cc5fd5]::ErrorReported>>
  47:     0x7f0a86000a99 - <<std[6a13073971966f88]::thread::Builder>::spawn_unchecked_<rustc_interface[9aa301a3811405e2]::util::run_in_thread_pool_with_globals<rustc_interface[9aa301a3811405e2]::interface::run_compiler<core[64c76e218c955efd]::result::Result<(), rustc_errors[a9175c9762cc5fd5]::ErrorReported>, rustc_driver[691b9c2a58b062eb]::run_compiler::{closure#1}>::{closure#0}, core[64c76e218c955efd]::result::Result<(), rustc_errors[a9175c9762cc5fd5]::ErrorReported>>::{closure#0}, core[64c76e218c955efd]::result::Result<(), rustc_errors[a9175c9762cc5fd5]::ErrorReported>>::{closure#1} as core[64c76e218c955efd]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  48:     0x7f0a83a06bb3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h47f7423189df9269
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/alloc/src/boxed.rs:1854:9
  49:     0x7f0a83a06bb3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7e8094f66f114b55
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/alloc/src/boxed.rs:1854:9
  50:     0x7f0a83a06bb3 - std::sys::unix::thread::Thread::new::thread_start::h928d5beb8b5b03f1
                               at /rustc/c1d075a4592e1f9aef1f13e960cea0b03d2ad025/library/std/src/sys/unix/thread.rs:108:17
  51:     0x7f0a8393a609 - start_thread
  52:     0x7f0a83853163 - clone
  53:                0x0 - <unknown>

query:

#0 [typeck] type-checking `main`
#1 [typeck] type-checking `main::{closure#0}`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
@M1ngXU M1ngXU 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 Mar 4, 2022
@M1ngXU M1ngXU changed the title Format macro causes panic if inside closure which result is passed into a function with too many args. Format macro causes panic if it is inside closure which result is passed into a function that accepts less args. Mar 4, 2022
@M1ngXU
Copy link
Author

M1ngXU commented Mar 4, 2022

@ouz-a
Copy link
Contributor

ouz-a commented Mar 4, 2022

Probably duplicate of #94516

@compiler-errors
Copy link
Member

Actually, not sure if it's a duplicate of #94516. Still failing on master after the fix for that one landed, and failed with the same error (and not a duplicated adjustment bug) on beta. I will look into it!

@rustbot claim

@compiler-errors
Copy link
Member

Minimized:

fn main() {
    (|| {})(|| {
        let b = 1;
    });
}

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. glacier ICE tracked in rust-lang/glacier. 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.

4 participants