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 when evaluating trait selection obligation #13862

Open
mciantyre opened this issue Dec 21, 2024 · 0 comments · May be fixed by #13863
Open

ICE when evaluating trait selection obligation #13862

mciantyre opened this issue Dec 21, 2024 · 0 comments · May be fixed by #13863
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@mciantyre
Copy link

mciantyre commented Dec 21, 2024

Summary

The example below causes a panic in clippy 1.83. It will also cause a panic in older clippy releases 1.82 and 1.81. If it helps, I set up a repository here containing the example and reproductions.

The ICE disappears if we apply this patch to the example, removing the Channel's generic DMA_INST.

#![no_std]

use core::{
    future::Future,
    pin::Pin,
    task::{Context, Poll},
};

pub struct Channel<const DMA_INST: u8>;

pub struct Write<'a, const DMA_INST: u8> {
    _channel: &'a Channel<DMA_INST>,
}

impl<const DMA_INST: u8> Future for Write<'_, DMA_INST> {
    type Output = ();
    fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
        Poll::Ready(())
    }
}

pub struct Periph;

impl Periph {
    pub fn dma_write<'a, const DMA_INST: u8>(
        &'a mut self,
        _channel: &'a mut Channel<DMA_INST>,
    ) -> Write<'a, DMA_INST> {
        Write { _channel }
    }
}

Version

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-apple-darwin
release: 1.83.0
LLVM version: 19.1.1

Error output

Backtrace

thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:363:36:
called `Option::unwrap()` on a `None` value
stack backtrace:
 0:        0x10eb70026 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h0fd572ca60ee9a4e
 1:        0x10bd5ce83 - core::fmt::write::hbc078725bba6692a
 2:        0x10eb63db2 - std::io::Write::write_fmt::h100f2ae009a3df53
 3:        0x10eb6fe72 - std::sys::backtrace::BacktraceLock::print::hf0d5a155265a9dd5
 4:        0x10eb7274e - std::panicking::default_hook::{{closure}}::h5499fb85b118791b
 5:        0x10eb7259c - std::panicking::default_hook::h3be9b9b36bd75e8f
 6:        0x10c95821d - std[a09b67190130f411]::panicking::update_hook::<alloc[285955a53c51d5e7]::boxed::Box<rustc_driver_impl[64a020ea63dda478]::install_ice_hook::{closure#0}>>::{closure#0}
 7:        0x10eb73018 - std::panicking::rust_panic_with_hook::h10014b4a7f4c072b
 8:        0x10eb72c55 - std::panicking::begin_panic_handler::{{closure}}::hc871510d12acad65
 9:        0x10eb704d9 - std::sys::backtrace::__rust_end_short_backtrace::hca0d49bc0c1e56d3
10:        0x10eb728cc - _rust_begin_unwind
11:        0x1117f075f - core::panicking::panic_fmt::haa8e13f18984c8e5
12:        0x1117f0804 - core::panicking::panic::hc2aae38099a8d6cf
13:        0x1117f06d8 - core::option::unwrap_failed::hb6226bf7a36b0a5a
14:        0x10d79dab8 - <rustc_middle[205dbd0098ce5d0a]::ty::sty::ParamConst>::find_ty_from_env
15:        0x10e951ec0 - <rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluate_predicate_recursively::{closure#0}::{closure#0}
16:        0x10e950fc2 - <rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluate_predicate_recursively
17:        0x10e9546ad - <rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluate_candidate::{closure#0}::{closure#0}
18:        0x10e8dea20 - <rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluation_probe::<<rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluate_candidate::{closure#0}::{closure#0}>
19:        0x10e953e5f - <rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively::{closure#0}::{closure#1}
20:        0x10e95288a - <rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively::{closure#0}
21:        0x10e95129c - <rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluate_predicate_recursively::{closure#0}::{closure#0}
22:        0x10e950fc2 - <rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluate_predicate_recursively
23:        0x10e8dee72 - <rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluation_probe::<<rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluate_root_obligation::{closure#0}>::{closure#0}
24:        0x10e8de8d5 - <rustc_trait_selection[3f465ba9c174d506]::traits::select::SelectionContext>::evaluate_root_obligation
25:        0x10ea001e7 - rustc_traits[d5556349cb396c96]::evaluate_obligation::evaluate_obligation
26:        0x10e13ed5c - rustc_query_impl[15b127f51fbcb8d2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[15b127f51fbcb8d2]::query_impl::evaluate_obligation::dynamic_query::{closure#2}::{closure#0}, rustc_middle[205dbd0098ce5d0a]::query::erase::Erased<[u8; 2usize]>>
27:        0x10e0f5ddf - <rustc_query_impl[15b127f51fbcb8d2]::query_impl::evaluate_obligation::dynamic_query::{closure#2} as core[239cfdf43388e8c4]::ops::function::FnOnce<(rustc_middle[205dbd0098ce5d0a]::ty::context::TyCtxt, rustc_type_ir[41f7d002a1ed06dd]::canonical::Canonical<rustc_middle[205dbd0098ce5d0a]::ty::context::TyCtxt, rustc_middle[205dbd0098ce5d0a]::ty::ParamEnvAnd<rustc_middle[205dbd0098ce5d0a]::ty::predicate::Predicate>>)>>::call_once
28:        0x10dfb1a65 - rustc_query_system[1984efb36f276886]::query::plumbing::try_execute_query::<rustc_query_impl[15b127f51fbcb8d2]::DynamicConfig<rustc_query_system[1984efb36f276886]::query::caches::DefaultCache<rustc_type_ir[41f7d002a1ed06dd]::canonical::Canonical<rustc_middle[205dbd0098ce5d0a]::ty::context::TyCtxt, rustc_middle[205dbd0098ce5d0a]::ty::ParamEnvAnd<rustc_middle[205dbd0098ce5d0a]::ty::predicate::Predicate>>, rustc_middle[205dbd0098ce5d0a]::query::erase::Erased<[u8; 2usize]>>, false, false, false>, rustc_query_impl[15b127f51fbcb8d2]::plumbing::QueryCtxt, true>
29:        0x10e1fc9d7 - rustc_query_impl[15b127f51fbcb8d2]::query_impl::evaluate_obligation::get_query_incr::__rust_end_short_backtrace
30:        0x10e93fea1 - <rustc_infer[4a5b37671f7872af]::infer::InferCtxt as rustc_trait_selection[3f465ba9c174d506]::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation
31:        0x101903950 - clippy_utils[a707c304bec98fbe]::ty::implements_trait
32:        0x101609b32 - clippy_lints[9cbea354f1d3b5a8]::doc::missing_headers::check
33:        0x10160c119 - <clippy_lints[9cbea354f1d3b5a8]::doc::Documentation as rustc_lint[4e10caf754b7c4f2]::passes::LateLintPass>::check_attributes
34:        0x10d47db56 - <rustc_lint[4e10caf754b7c4f2]::late::LateContextAndPass<rustc_lint[4e10caf754b7c4f2]::late::RuntimeCombinedLateLintPass>>::with_lint_attrs::<<rustc_lint[4e10caf754b7c4f2]::late::LateContextAndPass<rustc_lint[4e10caf754b7c4f2]::late::RuntimeCombinedLateLintPass> as rustc_hir[a51b4994050fe052]::intravisit::Visitor>::visit_item::{closure#0}>
35:        0x10d3a6a78 - rustc_hir[a51b4994050fe052]::intravisit::walk_mod::<rustc_lint[4e10caf754b7c4f2]::late::LateContextAndPass<rustc_lint[4e10caf754b7c4f2]::late::RuntimeCombinedLateLintPass>>
36:        0x10d48579d - rustc_lint[4e10caf754b7c4f2]::late::check_crate
37:        0x10d34e626 - rustc_interface[35c538ee69994c62]::passes::analysis
38:        0x10e140f3a - rustc_query_impl[15b127f51fbcb8d2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[15b127f51fbcb8d2]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[205dbd0098ce5d0a]::query::erase::Erased<[u8; 1usize]>>
39:        0x10df94cbc - rustc_query_system[1984efb36f276886]::query::plumbing::try_execute_query::<rustc_query_impl[15b127f51fbcb8d2]::DynamicConfig<rustc_query_system[1984efb36f276886]::query::caches::SingleCache<rustc_middle[205dbd0098ce5d0a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[15b127f51fbcb8d2]::plumbing::QueryCtxt, true>
40:        0x10e15a8be - rustc_query_impl[15b127f51fbcb8d2]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
41:        0x10c90ec3b - <rustc_interface[35c538ee69994c62]::queries::QueryResult<&rustc_middle[205dbd0098ce5d0a]::ty::context::GlobalCtxt>>::enter::<core[239cfdf43388e8c4]::result::Result<(), rustc_span[a545ab19381ab211]::ErrorGuaranteed>, rustc_driver_impl[64a020ea63dda478]::run_compiler::{closure#0}::{closure#1}::{closure#5}>
42:        0x10c9569b2 - rustc_interface[35c538ee69994c62]::interface::run_compiler::<core[239cfdf43388e8c4]::result::Result<(), rustc_span[a545ab19381ab211]::ErrorGuaranteed>, rustc_driver_impl[64a020ea63dda478]::run_compiler::{closure#0}>::{closure#1}
43:        0x10c947343 - std[a09b67190130f411]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[35c538ee69994c62]::util::run_in_thread_with_globals<rustc_interface[35c538ee69994c62]::interface::run_compiler<core[239cfdf43388e8c4]::result::Result<(), rustc_span[a545ab19381ab211]::ErrorGuaranteed>, rustc_driver_impl[64a020ea63dda478]::run_compiler::{closure#0}>::{closure#1}, core[239cfdf43388e8c4]::result::Result<(), rustc_span[a545ab19381ab211]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[239cfdf43388e8c4]::result::Result<(), rustc_span[a545ab19381ab211]::ErrorGuaranteed>>
44:        0x10c95c7cc - <<std[a09b67190130f411]::thread::Builder>::spawn_unchecked_<rustc_interface[35c538ee69994c62]::util::run_in_thread_with_globals<rustc_interface[35c538ee69994c62]::interface::run_compiler<core[239cfdf43388e8c4]::result::Result<(), rustc_span[a545ab19381ab211]::ErrorGuaranteed>, rustc_driver_impl[64a020ea63dda478]::run_compiler::{closure#0}>::{closure#1}, core[239cfdf43388e8c4]::result::Result<(), rustc_span[a545ab19381ab211]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[239cfdf43388e8c4]::result::Result<(), rustc_span[a545ab19381ab211]::ErrorGuaranteed>>::{closure#1} as core[239cfdf43388e8c4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
45:        0x10eb7dcbb - std::sys::pal::unix::thread::Thread::new::thread_start::h08338ace24ce5652
46:     0x7ff81a8a218b - __pthread_start

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: rustc 1.83.0 (90b35a623 2024-11-26) running on x86_64-apple-darwin

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED]

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

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `Write<'_, DMA_INST>: core::future::future::Future`
#1 [analysis] running analysis passes on this crate
end of query stack
note: Clippy version: clippy 0.1.83 (90b35a62 2024-11-26)

error: could not compile `clippy-ice` (lib)

@mciantyre mciantyre added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ labels Dec 21, 2024
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) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant