rust-lang / rust

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

ICE: `unexpected ambiguity: Canonical..` #119272

Closed matthiaskrgr closed 1 month ago

matthiaskrgr commented 10 months ago

auto-reduced (treereduce-rust):

#![feature(type_alias_impl_trait)]
mod defining_scope {
    use super::*;
    pub type Alias<T> = impl Sized;

    pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
        x
    }
}

struct Container<T: Trait<U>, U> {
    x: <T as Trait<U>>::Assoc,
}

trait Trait<T> {
    type Assoc;
}

impl<T> Trait<T> for T {
    type Assoc = Box<u32>;
}
impl<T> Trait<T> for defining_scope::Alias<T> {
    type Assoc = usize;
}

fn main() {}

original:

//revisions: old next
//[next] compile-flags: -Znext-solver

// A regression test for #105787

//[old] known-bug: #105787
//[old] check-pass
#![feature(type_alias_impl_trait)]
mod defining_scope {
    use super::*;
    pub type Alias<T> = impl Sized;

    pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
        x
    }
}

struct Container<T: Trait<U>, U> {
    x: <T as Trait<U>>::Assoc,
}

trait Trait<T> {
    type Assoc;
}

impl<T> Trait<T> for T {
    type Assoc = Box<u32>;
}
impl<T> Trait<T> for defining_scope::Alias<T> {
    //[next]~^ ERROR conflicting implementations of trait
    type Assoc = usize;
}

fn main() {
        Default::default()
    }

Version information

rustc 1.77.0-nightly (2d7be7393 2023-12-23)
binary: rustc
commit-hash: 2d7be73931e0978c8758a672cc7258b417a7e999
commit-date: 2023-12-23
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

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

Program output

``` warning: struct `Container` is never constructed --> /tmp/icemaker_global_tempdir.fzzOAlARA6tK/rustc_testrunner_tmpdir_reporting.utiWfmv9NFbE/mvce.rs:11:8 | 11 | struct Container, U> { | ^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: function `cast` is never used --> /tmp/icemaker_global_tempdir.fzzOAlARA6tK/rustc_testrunner_tmpdir_reporting.utiWfmv9NFbE/mvce.rs:6:12 | 6 | pub fn cast(x: Container, T>) -> Container { | ^^^^ error: internal compiler error: no errors encountered even though `span_delayed_bug` issued error: internal compiler error: unexpected ambiguity: Canonical { value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [Binder { value: TraitPredicate(, polarity:Positive), bound_vars: [] }], reveal: All }, value: AliasTy { args: [T/#0, T/#0], def_id: DefId(0:15 ~ mvce[8437]::Trait::Assoc) } }, max_universe: U0, variables: [] } Canonical { value: QueryResponse { var_values: CanonicalVarValues { var_values: [] }, region_constraints: QueryRegionConstraints { outlives: [], member_constraints: [] }, certainty: Ambiguous, opaque_types: [], value: NormalizationResult { normalized_ty: ^0 } }, max_universe: U0, variables: [CanonicalVarInfo { kind: Ty(General(U0)) }] } | = note: delayed at compiler/rustc_trait_selection/src/traits/query/normalize.rs:295:34 0: ::emit_diagnostic_without_consuming 1: ::emit_diagnostic_without_consuming 2: ::emit_diagnostic 3: ::span_delayed_bug:: 4: >::try_fold_ty 5: )>>::call_once 6: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 7: rustc_query_system::query::plumbing::try_execute_query::, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false> 8: rustc_query_impl::query_impl::try_normalize_generic_arg_after_erasing_regions::get_query_non_incr::__rust_end_short_backtrace 9: >::try_fold_ty 10: rustc_ty_utils::needs_drop::needs_drop_raw 11: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 12: rustc_query_system::query::plumbing::try_execute_query::, rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false> 13: rustc_query_impl::query_impl::needs_drop_raw::get_query_non_incr::__rust_end_short_backtrace 14: ::run_pass 15: rustc_mir_transform::run_analysis_to_runtime_passes 16: rustc_mir_transform::mir_drops_elaborated_and_const_checked 17: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 18: rustc_query_system::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false> 19: rustc_query_impl::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace 20: rustc_interface::passes::analysis 21: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 22: rustc_query_system::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false> 23: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 24: rustc_interface::interface::run_compiler::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0} 25: std::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>> 26: <::spawn_unchecked_, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 27: as core::ops::function::FnOnce>::call_once at /rustc/2d7be73931e0978c8758a672cc7258b417a7e999/library/alloc/src/boxed.rs:2015:9 28: as core::ops::function::FnOnce>::call_once at /rustc/2d7be73931e0978c8758a672cc7258b417a7e999/library/alloc/src/boxed.rs:2015:9 29: std::sys::unix::thread::Thread::new::thread_start at /rustc/2d7be73931e0978c8758a672cc7258b417a7e999/library/std/src/sys/unix/thread.rs:108:17 30: 31: 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: rustc 1.77.0-nightly (2d7be7393 2023-12-23) running on x86_64-unknown-linux-gnu query stack during panic: end of query stack error: aborting due to 2 previous errors; 2 warnings emitted ```

matthiaskrgr commented 10 months ago

Apparently this regressed in #113126 ? weird..

matthiaskrgr commented 3 months ago

still crashing :thinking:

oli-obk commented 3 months ago

uhm... how? the corresponding crashes test now passes

matthiaskrgr commented 3 months ago

yeh, its weird.. my first guess would be that there are some rustflags that passed by default to uitests that "prevent" the ice, but skipping them, such as doing rustc file.rs still crashes them?

something like debuginfo, or crate-type=something ?

lcnr commented 3 months ago

uhm... how? the corresponding crashes test now passes

this test only ICEs during codegen, so it passes with cargo build. see the discussion in the compiler team meeting https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-08-01/near/455671961