Skip to content

ICE: attempted to read from stolen value #14774

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

Closed
matthiaskrgr opened this issue May 10, 2025 · 1 comment · Fixed by #14776
Closed

ICE: attempted to read from stolen value #14774

matthiaskrgr opened this issue May 10, 2025 · 1 comment · Fixed by #14776
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ L-nursery Lint: Currently in the nursery group

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented May 10, 2025

Summary

static BLOCK_FN_DEF: fn(usize) -> usize = {
    fn foo(a: usize) -> usize {
        a + 10
    }
    foo
};
struct X; //~ ERROR the name `X` is defined multiple times

fn main() {}

clippy-driver 7A8BA9EAB353077681959D01D05ABED1177C84A6CEFB373E1FE5C6AC8E0E5907.rs -Zvalidate-mir -Wclippy::missing_const_for_fn

Version

rustc 1.88.0-nightly (50aa04180 2025-05-08)
binary: rustc
commit-hash: 50aa04180709189a03dde5fd1c05751b2625ed37
commit-date: 2025-05-08
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.4

Error output

Backtrace

warning: static `BLOCK_FN_DEF` is never used
--> 7A8BA9EAB353077681959D01D05ABED1177C84A6CEFB373E1FE5C6AC8E0E5907.rs:1:8
|
1 | static BLOCK_FN_DEF: fn(usize) -> usize = {
|        ^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default

warning: struct `X` is never constructed
--> 7A8BA9EAB353077681959D01D05ABED1177C84A6CEFB373E1FE5C6AC8E0E5907.rs:7:8
|
7 | struct X; //~ ERROR the name `X` is defined multiple times
|        ^


thread 'rustc' panicked at src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs:160:50:
attempted to read from stolen value: rustc_middle::mir::Body
stack backtrace:
 0:     0x7f7aa4763923 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h35b8f72326f85230
 1:     0x7f7aa4e05c07 - core::fmt::write::h73f5af0fa08ac030
 2:     0x7f7aa5ee42d1 - std::io::Write::write_fmt::h0140e0dae4becf43
 3:     0x7f7aa4763782 - std::sys::backtrace::BacktraceLock::print::h2c50f8265df4edf7
 4:     0x7f7aa476737a - std::panicking::default_hook::{{closure}}::h4f831a137f70e67f
 5:     0x7f7aa4766eff - std::panicking::default_hook::h47af645a18677257
 6:     0x7f7aa3795ef3 - std[e444442488e5ea2d]::panicking::update_hook::<alloc[24374ce535a764d]::boxed::Box<rustc_driver_impl[d80da60e87609ad4]::install_ice_hook::{closure#1}>>::{closure#0}
 7:     0x7f7aa4767bf3 - std::panicking::rust_panic_with_hook::h2b8636e09e17cf97
 8:     0x7f7aa47678ea - std::panicking::begin_panic_handler::{{closure}}::h21b513d3b95c0c8c
 9:     0x7f7aa4763de9 - std::sys::backtrace::__rust_end_short_backtrace::h1fff5f9fcecd2e0e
10:     0x7f7aa47675ad - __rustc[f67a3b4e60d8f4c4]::rust_begin_unwind
11:     0x7f7aa1085ce0 - core::panicking::panic_fmt::h0a5d5e7acfcd4e48
12:     0x5b8e8a06efe2 - <rustc_data_structures[c2151ea158282339]::steal::Steal<rustc_middle[dca19e53efad7b1b]::mir::Body>>::borrow
13:     0x5b8e8a24191a - <clippy_lints[9db272bf031097ce]::missing_const_for_fn::MissingConstForFn as rustc_lint[ed09b7a07297b4c1]::passes::LateLintPass>::check_fn
14:     0x7f7aa3d144f8 - <rustc_lint[ed09b7a07297b4c1]::late::LateContextAndPass<rustc_lint[ed09b7a07297b4c1]::late::RuntimeCombinedLateLintPass> as rustc_hir[af6f8bbf2100f3d8]::intravisit::Visitor>::visit_fn
15:     0x7f7aa3cfc514 - <rustc_lint[ed09b7a07297b4c1]::late::LateContextAndPass<rustc_lint[ed09b7a07297b4c1]::late::RuntimeCombinedLateLintPass> as rustc_hir[af6f8bbf2100f3d8]::intravisit::Visitor>::visit_nested_item
16:     0x7f7aa3d14c4d - <rustc_lint[ed09b7a07297b4c1]::late::LateContextAndPass<rustc_lint[ed09b7a07297b4c1]::late::RuntimeCombinedLateLintPass> as rustc_hir[af6f8bbf2100f3d8]::intravisit::Visitor>::visit_block
17:     0x7f7aa3d141e7 - <rustc_lint[ed09b7a07297b4c1]::late::LateContextAndPass<rustc_lint[ed09b7a07297b4c1]::late::RuntimeCombinedLateLintPass> as rustc_hir[af6f8bbf2100f3d8]::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}
18:     0x7f7aa3d13a87 - <rustc_lint[ed09b7a07297b4c1]::late::LateContextAndPass<rustc_lint[ed09b7a07297b4c1]::late::RuntimeCombinedLateLintPass> as rustc_hir[af6f8bbf2100f3d8]::intravisit::Visitor>::visit_expr
19:     0x7f7aa3d138c2 - <rustc_lint[ed09b7a07297b4c1]::late::LateContextAndPass<rustc_lint[ed09b7a07297b4c1]::late::RuntimeCombinedLateLintPass> as rustc_hir[af6f8bbf2100f3d8]::intravisit::Visitor>::visit_nested_body
20:     0x7f7aa3cfc100 - <rustc_lint[ed09b7a07297b4c1]::late::LateContextAndPass<rustc_lint[ed09b7a07297b4c1]::late::RuntimeCombinedLateLintPass> as rustc_hir[af6f8bbf2100f3d8]::intravisit::Visitor>::visit_nested_item
21:     0x7f7aa5dea71e - rustc_lint[ed09b7a07297b4c1]::late::check_crate::{closure#0}
22:     0x7f7aa5dea9c9 - rustc_lint[ed09b7a07297b4c1]::late::check_crate
23:     0x7f7aa5de8cdf - rustc_interface[4b2c44076e9c0aea]::passes::analysis
24:     0x7f7aa5de8ab5 - rustc_query_impl[d196c070bbe03594]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d196c070bbe03594]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dca19e53efad7b1b]::query::erase::Erased<[u8; 0usize]>>
25:     0x7f7aa5d3ccfa - rustc_query_system[ff49814a586d4008]::query::plumbing::try_execute_query::<rustc_query_impl[d196c070bbe03594]::DynamicConfig<rustc_query_system[ff49814a586d4008]::query::caches::SingleCache<rustc_middle[dca19e53efad7b1b]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[d196c070bbe03594]::plumbing::QueryCtxt, false>
26:     0x7f7aa5d3c9cf - rustc_query_impl[d196c070bbe03594]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
27:     0x7f7aa6034b87 - rustc_interface[4b2c44076e9c0aea]::passes::create_and_enter_global_ctxt::<core[ce1fa00964895ff1]::option::Option<rustc_interface[4b2c44076e9c0aea]::queries::Linker>, rustc_driver_impl[d80da60e87609ad4]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
28:     0x7f7aa5f0b5a6 - rustc_interface[4b2c44076e9c0aea]::interface::run_compiler::<(), rustc_driver_impl[d80da60e87609ad4]::run_compiler::{closure#0}>::{closure#1}
29:     0x7f7aa5edad7e - std[e444442488e5ea2d]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4b2c44076e9c0aea]::util::run_in_thread_with_globals<rustc_interface[4b2c44076e9c0aea]::util::run_in_thread_pool_with_globals<rustc_interface[4b2c44076e9c0aea]::interface::run_compiler<(), rustc_driver_impl[d80da60e87609ad4]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
30:     0x7f7aa5edb1f4 - <<std[e444442488e5ea2d]::thread::Builder>::spawn_unchecked_<rustc_interface[4b2c44076e9c0aea]::util::run_in_thread_with_globals<rustc_interface[4b2c44076e9c0aea]::util::run_in_thread_pool_with_globals<rustc_interface[4b2c44076e9c0aea]::interface::run_compiler<(), rustc_driver_impl[d80da60e87609ad4]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[ce1fa00964895ff1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
31:     0x7f7aa5edc5eb - std::sys::pal::unix::thread::Thread::new::thread_start::h8985427f793e6fe1
32:     0x7f7a9fa9caa4 - start_thread
                             at ./nptl/pthread_create.c:447:8
33:     0x7f7a9fb29c3c - clone3
                             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78:0
34:                0x0 - <unknown>

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/gh-matthiaskrgr/vcs/github/rust_misc_stuff/tests/im/rustc-ice-2025-05-10T09_15_12-3604898.txt` to your bug report

note: compiler flags: -Z validate-mir

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
note: Clippy version: clippy 0.1.88 (50aa041807 2025-05-08)

warning: 2 warnings emitted

gh-matthiaskrgr@dev-desktop-eu-2:~/vcs/githu

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ labels May 10, 2025
@samueltardieu
Copy link
Contributor

@rustbot label +L-nursery
@rustbot claim

@rustbot rustbot added the L-nursery Lint: Currently in the nursery group label May 10, 2025
github-merge-queue bot pushed a commit that referenced this issue May 10, 2025
The `mir_drops_elaborated_and_const_checked` query result has been
stolen already and cannot be borrowed again. Use the `optimized_mir`
query result instead.

changelog: [`missing_const_for_fn`]: fix ICE with some compilation
options

Fixes #14774

r? @Jarcho
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ L-nursery Lint: Currently in the nursery group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants