rust-lang / rust

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

rustdoc: ICE: synthetic auto trait impls: `unexpected result when selecting […] obligation` #91380

Open dalcde opened 2 years ago

dalcde commented 2 years ago

Code

rustdoc crashes on the following code:

pub trait Module {
    type Algebra;
}

pub trait ChainComplex {
    type Algebra;
    type Module: Module;
}

pub struct FreeModule<A> {
    foo: A,
}

impl<A> Module for FreeModule<A> {
    type Algebra = A;
}

pub trait FreeChainComplex:
    ChainComplex<Module = FreeModule<<Self as ChainComplex>::Algebra>>
{
}

pub struct ResolutionHomomorphism<CC1, CC2>
where
    CC1: FreeChainComplex<Algebra = CC2::Algebra>,
    CC2: FreeChainComplex,
{
    source: CC1,
    maps: CC2::Module,
}

pub struct SecondaryResolutionHomomorphism<
    CC1: FreeChainComplex,
    CC2: FreeChainComplex<Algebra = CC1::Algebra>,
> {
    underlying: ResolutionHomomorphism<CC1, CC2>,
}

Meta

This crashes on both 1.54.0, 1.56.0 and nightly (2021-11-29)

Error output

thread 'rustc' panicked at 'Unexpected result when selecting SecondaryResolutionHomomorphism<CC1, CC2> Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { substs: [CC2], item_def_id: DefId(0:7 ~ ice[d87a]::ChainComplex::Module) }, _), []), depth=2)', compiler/rustc_trait_selection/src/traits/auto_trait.rs:773:33
Backtrace

``` stack backtrace: 0: rust_begin_unwind at /rustc/6db0a0e9a4a2f55b1a85954e114ada0b45c32e45/library/std/src/panicking.rs:498:5 1: core::panicking::panic_fmt at /rustc/6db0a0e9a4a2f55b1a85954e114ada0b45c32e45/library/core/src/panicking.rs:107:14 2: ::evaluate_nested_obligations::>> 3: ::evaluate_predicates 4: ::generate_for_trait 5: as alloc::vec::spec_from_iter::SpecFromIter, ::get_auto_trait_impls::{closure#0}>>>::from_iter 6: ::get_auto_trait_impls 7: rustdoc::clean::utils::get_auto_trait_and_blanket_impls 8: ::visit_item 9: ::visit_item 10: ::visit_crate 11: ::time::, rustdoc::passes::collect_trait_impls::collect_trait_impls::{closure#0}> 12: rustdoc::passes::collect_trait_impls::collect_trait_impls 13: ::time:: 14: rustdoc::core::run_global_ctxt 15: ::time::<(rustdoc::clean::types::Crate, rustdoc::config::RenderOptions, rustdoc::formats::cache::Cache), rustdoc::main_options::{closure#0}::{closure#0}::{closure#0}::{closure#0}> 16: ::enter::> 17: rustc_span::with_source_map::, rustc_interface::interface::create_compiler_and_run, rustdoc::main_options::{closure#0}>::{closure#1}> 18: rustc_interface::interface::create_compiler_and_run::, rustdoc::main_options::{closure#0}> 19: rustdoc::main_options 20: >::set::>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>> note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. error: internal compiler error: unexpected panic error: Unrecognized option: 'crate-version' error: could not document `ice` Caused by: process didn't exit successfully: `rustdoc --edition=2018 --crate-type lib --crate-name ice src/lib.rs -o /tmp/ice/target/doc --error-format=json --json=diagnostic-rendered-ansi -C metadata=75642385eb1e00a4 -L dependency=/tmp/ice/target/debug/deps --crate-version 0.1.0` (exit status: 1) ```

jyn514 commented 2 years ago

@BoxyUwU @lcnr do one of you happen to know what's going on here?

jyn514 commented 2 years ago

Slightly smaller:

pub trait Module {
    type Algebra;
}

pub trait ChainComplex {
    type Algebra;
    type Module: Module;
}

pub struct FreeModule<A> {
    foo: A,
}

impl<A> Module for FreeModule<A> {
    type Algebra = A;
}

pub trait FreeChainComplex:
    ChainComplex<Module = FreeModule<<Self as ChainComplex>::Algebra>>
{
}

pub struct ResolutionHomomorphism<CC2>
where
    CC2: ChainComplex,
{
    maps: CC2::Module,
}

pub struct SecondaryResolutionHomomorphism<
    CC2: FreeChainComplex<Algebra = usize>,
> {
    underlying: ResolutionHomomorphism<CC2>,
}
lcnr commented 2 years ago

uh.. that seems weird

https://github.com/rust-lang/rust/blob/207c80f105282245d93024c95ac408c622f70114/compiler/rustc_trait_selection/src/traits/auto_trait.rs#L764-L774

cc @nikomatsakis @jackh726

so the obligation is Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { substs: [CC2], item_def_id: DefId(0:7 ~ dep[b688]::ChainComplex::Module) }, _), []), depth=2) with param env

ParamEnv {
   caller_bounds: [
      Binder(TraitPredicate(<CC2 as std::marker::Sized>, polarity:Positive), []),
      Binder(TraitPredicate(<CC2 as ChainComplex>, polarity:Positive), []),
      Binder(ProjectionPredicate(ProjectionTy { substs: [CC2], item_def_id: DefId(0:7 ~ dep[b688]::ChainComplex::Module) }, FreeModule<usize>), []),
      Binder(TraitPredicate(<CC2 as FreeChainComplex>, polarity:Positive), []),
      Binder(ProjectionPredicate(
         ProjectionTy { substs: [CC2], item_def_id: DefId(0:7 ~ dep[b688]::ChainComplex::Module) },
         FreeModule<<CC2 as ChainComplex>::Algebra>
      ), []),
      Binder(ProjectionPredicate(
         ProjectionTy { substs: [CC2], item_def_id: DefId(0:6 ~ dep[b688]::ChainComplex::Algebra) }, usize), [])
   ],
   reveal: UserFacing
}

This obligation should be easily provable, so I expect there to either be a bug something bigger going wrong :thinking: maybe a caching issue where rustdoc is using a SelectionContext the wrong way or something?

istankovic commented 9 months ago

Still panics with 1.75-nightly: rustc-ice-2023-10-22T13_45_33-85873.txt