rust-lang / rust

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

ICE: `When translating generic parameters from DefId, the expected specialization failed to hold` #132519

Open matthiaskrgr opened 1 month ago

matthiaskrgr commented 1 month ago

auto-reduced (treereduce-rust):

#![feature(specialization)]

trait Spec {
    type Assoc;
}

default impl<T, U> Spec for T
where
    T: IntoIterator<Item = U>,
{
    type Assoc = U;
}

impl<T> Spec for [T; 0] {}

fn main() {
    let x: <[_; 0] as Spec>::Assoc = 1;
}

original:

//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
//@[next] check-pass
//@[current] known-bug: unknown
//@[current] failure-status: 101
//~^ ERROR defaults for generic parameters are not allowed in `for<...>` binders

// Tests that rebasing from the concrete impl to the default impl also processes the
// `[u32; 0]: IntoIterator<Item = ?U>` predicate to constrain the `?U` impl arg.
// This test also makes sure that we don't do anything weird when rebasing the args
// is ambiguous.

#![feature(specialization)]
//[next]~^ WARN the feature `specialization` is incomplete

trait Spec {
    type Assoc;
}

default impl<T, U> Spec for T where T: IntoIterator<Item = U> {
    type Assoc = U;
}

impl<T> Spec for [T; 0] {}

fn main() {
    let x: <[_; 0] as Spec>::Assoc = 1;
}

Version information

rustc 1.84.0-nightly (ef972a346 2024-11-02)
binary: rustc
commit-hash: ef972a346668ed4234d1a43ed4ad7ca4e9c58d51
commit-date: 2024-11-02
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Possibly related line of code: https://github.com/rust-lang/rust/blob/ef972a346668ed4234d1a43ed4ad7ca4e9c58d51/compiler/rustc_trait_selection/src/traits/specialize/mod.rs#L121-L133

Command: /home/matthias/.rustup/toolchains/master/bin/rustc

Program output

``` warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes --> /tmp/icemaker_global_tempdir.jxbDO1GMyC8v/rustc_testrunner_tmpdir_reporting.X0a6Q55Ph3Zn/mvce.rs:1:12 | 1 | #![feature(specialization)] | ^^^^^^^^^^^^^^ | = note: see issue #31844 for more information = help: consider using `min_specialization` instead, which is more stable and complete = note: `#[warn(incomplete_features)]` on by default error: internal compiler error: compiler/rustc_trait_selection/src/traits/specialize/mod.rs:127:21: When translating generic parameters from DefId(0:9 ~ mvce[4f49]::{impl#1}) to DefId(0:5 ~ mvce[4f49]::{impl#0}), the expected specialization failed to hold thread 'rustc' panicked at compiler/rustc_trait_selection/src/traits/specialize/mod.rs:127:21: Box stack backtrace: 0: 0x7737134584aa - ::fmt::hce429173f4835cf6 1: 0x773713c040ca - core::fmt::write::hd474fbdfe63c8008 2: 0x77371507b011 - std::io::Write::write_fmt::ha6b1be51a74d6c82 3: 0x773713458302 - std::sys::backtrace::BacktraceLock::print::h9a37e75f7192ac21 4: 0x77371345a806 - std::panicking::default_hook::{{closure}}::hd9ac8cf20a0b7897 5: 0x77371345a650 - std::panicking::default_hook::hdde16dcfa738c4aa 6: 0x7737124ddb49 - std[85c38ff02e03f0e6]::panicking::update_hook::>::{closure#0} 7: 0x77371345af18 - std::panicking::rust_panic_with_hook::h6eef9cc88a2d4e79 8: 0x773712517231 - std[85c38ff02e03f0e6]::panicking::begin_panic::::{closure#0} 9: 0x77371250a206 - std[85c38ff02e03f0e6]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 10: 0x773712505829 - std[85c38ff02e03f0e6]::panicking::begin_panic:: 11: 0x773712520e01 - ::emit_producing_guarantee 12: 0x773712b9a363 - rustc_middle[b16c40c3cb132ea9]::util::bug::opt_span_bug_fmt::::{closure#0} 13: 0x773712b8095a - rustc_middle[b16c40c3cb132ea9]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 14: 0x773712b807eb - rustc_middle[b16c40c3cb132ea9]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 15: 0x773710ccf260 - rustc_middle[b16c40c3cb132ea9]::util::bug::bug_fmt 16: 0x773713c65283 - rustc_trait_selection[7d6948a7a05ac95]::traits::specialize::translate_args_with_cause:: 17: 0x77371469a013 - rustc_trait_selection[7d6948a7a05ac95]::traits::project::opt_normalize_projection_term 18: 0x7737146931df - >::fold_ty 19: 0x773713f06b53 - ::normalize:: 20: 0x7737145c13fb - ::lower_ty 21: 0x7737147b4fa9 - ::declare 22: 0x773713f2336d - ::visit_expr 23: 0x773713f24f19 - rustc_hir_typeck[643602d1ca0da9fa]::check::check_fn 24: 0x773713f1b2f5 - rustc_hir_typeck[643602d1ca0da9fa]::typeck 25: 0x773713f1ac93 - rustc_query_impl[c0318c643aee4f05]::plumbing::__rust_begin_short_backtrace::> 26: 0x773714321d81 - rustc_query_system[708ef94f36d60214]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[c0318c643aee4f05]::plumbing::QueryCtxt, false> 27: 0x77371432024d - rustc_query_impl[c0318c643aee4f05]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace 28: 0x77371431fec7 - ::par_body_owners::::{closure#0} 29: 0x77371431de99 - rustc_hir_analysis[614b5c894f29c678]::check_crate 30: 0x7737140e384a - rustc_interface[46946d42a40348f7]::passes::run_required_analyses 31: 0x7737147d451e - rustc_interface[46946d42a40348f7]::passes::analysis 32: 0x7737147d44ef - rustc_query_impl[c0318c643aee4f05]::plumbing::__rust_begin_short_backtrace::> 33: 0x773714ba1bae - rustc_query_system[708ef94f36d60214]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[c0318c643aee4f05]::plumbing::QueryCtxt, false> 34: 0x773714ba188e - rustc_query_impl[c0318c643aee4f05]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 35: 0x773714a65292 - rustc_interface[46946d42a40348f7]::interface::run_compiler::, rustc_driver_impl[8ea1370c87ac4c52]::run_compiler::{closure#0}>::{closure#1} 36: 0x773714af0590 - std[85c38ff02e03f0e6]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[8ea1370c87ac4c52]::run_compiler::{closure#0}>::{closure#1}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>>::{closure#0}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>> 37: 0x773714af09ab - <::spawn_unchecked_, rustc_driver_impl[8ea1370c87ac4c52]::run_compiler::{closure#0}>::{closure#1}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>>::{closure#0}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d9ceb9bc2a384707]::result::Result<(), rustc_span[94bdfa138cad1541]::ErrorGuaranteed>>::{closure#1} as core[d9ceb9bc2a384707]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 38: 0x773714af1479 - std::sys::pal::unix::thread::Thread::new::thread_start::h00969398ad9e9953 39: 0x77371631139d - 40: 0x77371639649c - 41: 0x0 - note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md note: please make sure that you have updated to the latest nightly note: rustc 1.84.0-nightly (ef972a346 2024-11-02) running on x86_64-unknown-linux-gnu query stack during panic: #0 [typeck] type-checking `main` #1 [analysis] running analysis passes on this crate end of query stack error: aborting due to 1 previous error; 1 warning emitted ```

@rustbot label +F-specialization

matthiaskrgr commented 1 month ago

Regression in nightly-2021-04-26 commit[0] 2021-04-24: Auto merge of #84511 - davidhewitt:revert-84445, r=GuillaumeGomez commit[1] 2021-04-24: Auto merge of #84310 - RalfJung:const-fn-feature-flags, r=oli-obk commit[2] 2021-04-25: Auto merge of #80339 - jyn514:no-span, r=GuillaumeGomez commit[3] 2021-04-25: Auto merge of #84115 - CDirkx:rt, r=m-ou-se commit[4] 2021-04-25: Auto merge of #84147 - cuviper:array-method-dispatch, r=nikomatsakis,m-ou-se commit[5] 2021-04-25: Auto merge of #84216 - RalfJung:black-box, r=Mark-Simulacrum commit[6] 2021-04-25: Auto merge of #84299 - lcnr:const-generics-defaults-name-res, r=varkor commit[7] 2021-04-25: Auto merge of #84481 - RalfJung:miri, r=RalfJung commit[8] 2021-04-25: Auto merge of #84325 - jsha:ephemeral-collapse, r=GuillaumeGomez