Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dalcde opened this issue Nov 30, 2021 · 6 comments
Assignees
Labels
A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) A-synthetic-impls Area: Synthetic impls, used by rustdoc to document auto traits and traits with blanket impls C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@dalcde
Copy link
Contributor

dalcde commented Nov 30, 2021

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: <rustc_trait_selection::traits::auto_trait::AutoTraitFinder>::evaluate_nested_obligations::<alloc::vec::into_iter::IntoIter<rustc_infer::traits::Obligation<rustc_middle::ty::Predicate>>>
   3: <rustc_trait_selection::traits::auto_trait::AutoTraitFinder>::evaluate_predicates
   4: <rustdoc::clean::auto_trait::AutoTraitFinder>::generate_for_trait
   5: <alloc::vec::Vec<rustdoc::clean::types::Item> as alloc::vec::spec_from_iter::SpecFromIter<rustdoc::clean::types::Item, core::iter::adapters::filter_map::FilterMap<alloc::vec::into_iter::IntoIter<rustc_span::def_id::DefId>, <rustdoc::clean::auto_trait::AutoTraitFinder>::get_auto_trait_impls::{closure#0}>>>::from_iter
   6: <rustdoc::clean::auto_trait::AutoTraitFinder>::get_auto_trait_impls
   7: rustdoc::clean::utils::get_auto_trait_and_blanket_impls
   8: <rustdoc::passes::collect_trait_impls::SyntheticImplCollector as rustdoc::visit::DocVisitor>::visit_item
   9: <rustdoc::passes::collect_trait_impls::SyntheticImplCollector as rustdoc::visit::DocVisitor>::visit_item
  10: <rustdoc::passes::collect_trait_impls::SyntheticImplCollector as rustdoc::visit::DocVisitor>::visit_crate
  11: <rustc_session::session::Session>::time::<alloc::vec::Vec<rustdoc::clean::types::Item>, rustdoc::passes::collect_trait_impls::collect_trait_impls::{closure#0}>
  12: rustdoc::passes::collect_trait_impls::collect_trait_impls
  13: <rustc_session::session::Session>::time::<rustdoc::clean::types::Crate, rustdoc::core::run_global_ctxt::{closure#11}>
  14: rustdoc::core::run_global_ctxt
  15: <rustc_session::session::Session>::time::<(rustdoc::clean::types::Crate, rustdoc::config::RenderOptions, rustdoc::formats::cache::Cache), rustdoc::main_options::{closure#0}::{closure#0}::{closure#0}::{closure#0}>
  16: <rustc_interface::interface::Compiler>::enter::<rustdoc::main_options::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
  17: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustdoc::main_options::{closure#0}>::{closure#1}>
  18: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustdoc::main_options::{closure#0}>
  19: rustdoc::main_options
  20: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustdoc::main_args::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{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)

@dalcde dalcde added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 30, 2021
@jyn514 jyn514 added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Nov 30, 2021
@jyn514
Copy link
Member

jyn514 commented Nov 30, 2021

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

@jyn514
Copy link
Member

jyn514 commented Nov 30, 2021

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>,
}

@inquisitivecrystal inquisitivecrystal added the A-trait-system Area: Trait system label Nov 30, 2021
@lcnr
Copy link
Contributor

lcnr commented Nov 30, 2021

uh.. that seems weird

Ok(Ok(None)) => {
// It's ok not to make progress when have no inference variables -
// in that case, we were only performing unifcation to check if an
// error occurred (which would indicate that it's impossible for our
// type to implement the auto trait).
// However, we should always make progress (either by generating
// subobligations or getting an error) when we started off with
// inference variables
if p.ty().skip_binder().has_infer_types() {
panic!("Unexpected result when selecting {:?} {:?}", ty, obligation)
}

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 🤔 maybe a caching issue where rustdoc is using a SelectionContext the wrong way or something?

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 27, 2021
@istankovic
Copy link
Contributor

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

@fmease fmease changed the title rustdoc ICE when resolving traits rustdoc: ICE: synthetic auto trait impls: unexpected result when selecting […] Jun 25, 2024
@fmease fmease changed the title rustdoc: ICE: synthetic auto trait impls: unexpected result when selecting […] rustdoc: ICE: synthetic auto trait impls: unexpected result when selecting […] obligation Jun 25, 2024
@fmease fmease added A-synthetic-impls Area: Synthetic impls, used by rustdoc to document auto traits and traits with blanket impls A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) and removed A-trait-system Area: Trait system labels Jun 25, 2024
@fmease fmease self-assigned this Jun 25, 2024
@neysofu
Copy link

neysofu commented Nov 6, 2024

I got one with 1.79-nightly: https://gist.github.com/neysofu/c99fe7c8bf36a30e82ea2f21a8aef27e.

@emhane
Copy link

emhane commented Apr 8, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) A-synthetic-impls Area: Synthetic impls, used by rustdoc to document auto traits and traits with blanket impls C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants