Skip to content

ICE: None in `cast_possible_truncation #12352

Closed

Description

@matthiaskrgr

Summary

//@ run-pass
#![allow(unused_variables)]
enum Foo {
    Bar = (|_: T::Item| { }, 42).1,
}

fn main() {
    assert_eq!(Foo::Bar as usize, 42);
}

Version

rustc 1.78.0-nightly (381d69953 2024-02-24)
binary: rustc
commit-hash: 381d69953bb7c3390cec0fee200f24529cb6320f
commit-date: 2024-02-24
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Error output

Backtrace

thread 'rustc' panicked at src/tools/clippy/clippy_utils/src/ty.rs:888:73:
called `Option::unwrap()` on a `None` value
stack backtrace:
 0:     0x7fe9ccfc1af6 - std::backtrace_rs::backtrace::libunwind::trace::h109bf01707803b21
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
 1:     0x7fe9ccfc1af6 - std::backtrace_rs::backtrace::trace_unsynchronized::hefcf68af32ee251e
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
 2:     0x7fe9ccfc1af6 - std::sys_common::backtrace::_print_fmt::h31a90ba3e667b38a
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/sys_common/backtrace.rs:68:5
 3:     0x7fe9ccfc1af6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he4f0cdaaa4ef639a
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/sys_common/backtrace.rs:44:22
 4:     0x7fe9cd012a7c - core::fmt::rt::Argument::fmt::h1ec5088860cf50b0
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/core/src/fmt/rt.rs:142:9
 5:     0x7fe9cd012a7c - core::fmt::write::h689bbff3655bb9d8
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/core/src/fmt/mod.rs:1120:17
 6:     0x7fe9ccfb642f - std::io::Write::write_fmt::h7ecff4baaa465710
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/io/mod.rs:1846:15
 7:     0x7fe9ccfc18a4 - std::sys_common::backtrace::_print::h9485e3dec28344ea
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/sys_common/backtrace.rs:47:5
 8:     0x7fe9ccfc18a4 - std::sys_common::backtrace::print::heeebf1d6105a1e60
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/sys_common/backtrace.rs:34:9
 9:     0x7fe9ccfc45eb - std::panicking::default_hook::{{closure}}::h88c7af55bc049fb9
10:     0x7fe9ccfc4339 - std::panicking::default_hook::haa382d9c5bfbc23c
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/panicking.rs:292:9
11:     0x7fe9c9c82fdc - std[c7add3eab026fdb7]::panicking::update_hook::<alloc[2ba798d9f5e2777d]::boxed::Box<rustc_driver_impl[4d7390d1e092a0cc]::install_ice_hook::{closure#0}>>::{closure#0}
12:     0x7fe9ccfc4d50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h8d3a037cf4dab9e8
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/alloc/src/boxed.rs:2030:9
13:     0x7fe9ccfc4d50 - std::panicking::rust_panic_with_hook::hd9ee0be535a8506e
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/panicking.rs:783:13
14:     0x7fe9ccfc4a59 - std::panicking::begin_panic_handler::{{closure}}::h68a8f56dc216071f
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/panicking.rs:649:13
15:     0x7fe9ccfc1fd6 - std::sys_common::backtrace::__rust_end_short_backtrace::h6d2f61b909cc18f6
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/sys_common/backtrace.rs:171:18
16:     0x7fe9ccfc47c4 - rust_begin_unwind
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/panicking.rs:645:5
17:     0x7fe9cd00ef95 - core::panicking::panic_fmt::h1771cb6a138bf784
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/core/src/panicking.rs:72:14
18:     0x7fe9cd00f053 - core::panicking::panic::hf28077d97f77dc45
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/core/src/panicking.rs:144:5
19:     0x7fe9cd00ed26 - core::option::unwrap_failed::h5c249521c970c316
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/core/src/option.rs:1985:5
20:     0x55a2aa1895f3 - clippy_utils[aa522ab0b4e2c511]::ty::get_discriminant_value
21:     0x55a2a9f4a74c - clippy_lints[104fdc8d5d35ad3d]::casts::cast_possible_truncation::check
22:     0x55a2a9f4ebb9 - <clippy_lints[104fdc8d5d35ad3d]::casts::Casts as rustc_lint[e54ff600f0934aae]::passes::LateLintPass>::check_expr
23:     0x7fe9ca00e622 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_expr::{closure#0}
24:     0x7fe9ca00e4b8 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_expr
25:     0x7fe9ca00e78f - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_expr::{closure#0}
26:     0x7fe9ca00e4b8 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_expr
27:     0x7fe9ca00e737 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_expr::{closure#0}
28:     0x7fe9ca00e4b8 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_expr
29:     0x7fe9ca00e862 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_expr::{closure#0}
30:     0x7fe9ca00e4b8 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_expr
31:     0x7fe9ca00f26c - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_block
32:     0x7fe9ca00eac4 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_expr::{closure#0}
33:     0x7fe9ca00e4b8 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_expr
34:     0x7fe9ca00e3b8 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_nested_body
35:     0x7fe9ca00f074 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_fn
36:     0x7fe9c9ffe454 - <rustc_lint[e54ff600f0934aae]::late::LateContextAndPass<rustc_lint[e54ff600f0934aae]::late::RuntimeCombinedLateLintPass> as rustc_hir[54d089fe68af4196]::intravisit::Visitor>::visit_nested_item
37:     0x7fe9cbbd0d3d - rustc_lint[e54ff600f0934aae]::late::check_crate::{closure#0}
38:     0x7fe9cbbd0f91 - rustc_lint[e54ff600f0934aae]::late::check_crate
39:     0x7fe9cbbcaea5 - rustc_interface[a8e077c2594aedc9]::passes::analysis
40:     0x7fe9cbbc9b99 - rustc_query_impl[3dbe716596c9e9df]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3dbe716596c9e9df]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[be2fc7c2c4a6d89d]::query::erase::Erased<[u8; 1usize]>>
41:     0x7fe9cbdd2a65 - rustc_query_system[c21ecc0bfee3e160]::query::plumbing::try_execute_query::<rustc_query_impl[3dbe716596c9e9df]::DynamicConfig<rustc_query_system[c21ecc0bfee3e160]::query::caches::SingleCache<rustc_middle[be2fc7c2c4a6d89d]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[3dbe716596c9e9df]::plumbing::QueryCtxt, false>
42:     0x7fe9cbdd27c9 - rustc_query_impl[3dbe716596c9e9df]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
43:     0x7fe9cbcfa256 - rustc_interface[a8e077c2594aedc9]::interface::run_compiler::<core[53164db537a29558]::result::Result<(), rustc_span[e3ed1f921c615197]::ErrorGuaranteed>, rustc_driver_impl[4d7390d1e092a0cc]::run_compiler::{closure#0}>::{closure#0}
44:     0x7fe9cbfc7cc5 - std[c7add3eab026fdb7]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[a8e077c2594aedc9]::util::run_in_thread_with_globals<rustc_interface[a8e077c2594aedc9]::util::run_in_thread_pool_with_globals<rustc_interface[a8e077c2594aedc9]::interface::run_compiler<core[53164db537a29558]::result::Result<(), rustc_span[e3ed1f921c615197]::ErrorGuaranteed>, rustc_driver_impl[4d7390d1e092a0cc]::run_compiler::{closure#0}>::{closure#0}, core[53164db537a29558]::result::Result<(), rustc_span[e3ed1f921c615197]::ErrorGuaranteed>>::{closure#0}, core[53164db537a29558]::result::Result<(), rustc_span[e3ed1f921c615197]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[53164db537a29558]::result::Result<(), rustc_span[e3ed1f921c615197]::ErrorGuaranteed>>
45:     0x7fe9cbfc7af2 - <<std[c7add3eab026fdb7]::thread::Builder>::spawn_unchecked_<rustc_interface[a8e077c2594aedc9]::util::run_in_thread_with_globals<rustc_interface[a8e077c2594aedc9]::util::run_in_thread_pool_with_globals<rustc_interface[a8e077c2594aedc9]::interface::run_compiler<core[53164db537a29558]::result::Result<(), rustc_span[e3ed1f921c615197]::ErrorGuaranteed>, rustc_driver_impl[4d7390d1e092a0cc]::run_compiler::{closure#0}>::{closure#0}, core[53164db537a29558]::result::Result<(), rustc_span[e3ed1f921c615197]::ErrorGuaranteed>>::{closure#0}, core[53164db537a29558]::result::Result<(), rustc_span[e3ed1f921c615197]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[53164db537a29558]::result::Result<(), rustc_span[e3ed1f921c615197]::ErrorGuaranteed>>::{closure#1} as core[53164db537a29558]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
46:     0x7fe9ccfce725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h160bc5962de4c385
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/alloc/src/boxed.rs:2016:9
47:     0x7fe9ccfce725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h55e504807a34477d
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/alloc/src/boxed.rs:2016:9
48:     0x7fe9ccfce725 - std::sys::pal::unix::thread::Thread::new::thread_start::h61059cf7b19988e2
                             at /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/sys/pal/unix/thread.rs:108:17
49:     0x7fe9c6b6055a - <unknown>
50:     0x7fe9c6bdda3c - <unknown>
51:                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 attach the file at `/tmp/im/rustc-ice-2024-02-26T05_30_13-3731547.txt` to your bug report

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
note: Clippy version: clippy 0.1.78 (381d699 2024-02-24)

error[E0433]: failed to resolve: use of undeclared type `T`
--> /home/matthias/vcs/github/rust_misc_stuff/tests/icemaker_omni_1/9937CCD9708EE78AB2F64C1F1365AF5445CB14A89F4E415E192E70758F2394EE.rs:4:16
|
4 |     Bar = (|_: T::Item| { }, 42).1,
|                ^ use of undeclared type `T`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0433`.

Activity

  1. added
    C-bugCategory: Clippy is not doing the correct thing
    I-ICEIssue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
    on Feb 26, 2024
  2. matthiaskrgr commented on Feb 27, 2024

    @matthiaskrgr
    MemberAuthor

    another one

    #[derive(Copy, Clone)]
    union Foo {
        a: isize,
        b: std::num::NonZeroU64,
    }
    
    enum Bar {
        Boo = [unsafe { Foo { b: () }.a }; 4][3],
        //~^ ERROR evaluation of constant value failed
        //~| uninitialized
    }
    
    fn main() {
        assert_ne!(Bar::Boo as isize, 0);
    }
  3. Jarcho commented on Mar 24, 2024

    @Jarcho
    Contributor

    Doesn't reproduce. Lints shouldn't have run due to E0433 for the first example, or E0308 in the second.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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