Skip to content
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

Rustdoc ICE "Unable to fulfill trait" #80233

Closed
orangeturtle739 opened this issue Dec 20, 2020 · 6 comments · Fixed by #80254
Closed

Rustdoc ICE "Unable to fulfill trait" #80233

orangeturtle739 opened this issue Dec 20, 2020 · 6 comments · Fixed by #80254
Assignees
Labels
A-associated-items Area: Associated items such as associated types and consts. A-traits Area: Trait system 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@orangeturtle739
Copy link

This bug occurs with cargo doc. cargo build works fine.

Code

pub trait Trait1 {}

pub trait Trait2 {
    type Type2;
}

pub trait Trait3 {
    type Type3;
}

impl<T: Trait1> Trait2 for Struct1<T> {
    type Type2 = Struct1<T>;
}

impl<I: Trait2> Trait2 for Vec<I> {
    type Type2 = Vec<I::Type2>;
}

impl<T: Trait1> Trait3 for T {
    type Type3 = Struct1<T>;
}

impl<T: Trait3> Trait3 for Vec<T> {
    type Type3 = Vec<T::Type3>;
}

pub struct Struct1<T: Trait1> {
    pub ty: T,
}

pub struct Question<T: Trait1> {
    pub ins: <<Vec<T> as Trait3>::Type3 as Trait2>::Type2,
}

Meta

rustc --version --verbose:

rustc 1.50.0-nightly (eb4fc71dc 2020-12-17)
binary: rustc
commit-hash: eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e
commit-date: 2020-12-17
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly

Error output

cargo doc
 Documenting bad v0.1.0 (/home/jacob/scratch/bad)
thread 'rustc' panicked at 'Unable to fulfill trait DefId(2:2069 ~ core[27a9]::marker::Send) for 'Question<T>': [FulfillmentError(Obligation(predicate=TraitPredicate(<<<T as Trait3>::Type3 as Trait2>::Type2 as std::marker::Send>), depth=4),Unimplemented)]', /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/compiler/rustc_trait_selection/src/traits/auto_trait.rs:193:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

error: Unrecognized option: 'crate-version'

error: could not document `bad`

Caused by:
  process didn't exit successfully: `rustdoc --edition=2018 --crate-type lib --crate-name bad src/lib.rs -o /home/jacob/scratch/bad/target/doc --error-format=json --json=diagnostic-rendered-ansi -L dependency=/home/jacob/scratch/bad/target/debug/deps --crate-version 0.1.0` (exit code: 1)
Backtrace

cargo doc
 Documenting bad v0.1.0 (/home/jacob/scratch/bad)
thread 'rustc' panicked at 'Unable to fulfill trait DefId(2:2069 ~ core[27a9]::marker::Send) for 'Question<T>': [FulfillmentError(Obligation(predicate=TraitPredicate(<<<T as Trait3>::Type3 as Trait2>::Type2 as std::marker::Send>), depth=4),Unimplemented)]', /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/compiler/rustc_trait_selection/src/traits/auto_trait.rs:193:17
stack backtrace:
   0:     0x7f9d8fa8e6c7 - std::backtrace_rs::backtrace::libunwind::trace::h746c3e9529d524bc
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7f9d8fa8e6c7 - std::backtrace_rs::backtrace::trace_unsynchronized::h84373278bfb39e0c
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f9d8fa8e6c7 - std::sys_common::backtrace::_print_fmt::h517324efde750597
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f9d8fa8e6c7 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf594ab77fac89284
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f9d8faff28c - core::fmt::write::h3868db8542c90941
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/core/src/fmt/mod.rs:1078:17
   5:     0x7f9d8fa80592 - std::io::Write::write_fmt::h3f6656f045fa877f
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/io/mod.rs:1519:15
   6:     0x7f9d8fa923b5 - std::sys_common::backtrace::_print::hda7655c057c24dcc
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f9d8fa923b5 - std::sys_common::backtrace::print::h546a6c8431d46287
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f9d8fa923b5 - std::panicking::default_hook::{{closure}}::h006dd083853faf51
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/panicking.rs:208:50
   9:     0x7f9d8fa91f0a - std::panicking::default_hook::hf0f9afb1017317fc
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/panicking.rs:225:9
  10:     0x7f9d903731d8 - rustc_driver::report_ice::hbf1f5af0a1bb3349
  11:     0x7f9d8fa92cb6 - std::panicking::rust_panic_with_hook::hb7a19826c029b1d6
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/panicking.rs:595:17
  12:     0x7f9d8fa927d7 - std::panicking::begin_panic_handler::{{closure}}::hde71edcd925d0c5e
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/panicking.rs:497:13
  13:     0x7f9d8fa8eb8c - std::sys_common::backtrace::__rust_end_short_backtrace::h8a3c7d6cea578919
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7f9d8fa92739 - rust_begin_unwind
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/panicking.rs:493:5
  15:     0x7f9d8fa926eb - std::panicking::begin_panic_fmt::hee67ce14b77d0396
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/panicking.rs:435:5
  16:     0x563ce8c44390 - rustc_trait_selection::traits::auto_trait::AutoTraitFinder::find_auto_trait_generics::{{closure}}::{{closure}}::h24f963735a19b24c
  17:     0x563ce8c3fc28 - rustc_infer::infer::InferCtxtBuilder::enter::h6f305094b7c79e84
  18:     0x563ce8b46668 - rustc_trait_selection::traits::auto_trait::AutoTraitFinder::find_auto_trait_generics::h5f7cfd40341c41b7
  19:     0x563ce8c44f1f - core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut::he8097515da180b22
  20:     0x563ce8a7abf9 - <alloc::vec::Vec<T> as alloc::vec::SpecFromIter<T,I>>::from_iter::he4369931f61cc75e
  21:     0x563ce8aae6c8 - rustdoc::clean::utils::get_auto_trait_and_blanket_impls::h03c689b42451b542
  22:     0x563ce8b18767 - <rustdoc::passes::collect_trait_impls::SyntheticImplCollector as rustdoc::fold::DocFolder>::fold_item::h0304671b3378ba87
  23:     0x563ce8a6ae76 - <alloc::vec::Vec<T> as alloc::vec::SpecFromIter<T,I>>::from_iter::h85a2d0b1ea065485
  24:     0x563ce8b0f1ee - rustdoc::fold::DocFolder::fold_inner_recur::hf82eebf876a8928b
  25:     0x563ce8b18613 - <rustdoc::passes::collect_trait_impls::SyntheticImplCollector as rustdoc::fold::DocFolder>::fold_item::h0304671b3378ba87
  26:     0x563ce8b15bd8 - rustdoc::passes::collect_trait_impls::collect_trait_impls::h32e1829254f0f163
  27:     0x563ce8b0d1a9 - rustdoc::core::run_global_ctxt::h5bce5fb8718d21e3
  28:     0x563ce8b44429 - rustc_interface::passes::QueryContext::enter::h4081845523393810
  29:     0x563ce8b1c2ca - rustc_session::utils::<impl rustc_session::session::Session>::time::h824784fce2dc028a
  30:     0x563ce8915e31 - rustc_interface::interface::create_compiler_and_run::ha094046b19091e9c
  31:     0x563ce8b0af6e - rustdoc::core::run_core::h3988042543ac116a
  32:     0x563ce895fb38 - rustdoc::main_options::hf40919f9c3ac1b02
  33:     0x563ce899c79a - scoped_tls::ScopedKey<T>::set::h4d4ecaa7c363425f
  34:     0x563ce8b468a5 - std::sys_common::backtrace::__rust_begin_short_backtrace::h705cbdf6039205b3
  35:     0x563ce891c01a - core::ops::function::FnOnce::call_once{{vtable.shim}}::h9e684899a6c1a39e
  36:     0x7f9d8faa27ba - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hea1090dbdcecbf5a
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/alloc/src/boxed.rs:1328:9
  37:     0x7f9d8faa27ba - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8d5723d3912bd325
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/alloc/src/boxed.rs:1328:9
  38:     0x7f9d8faa27ba - std::sys::unix::thread::Thread::new::thread_start::hc17a425ca2995724
                               at /rustc/eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e/library/std/src/sys/unix/thread.rs:71:17
  39:     0x7f9d8f9bbe9e - start_thread
  40:     0x7f9d8f7a566f - __GI___clone
  41:                0x0 - <unknown>

error: internal compiler error: unexpected panic

error: Unrecognized option: 'crate-version'

error: could not document `bad`

Caused by:
  process didn't exit successfully: `rustdoc --edition=2018 --crate-type lib --crate-name bad src/lib.rs -o /home/jacob/scratch/bad/target/doc --error-format=json --json=diagnostic-rendered-ansi -L dependency=/home/jacob/scratch/bad/target/debug/deps --crate-version 0.1.0` (exit code: 1)

@orangeturtle739 orangeturtle739 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 Dec 20, 2020
@matthiaskrgr
Copy link
Member

might be a duplicate of #79466

@SNCPlay42
Copy link
Contributor

I think there are important differences: this code doesn't use feature gates, and it successfully builds, so rustdoc should be expected to succeed instead of erroring or ICE, and the rationale for prioritizing that low (that the input is invalid) doesn't apply.

