rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.01k stars 12.54k forks source link

ICE when implementing a generic trait + generic supertrait (and default values) #129556

Open ReaTekWither opened 4 weeks ago

ReaTekWither commented 4 weeks ago

Summary

The ICE occurs if

The ICE occurs as the trait is implemented for a type. The targeted type doesn't have to be the same as the generic one.

#![feature(adt_const_params)]
#![feature(generic_const_exprs)]

use core::marker::ConstParamTy;

// #[derive(ConstParamTy, PartialEq, Eq)]
// struct StructOrEnum;

#[derive(ConstParamTy, PartialEq, Eq)]
enum StructOrEnum {
    A,
}

trait TraitParent<const SMTH: StructOrEnum = { StructOrEnum::A }> {}

trait TraitChild<const SMTH: StructOrEnum = { StructOrEnum::A }>: TraitParent<SMTH> {}

impl TraitParent for StructOrEnum {}

// ICE occurs
impl TraitChild for StructOrEnum {}

// ICE does not occur
// impl TraitChild<{ StructOrEnum::A }> for StructOrEnum {}

Version

rustc 1.82.0-nightly (f167efad2 2024-08-24)
binary: rustc
commit-hash: f167efad2f51088d86180ee89177b3d7c9e7c2f5
commit-date: 2024-08-24
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

Error output

Backtrace

``` stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: >::const_param_out_of_range 3: as rustc_type_ir::fold::TypeFolder>::fold_const.llvm.11519418143500691559.cold 4: ::instantiate_into 5: ::nominal_obligations 6: >::visit_const 7: ::process_obligation 8: >::process_obligations:: 9: >::assumed_wf_types_and_report_errors 10: rustc_hir_analysis::check::wfcheck::check_well_formed [... omitted 1 frame ...] 11: rustc_hir_analysis::check::wfcheck::check_mod_type_wf [... omitted 1 frame ...] 12: rustc_hir_analysis::check_crate 13: rustc_interface::passes::run_required_analyses 14: rustc_interface::passes::analysis [... omitted 1 frame ...] 15: rustc_interface::interface::run_compiler::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1} ```

ICE

``` thread 'rustc' panicked at /rustc/f167efad2f51088d86180ee89177b3d7c9e7c2f5/compiler/rustc_type_ir/src/binder.rs:739:9: const parameter `SMTH/#1` (SMTH/#1/1) out of range when instantiating args=[StructOrEnum] stack backtrace: 0: 0x7044d54c4ea5 - std::backtrace::Backtrace::create::h60f0872d50b7947d 1: 0x7044d39d1ec5 - std::backtrace::Backtrace::force_capture::h5f5782d9f084b444 2: 0x7044d2b602ae - std[6e15924ca43b8509]::panicking::update_hook::>::{closure#0} 3: 0x7044d39e9d37 - std::panicking::rust_panic_with_hook::h48ec1454fab3e9d6 4: 0x7044d39e99f7 - std::panicking::begin_panic_handler::{{closure}}::hdfdc79a140009172 5: 0x7044d39e71f9 - std::sys::backtrace::__rust_end_short_backtrace::h5e9ef3624d34a08c 6: 0x7044d39e96c4 - rust_begin_unwind 7: 0x7044d0b9f263 - core::panicking::panic_fmt::h5c7dda2686e962d9 8: 0x7044d30f2bb9 - >::const_param_out_of_range 9: 0x7044d55da828 - as rustc_type_ir[a178b1c04a843a22]::fold::TypeFolder>::fold_const.llvm.11519418143500691559.cold 10: 0x7044d423268c - ::instantiate_into 11: 0x7044d422f5a3 - ::nominal_obligations 12: 0x7044d4c88362 - >::visit_const 13: 0x7044d08b4bdf - ::process_obligation 14: 0x7044d44178c1 - >::process_obligations:: 15: 0x7044d440a8c3 - >::assumed_wf_types_and_report_errors 16: 0x7044d17183ca - rustc_hir_analysis[2f099064b091af30]::check::wfcheck::check_well_formed 17: 0x7044d45a6d27 - rustc_query_impl[7a841671113bb270]::plumbing::__rust_begin_short_backtrace::> 18: 0x7044d45aa4ea - rustc_query_system[77a41dfa2d87d677]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[7a841671113bb270]::plumbing::QueryCtxt, true> 19: 0x7044d45a9ef8 - rustc_query_impl[7a841671113bb270]::query_impl::check_well_formed::get_query_incr::__rust_end_short_backtrace 20: 0x7044d45a7acb - rustc_hir_analysis[2f099064b091af30]::check::wfcheck::check_mod_type_wf 21: 0x7044d45a7909 - rustc_query_impl[7a841671113bb270]::plumbing::__rust_begin_short_backtrace::> 22: 0x7044d508fbcc - rustc_query_system[77a41dfa2d87d677]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[7a841671113bb270]::plumbing::QueryCtxt, true> 23: 0x7044d509089b - rustc_query_impl[7a841671113bb270]::query_impl::check_mod_type_wf::get_query_incr::__rust_end_short_backtrace 24: 0x7044d473c34d - rustc_hir_analysis[2f099064b091af30]::check_crate 25: 0x7044d4739abf - rustc_interface[eb6eb7ed9ab023cb]::passes::run_required_analyses 26: 0x7044d4d59c9e - rustc_interface[eb6eb7ed9ab023cb]::passes::analysis 27: 0x7044d4d59c71 - rustc_query_impl[7a841671113bb270]::plumbing::__rust_begin_short_backtrace::> 28: 0x7044d520d90d - rustc_query_system[77a41dfa2d87d677]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[7a841671113bb270]::plumbing::QueryCtxt, true> 29: 0x7044d520d5ba - rustc_query_impl[7a841671113bb270]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace 30: 0x7044d4ff43aa - rustc_interface[eb6eb7ed9ab023cb]::interface::run_compiler::, rustc_driver_impl[d6b1c5b97f2d776c]::run_compiler::{closure#0}>::{closure#1} 31: 0x7044d506f390 - std[6e15924ca43b8509]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[d6b1c5b97f2d776c]::run_compiler::{closure#0}>::{closure#1}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#0}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>> 32: 0x7044d506f9fa - <::spawn_unchecked_, rustc_driver_impl[d6b1c5b97f2d776c]::run_compiler::{closure#0}>::{closure#1}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#0}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f2f627d3c87d2691]::result::Result<(), rustc_span[641b1e127128c80]::ErrorGuaranteed>>::{closure#1} as core[f2f627d3c87d2691]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 33: 0x7044d506fd6b - std::sys::pal::unix::thread::Thread::new::thread_start::h5ac727470998e7f2 34: 0x7044d680d39d - 35: 0x7044d689249c - 36: 0x0 - rustc version: 1.82.0-nightly (f167efad2 2024-08-24) platform: x86_64-unknown-linux-gnu query stack during panic: #0 [check_well_formed] checking that `` is well-formed rust-lang/rust-clippy#1 [check_mod_type_wf] checking that types are well-formed in top-level module rust-lang/rust-clippy#2 [analysis] running analysis passes on this crate end of query stack ```

y21 commented 4 weeks ago

(Moved to rust-lang/rust because this doesn't seem clippy specific and happens on regular rustc compilations)