Skip to content

debug_assert ICE in type_certainty contradiction detection #12585

Closed
@kpreid

Description

@kpreid

Summary

Minimized reproduction: put the following code in a file:

struct One {
    x: i32,
}
struct Two {
    x: i32,
}

struct Product {}

impl Product {
    pub fn a_method(self, _: ()) {}
}

fn from_array(_: [i32; 2]) -> Product {
    todo!()
}

pub fn main() {
    let one = One { x: 1 };
    let two = Two { x: 2 };

    let product = from_array([one.x, two.x]);
    product.a_method(<()>::default());
}

Run a locally built Clippy with debug assertions on it with cargo dev lint example.rs. See the panic:

thread 'rustc' panicked at clippy_utils/src/ty/type_certainty/certainty.rs:68:21:
Contradiction with Some(DefId(0:3 ~ lib[b113]::One)) and Some(DefId(0:5 ~ lib[b113]::Two))

This is a debug_assert! so it will not occur in any release build. The ICE is not particularly sensitive to the details of the types (it originally happened with One and Two being from extern crates), but it does require all of:

  • two different types put in an array
  • the a_method() call using method call syntax
  • a ::default() call for the argument

Version

Clippy version: clippy 0.1.79 (01646457a 2024-03-28)

Error output

Backtrace

thread 'rustc' panicked at clippy_utils/src/ty/type_certainty/certainty.rs:68:21:
Contradiction with Some(DefId(0:3 ~ lib[b113]::One)) and Some(DefId(0:5 ~ lib[b113]::Two))
stack backtrace:
   0:        0x10436bb47 - std::backtrace::Backtrace::create::hd300636d718c0585
   1:        0x10436ba95 - std::backtrace::Backtrace::force_capture::h8d89553875b8da8d
   2:        0x10cec23d5 - std[e211ec57d13bd5fc]::panicking::update_hook::<alloc[71106a0fa9f3fbf1]::boxed::Box<rustc_driver_impl[a405476ed77058db]::install_ice_hook::{closure#0}>>::{closure#0}
   3:        0x104385a6b - std::panicking::rust_panic_with_hook::hcf50ca252d5a3603
   4:        0x104385394 - std::panicking::begin_panic_handler::{{closure}}::hefb1db5b2050b33a
   5:        0x1043825f9 - std::sys_common::backtrace::__rust_end_short_backtrace::hc6313edcd9c3388a
   6:        0x1043850c6 - _rust_begin_unwind
   7:        0x1043ea8e5 - core::panicking::panic_fmt::ha5bc93e69a450834
   8:        0x101fb0633 - clippy_utils::ty::type_certainty::certainty::Certainty::join::h0e0925fc0bae916b
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/certainty.rs:68:21
   9:        0x101e0e55a - core::ops::function::FnMut::call_mut::haf5470ebee5f6406
                               at /rustc/1388d7a069d872bcfe5e5dd97ef61fa0a586fac0/library/core/src/ops/function.rs:166:5
  10:        0x101e54ab8 - core::iter::adapters::map::map_fold::{{closure}}::ha9838fd2bb6175e1
                               at /rustc/1388d7a069d872bcfe5e5dd97ef61fa0a586fac0/library/core/src/iter/adapters/map.rs:89:21
  11:        0x101ea183a - <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::fold::h9908808caa90d1c1
                               at /rustc/1388d7a069d872bcfe5e5dd97ef61fa0a586fac0/library/core/src/slice/iter/macros.rs:232:27
  12:        0x101e4e771 - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::hf127a46e035bb87d
                               at /rustc/1388d7a069d872bcfe5e5dd97ef61fa0a586fac0/library/core/src/iter/adapters/map.rs:129:9
  13:        0x101de405a - clippy_utils::ty::type_certainty::certainty::join::h2800a89c581221e6
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/certainty.rs:121:5
  14:        0x101f2d391 - clippy_utils::ty::type_certainty::expr_type_certainty::h95e84fe07b5bc4a8
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/mod.rs:37:35
  15:        0x101fbd1d8 - clippy_utils::ty::type_certainty::expr_type_certainty::{{closure}}::h1415f7f05cecef57
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/mod.rs:42:44
  16:        0x101e55138 - core::iter::adapters::map::map_fold::{{closure}}::hfcce86dfe70f19b0
                               at /rustc/1388d7a069d872bcfe5e5dd97ef61fa0a586fac0/library/core/src/iter/adapters/map.rs:89:28
  17:        0x101ea13ba - <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::fold::h81ad596e989fd3c2
                               at /rustc/1388d7a069d872bcfe5e5dd97ef61fa0a586fac0/library/core/src/slice/iter/macros.rs:232:27
  18:        0x101e4e651 - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::hcdfbfea30da8b865
                               at /rustc/1388d7a069d872bcfe5e5dd97ef61fa0a586fac0/library/core/src/iter/adapters/map.rs:129:9
  19:        0x101de3fd6 - clippy_utils::ty::type_certainty::certainty::meet::h3ae6637d1fd00743
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/certainty.rs:116:5
  20:        0x101f2d789 - clippy_utils::ty::type_certainty::expr_type_certainty::h95e84fe07b5bc4a8
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/mod.rs:42:17
  21:        0x101fbd4e9 - clippy_utils::ty::type_certainty::path_segment_certainty::{{closure}}::h702032a1d378771a
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/mod.rs:249:58
  22:        0x101e5d898 - core::option::Option<T>::map_or::h2f5fefc0fc4d88aa
                               at /rustc/1388d7a069d872bcfe5e5dd97ef61fa0a586fac0/library/core/src/option.rs:1132:24
  23:        0x101f2e6eb - clippy_utils::ty::type_certainty::path_segment_certainty::h7f62ab2ee43fec24
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/mod.rs:247:27
  24:        0x101fbd2ec - clippy_utils::ty::type_certainty::qpath_certainty::{{closure}}::ha56d703401b8e536
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/mod.rs:164:21
  25:        0x101e6fadf - <core::iter::adapters::enumerate::Enumerate<I> as core::iter::traits::iterator::Iterator>::fold::enumerate::{{closure}}::h94d2082e3866f2a7
                               at /rustc/1388d7a069d872bcfe5e5dd97ef61fa0a586fac0/library/core/src/iter/adapters/enumerate.rs:107:27
  26:        0x101e9fb6e - <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::fold::h2533d89cdb966c40
                               at /rustc/1388d7a069d872bcfe5e5dd97ef61fa0a586fac0/library/core/src/slice/iter/macros.rs:232:27
  27:        0x101e6f93b - <core::iter::adapters::enumerate::Enumerate<I> as core::iter::traits::iterator::Iterator>::fold::hb6b777821b45aa40
                               at /rustc/1388d7a069d872bcfe5e5dd97ef61fa0a586fac0/library/core/src/iter/adapters/enumerate.rs:113:9
  28:        0x101f2dde0 - clippy_utils::ty::type_certainty::qpath_certainty::hfa0815ea9ecc1f6d
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/mod.rs:161:13
  29:        0x101f2d684 - clippy_utils::ty::type_certainty::expr_type_certainty::h95e84fe07b5bc4a8
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/mod.rs:82:34
  30:        0x101f2d2b5 - clippy_utils::ty::type_certainty::expr_type_is_certain::h592e2964a58c0946
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_utils/src/ty/type_certainty/mod.rs:27:5
  31:        0x101be5b97 - clippy_lints::methods::or_fun_call::check::check_unwrap_or_default::hab30390755d9d821
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_lints/src/methods/or_fun_call.rs:39:13
  32:        0x101be5898 - clippy_lints::methods::or_fun_call::check::h7f776c8b76199f95
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_lints/src/methods/or_fun_call.rs:200:25
  33:        0x101856a2b - <clippy_lints::methods::Methods as rustc_lint::passes::LateLintPass>::check_expr::hd49d5138b198f705
                               at /Users/kpreid/Projects/rust/contributing/rust-clippy/clippy_lints/src/methods/mod.rs:4270:17
  34:        0x10d6f8933 - <rustc_lint[fdccbe2b490645af]::late::LateContextAndPass<rustc_lint[fdccbe2b490645af]::late::RuntimeCombinedLateLintPass>>::with_lint_attrs::<<rustc_lint[fdccbe2b490645af]::late::LateContextAndPass<rustc_lint[fdccbe2b490645af]::late::RuntimeCombinedLateLintPass> as rustc_hir[7701f6bd8425be18]::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}>
  35:        0x10d69e262 - rustc_hir[7701f6bd8425be18]::intravisit::walk_block::<rustc_lint[fdccbe2b490645af]::late::LateContextAndPass<rustc_lint[fdccbe2b490645af]::late::RuntimeCombinedLateLintPass>>
  36:        0x10d6f9586 - <rustc_lint[fdccbe2b490645af]::late::LateContextAndPass<rustc_lint[fdccbe2b490645af]::late::RuntimeCombinedLateLintPass>>::with_lint_attrs::<<rustc_lint[fdccbe2b490645af]::late::LateContextAndPass<rustc_lint[fdccbe2b490645af]::late::RuntimeCombinedLateLintPass> as rustc_hir[7701f6bd8425be18]::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}>
  37:        0x10d6fff57 - <rustc_lint[fdccbe2b490645af]::late::LateContextAndPass<rustc_lint[fdccbe2b490645af]::late::RuntimeCombinedLateLintPass> as rustc_hir[7701f6bd8425be18]::intravisit::Visitor>::visit_nested_body
  38:        0x10d6fbae3 - <rustc_lint[fdccbe2b490645af]::late::LateContextAndPass<rustc_lint[fdccbe2b490645af]::late::RuntimeCombinedLateLintPass>>::with_lint_attrs::<<rustc_lint[fdccbe2b490645af]::late::LateContextAndPass<rustc_lint[fdccbe2b490645af]::late::RuntimeCombinedLateLintPass> as rustc_hir[7701f6bd8425be18]::intravisit::Visitor>::visit_item::{closure#0}>
  39:        0x10d6a4a51 - rustc_hir[7701f6bd8425be18]::intravisit::walk_mod::<rustc_lint[fdccbe2b490645af]::late::LateContextAndPass<rustc_lint[fdccbe2b490645af]::late::RuntimeCombinedLateLintPass>>
  40:        0x10d7011a2 - rustc_lint[fdccbe2b490645af]::late::check_crate::{closure#0}
  41:        0x10d700956 - rustc_lint[fdccbe2b490645af]::late::check_crate
  42:        0x10d66ef33 - rustc_interface[ec6a3316aa0ebffc]::passes::analysis
  43:        0x10e2eaeda - rustc_query_impl[822d58ec21b313ac]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[822d58ec21b313ac]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[64579eedb7c26b25]::query::erase::Erased<[u8; 1usize]>>
  44:        0x10e0d6ace - rustc_query_system[9f5f82b99e5205d2]::query::plumbing::try_execute_query::<rustc_query_impl[822d58ec21b313ac]::DynamicConfig<rustc_query_system[9f5f82b99e5205d2]::query::caches::SingleCache<rustc_middle[64579eedb7c26b25]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[822d58ec21b313ac]::plumbing::QueryCtxt, false>
  45:        0x10e2f51d7 - rustc_query_impl[822d58ec21b313ac]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  46:        0x10ce71482 - <rustc_interface[ec6a3316aa0ebffc]::queries::QueryResult<&rustc_middle[64579eedb7c26b25]::ty::context::GlobalCtxt>>::enter::<core[7e138c13ff563624]::result::Result<(), rustc_span[d860f9b6ae956ac2]::ErrorGuaranteed>, rustc_driver_impl[a405476ed77058db]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  47:        0x10cec8fe2 - rustc_interface[ec6a3316aa0ebffc]::interface::run_compiler::<core[7e138c13ff563624]::result::Result<(), rustc_span[d860f9b6ae956ac2]::ErrorGuaranteed>, rustc_driver_impl[a405476ed77058db]::run_compiler::{closure#0}>::{closure#0}
  48:        0x10cebd076 - std[e211ec57d13bd5fc]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ec6a3316aa0ebffc]::util::run_in_thread_with_globals<rustc_interface[ec6a3316aa0ebffc]::util::run_in_thread_pool_with_globals<rustc_interface[ec6a3316aa0ebffc]::interface::run_compiler<core[7e138c13ff563624]::result::Result<(), rustc_span[d860f9b6ae956ac2]::ErrorGuaranteed>, rustc_driver_impl[a405476ed77058db]::run_compiler::{closure#0}>::{closure#0}, core[7e138c13ff563624]::result::Result<(), rustc_span[d860f9b6ae956ac2]::ErrorGuaranteed>>::{closure#0}, core[7e138c13ff563624]::result::Result<(), rustc_span[d860f9b6ae956ac2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7e138c13ff563624]::result::Result<(), rustc_span[d860f9b6ae956ac2]::ErrorGuaranteed>>
  49:        0x10cecb9f8 - <<std[e211ec57d13bd5fc]::thread::Builder>::spawn_unchecked_<rustc_interface[ec6a3316aa0ebffc]::util::run_in_thread_with_globals<rustc_interface[ec6a3316aa0ebffc]::util::run_in_thread_pool_with_globals<rustc_interface[ec6a3316aa0ebffc]::interface::run_compiler<core[7e138c13ff563624]::result::Result<(), rustc_span[d860f9b6ae956ac2]::ErrorGuaranteed>, rustc_driver_impl[a405476ed77058db]::run_compiler::{closure#0}>::{closure#0}, core[7e138c13ff563624]::result::Result<(), rustc_span[d860f9b6ae956ac2]::ErrorGuaranteed>>::{closure#0}, core[7e138c13ff563624]::result::Result<(), rustc_span[d860f9b6ae956ac2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7e138c13ff563624]::result::Result<(), rustc_span[d860f9b6ae956ac2]::ErrorGuaranteed>>::{closure#1} as core[7e138c13ff563624]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:        0x10438ec19 - std::sys::pal::unix::thread::Thread::new::thread_start::h194b5d76f1fde531
  51:     0x7ff8054ce18b - __pthread_start


rustc version: 1.79.0-nightly (1388d7a06 2024-03-20)
platform: x86_64-apple-darwin

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack

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