@jyn514 jyn514 added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 20, 2020
@jyn514
Copy link
Member

jyn514 commented Dec 20, 2020

MCVE (although it panics in a slightly different place):

pub trait Trait2 {
    type Type2;
}

pub trait Trait3 {
    type Type3;
}

pub struct Question {
    pub ins: <<usize as Trait3>::Type3 as Trait2>::Type2,
}
thread 'rustc' panicked at 'Unexpected result when selecting Question Obligation(predicate=ProjectionPredicate(ProjectionTy { substs: [_], item_def_id: DefId(0:4 ~ fulfill[8787]::Trait2::Type2) }, _), depth=2)', compiler/rustc_trait_selection/src/traits/auto_trait.rs:778:33

@jyn514
Copy link
Member

jyn514 commented Dec 20, 2020

Oh interesting my MCVE is not correct - that panics because the impls are missing:

error[E0277]: the trait bound `usize: Trait3` is not satisfied
  --> fulfill.rs:10:14
   |
10 |     pub ins: <<usize as Trait3>::Type3 as Trait2>::Type2,
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait3` is not implemented for `usize`

If I add those impls, suddenly rustdoc works:

impl Trait3 for usize {
    type Type3 = isize;
}

impl Trait2 for isize {
    type Type2 = i32;
}

@jyn514
Copy link
Member

jyn514 commented Dec 20, 2020

In fact there are some programs rustdoc accepts that rustc doesn't:

#![crate_type = "lib"]
pub trait Trait1 {}

pub trait Trait2 {
    type Type2;
}

pub trait Trait3 {
    type Type3;
}

/*
impl<T: Trait1> Trait2 for Struct1<T> {
    type Type2 = Struct1<T>;
}
*/

impl<I: Trait2> Trait2 for Vec<I> {
    type Type2 = Vec<I::Type2>;
}

impl<T: Trait1> Trait3 for T {
    type Type3 = Struct1<T>;
}

impl<T: Trait3> Trait3 for Vec<T> {
    type Type3 = Vec<T::Type3>;
}

pub struct Struct1<T: Trait1> {
    pub ty: T,
}

pub struct Question<T: Trait1> {
    pub ins: <<Vec<T> as Trait3>::Type3 as Trait2>::Type2,
}
$ rustc fulfill.rs
error[E0277]: the trait bound `Struct1<T>: Trait2` is not satisfied
  --> fulfill.rs:35:14
   |
35 |     pub ins: <<Vec<T> as Trait3>::Type3 as Trait2>::Type2,
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait2` is not implemented for `Struct1<T>`
   |
   = note: required because of the requirements on the impl of `Trait2` for `Vec<Struct1<T>>`
$ rustdoc fulfill.rs
$

@Aaron1011 Aaron1011 self-assigned this Dec 20, 2020
@jyn514
Copy link
Member

jyn514 commented Dec 20, 2020

Slightly smaller repro:

#![crate_type = "lib"]
pub trait Trait1 {}

pub trait Trait2 {
    type Type2;
}

pub trait Trait3 {
    type Type3;
}

impl Trait2 for Struct1 {
    type Type2 = Struct1;
}

impl<I: Trait2> Trait2 for Vec<I> {
    type Type2 = Vec<I::Type2>;
}

impl<T: Trait1> Trait3 for T {
    type Type3 = Struct1;
}

impl<T: Trait3> Trait3 for Vec<T> {
    type Type3 = Vec<T::Type3>;
}

pub struct Struct1 {}

pub struct Question<T: Trait1> {
    pub ins: <<Vec<T> as Trait3>::Type3 as Trait2>::Type2,
}

@jyn514 jyn514 added A-associated-items Area: Associated items such as associated types and consts. A-traits Area: Trait system labels Dec 20, 2020
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 15, 2021
…=estebank

Don't try to add nested predicate to Rustdoc auto-trait `ParamEnv`

Fixes rust-lang#80233

We already have logic in `evaluate_predicates` that tries to add
unimplemented predicates to our `ParamEnv`. Trying to add a predicate
that already holds can lead to errors later on, since projection
will prefer trait candidates from the `ParamEnv` to predicates from an
impl.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 15, 2021
…=estebank

Don't try to add nested predicate to Rustdoc auto-trait `ParamEnv`

Fixes rust-lang#80233

We already have logic in `evaluate_predicates` that tries to add
unimplemented predicates to our `ParamEnv`. Trying to add a predicate
that already holds can lead to errors later on, since projection
will prefer trait candidates from the `ParamEnv` to predicates from an
impl.
@bors bors closed this as completed in f2d7c05 Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items such as associated types and consts. A-traits Area: Trait system 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants