Skip to content

dbg_macro lint causes an ICE when used inside an async closure #14914

@SergeyKasmy

Description

@SergeyKasmy

Summary

Using dbg!() inside an async closure causes clippy to reach an unreachable!() match arm.

#![warn(clippy::dbg_macro)]

fn main() {
    let _x = takes_async_fn(async |val| dbg!(val));
}

// to make type inference work
fn takes_async_fn<F, Fut>(_f: F)
where
    F: FnOnce(i32) -> Fut,
    Fut: Future<Output = i32>,
{
}

Bypassing the function by just calling the async closure later on also works, e.g.

let f = async |val| dbg!(val);
_ = f(1);

ICE's both on stable and latest nightly

Version

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1

-----
rustc 1.89.0-nightly (283db70ac 2025-05-25)
binary: rustc
commit-hash: 283db70ace62a0ae704a624e43b68c2ee44b87a6
commit-date: 2025-05-25
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Error output

Backtrace

thread 'rustc' panicked at src/tools/clippy/clippy_lints/src/dbg_macro.rs:118:30:
internal error: entered unreachable code
stack backtrace:
 0:     0x7fa986c8a3c3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hc04c8f544ab24d66
 1:     0x7fa987405b51 - core::fmt::write::hfe57b7174b7d8eab
 2:     0x7fa98888e011 - std::io::Write::write_fmt::h154385efa8565236
 3:     0x7fa986c8a222 - std::sys::backtrace::BacktraceLock::print::h0c8f24e22f5873a8
 4:     0x7fa986c8cada - std::panicking::default_hook::{{closure}}::hd07d57e6a602c8e4
 5:     0x7fa986c8c65f - std::panicking::default_hook::h63d12f7d95bd91ed
 6:     0x7fa985cf0450 - std[ab9b65b5f5dd2f44]::panicking::update_hook::<alloc[4810a64b00f2b3b7]::boxed::Box<rustc_driver_impl[ddaea9a5059e4009]::install_ice_hook::{closure#1}>>::{closure#0}
 7:     0x7fa986c8d353 - std::panicking::rust_panic_with_hook::h33b18b24045abff4
 8:     0x7fa986c8d016 - std::panicking::begin_panic_handler::{{closure}}::hf8313cc2fd0126bc
 9:     0x7fa986c8a899 - std::sys::backtrace::__rust_end_short_backtrace::h57fe07c8aea5c98a
10:     0x7fa986c8cd0d - __rustc[95feac21a9532783]::rust_begin_unwind
11:     0x7fa983694960 - core::panicking::panic_fmt::hd54fb667be51beea
12:     0x7fa9842f9c6c - core::panicking::panic::h48a7e1f3665210c6
13:     0x560dc26e7d46 - <clippy_utils[d60f2eef9f8d424a]::diagnostics::span_lint_and_then<rustc_lint[d85a9de049483200]::context::LateContext, rustc_span[b87e37d4967e23ab]::span_encoding::Span, &str, <clippy_lints[a8ab7ad3fb1e79e4]::dbg_macro::DbgMacro as rustc_lint[d85a9de049483200]::passes::LateLintPass>::check_expr::{closure#0}>::{closure#0} as core[6e25f1b983e4a449]::ops::function::FnOnce<(&mut rustc_errors[d0d9f9c9447584b1]::diagnostic::Diag<()>,)>>::call_once::{shim:vtable#0}
14:     0x7fa98793528d - rustc_middle[f5c565be837cd477]::lint::lint_level::lint_level_impl
15:     0x560dc27d7621 - <clippy_lints[a8ab7ad3fb1e79e4]::dbg_macro::DbgMacro as rustc_lint[d85a9de049483200]::passes::LateLintPass>::check_expr
16:     0x7fa9862460be - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}
17:     0x7fa986246027 - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_expr
18:     0x7fa986245e62 - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_nested_body
19:     0x7fa986246ace - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_fn
20:     0x7fa98624640a - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}
21:     0x7fa986246027 - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_expr
22:     0x7fa986246742 - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}
23:     0x7fa986246027 - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_expr
24:     0x7fa986247317 - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_block
25:     0x7fa986246787 - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}
26:     0x7fa986246027 - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_expr
27:     0x7fa986245e62 - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_nested_body
28:     0x7fa986246ace - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_fn
29:     0x7fa98622e414 - <rustc_lint[d85a9de049483200]::late::LateContextAndPass<rustc_lint[d85a9de049483200]::late::RuntimeCombinedLateLintPass> as rustc_hir[201392ed958526d3]::intravisit::Visitor>::visit_nested_item
30:     0x7fa987ef7f3f - rustc_lint[d85a9de049483200]::late::check_crate::{closure#0}
31:     0x7fa987ef81eb - rustc_lint[d85a9de049483200]::late::check_crate
32:     0x7fa987ef6598 - rustc_interface[4f8e933b45f54331]::passes::analysis
33:     0x7fa987ef636d - rustc_query_impl[9eb226868f218d86]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9eb226868f218d86]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f5c565be837cd477]::query::erase::Erased<[u8; 0usize]>>
34:     0x7fa9886e177e - rustc_query_system[719b00724ab1874c]::query::plumbing::try_execute_query::<rustc_query_impl[9eb226868f218d86]::DynamicConfig<rustc_query_system[719b00724ab1874c]::query::caches::SingleCache<rustc_middle[f5c565be837cd477]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[9eb226868f218d86]::plumbing::QueryCtxt, true>
35:     0x7fa9886e1061 - rustc_query_impl[9eb226868f218d86]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
36:     0x7fa988531e87 - rustc_interface[4f8e933b45f54331]::passes::create_and_enter_global_ctxt::<core[6e25f1b983e4a449]::option::Option<rustc_interface[4f8e933b45f54331]::queries::Linker>, rustc_driver_impl[ddaea9a5059e4009]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
37:     0x7fa988523eaa - rustc_interface[4f8e933b45f54331]::interface::run_compiler::<(), rustc_driver_impl[ddaea9a5059e4009]::run_compiler::{closure#0}>::{closure#1}
38:     0x7fa988364f08 - std[ab9b65b5f5dd2f44]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4f8e933b45f54331]::util::run_in_thread_with_globals<rustc_interface[4f8e933b45f54331]::util::run_in_thread_pool_with_globals<rustc_interface[4f8e933b45f54331]::interface::run_compiler<(), rustc_driver_impl[ddaea9a5059e4009]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
39:     0x7fa9883657f4 - <<std[ab9b65b5f5dd2f44]::thread::Builder>::spawn_unchecked_<rustc_interface[4f8e933b45f54331]::util::run_in_thread_with_globals<rustc_interface[4f8e933b45f54331]::util::run_in_thread_pool_with_globals<rustc_interface[4f8e933b45f54331]::interface::run_compiler<(), rustc_driver_impl[ddaea9a5059e4009]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[6e25f1b983e4a449]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
40:     0x7fa988366bf7 - std::sys::pal::unix::thread::Thread::new::thread_start::h2717d4f9aca577e6
41:     0x7fa9822a57eb - <unknown>
42:     0x7fa98232918c - <unknown>
43:                0x0 - <unknown>

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-ICEIssue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions