-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Internal compiler error when documenting capnp
#51236
Comments
UPDATE Also happen on rustc 1.26.1
|
Minimal reproduction: use std::marker::PhantomData;
pub mod traits {
pub trait Owned<'a> {
type Reader;
}
}
pub struct Owned<T> where T: for<'a> ::traits::Owned<'a> {
marker: PhantomData<<T as ::traits::Owned<'static>>::Reader>,
} Maybe some kind of mismatch between the HRTB on the struct definition and the EDIT: This is happening when figuring out the auto-trait impls on the |
Happens on current stable* and current nightly**, so this is interesting. I guess I can't build local documentation for my dependencies until this is fixed.
|
cc @nikomatsakis @Aaron1011 So this is what's failing rust/src/librustc/traits/auto_trait.rs Lines 217 to 222 in 4dc2d74
The huge comment before all of this suggests to me that it's a bit fragile and this is an edge case: rust/src/librustc/traits/auto_trait.rs Lines 136 to 167 in 4dc2d74
|
Debug output when run on my sample: $ RUST_LOG=rustc::traits::auto_trait rustdoc +local -o asdf l.rs
DEBUG 2018-06-22T19:03:59Z: rustc::traits::auto_trait: evaluate_nested_obligations(ty_did=DefId(0/0:7 ~ l[8787]::Owned[0]), trait_did=DefId(2/0:865 ~ core[1c6a]::marker[0]::Send[0])): succeeded with 'ParamEnv { caller_bounds: [Binder(TraitPredicate(<T as traits::Owned<'a>>)), Binder(TraitPredicate(<T
as std::marker::Sized>)), Binder(TraitPredicate(<<T as traits::Owned<'static>>::Reader as std::marker::Send>)), Binder(TraitPredicate(<T as traits::Owned<'static>>))], reveal: UserFacing }' 'ParamEnv { caller_bounds: [Binder(TraitPredicate(<T as traits::Owned<'static>>)), Binder(TraitPredicate(<<T as
traits::Owned<'static>>::Reader as std::marker::Send>)), Binder(TraitPredicate(<T as std::marker::Sized>)), Binder(TraitPredicate(<T as traits::Owned<'a>>))], reveal: UserFacing }'
DEBUG 2018-06-22T19:03:59Z: rustc::traits::auto_trait: evaluate_nested_obligations(ty_did=DefId(0/0:7 ~ l[8787]::Owned[0]), trait_did=DefId(2/0:865 ~ core[1c6a]::marker[0]::Send[0])): succeeded with 'ParamEnv { caller_bounds: [Binder(TraitPredicate(<T as traits::Owned<'a>>)), Binder(TraitPredicate(<T
as std::marker::Sized>)), Binder(TraitPredicate(<<T as traits::Owned<'static>>::Reader as std::marker::Send>)), Binder(TraitPredicate(<T as traits::Owned<'static>>))], reveal: UserFacing }' 'ParamEnv { caller_bounds: [Binder(TraitPredicate(<T as traits::Owned<'static>>)), Binder(TraitPredicate(<<T as
traits::Owned<'static>>::Reader as std::marker::Send>)), Binder(TraitPredicate(<T as std::marker::Sized>)), Binder(TraitPredicate(<T as traits::Owned<'a>>))], reveal: UserFacing }'
DEBUG 2018-06-22T19:03:59Z: rustc::traits::auto_trait: find_auto_trait_generics(did=DefId(0/0:7 ~ l[8787]::Owned[0]), trait_did=DefId(2/0:865 ~ core[1c6a]::marker[0]::Send[0]), generics=Generics { parent: None, parent_count: 0, params: [Type(T, DefId(0/1:10 ~ l[8787]::Owned[0]::T[0]), 0)], param_def_id_to_index: {DefId(0/1:10 ~ l[8787]::Owned[0]::T[0]): 0}, has_self: false, has_late_bound_regions: None }): fulfilling with ParamEnv { caller_bounds: [Binder(TraitPredicate(<T as traits::Owned<'a>>)), Binder(TraitPredicate(<T as std::marker::Sized>)), Binder(TraitPredicate(<<T as traits::Owned<'static>>::Reader as std::marker::Send>)), Binder(TraitPredicate(<T as traits::Owned<'static>>))], reveal: UserFacing }
thread '<unnamed>' panicked at 'Unable to fulfill trait DefId(2/0:865 ~ core[1c6a]::marker[0]::Send[0]) for 'Owned<T>': [FulfillmentError(Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { substs: [T, ReStatic], item_def_id: DefId(0/0:6 ~ l[8787]::traits[0]::Owned[0]::Reader[0]) }, _)),depth=2),Ambiguity), FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<_ as std::marker::Send>)),depth=2),Ambiguity)]', librustc/traits/auto_trait.rs:218:17
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.28.0-dev running on x86_64-unknown-linux-gnu |
Here's a slightly more simplified reproduction: use std::marker::PhantomData;
pub trait OwnedTrait<'a> {
type Reader;
}
pub struct Owned<T> where T: for<'a> OwnedTrait<'a> {
marker: PhantomData<<T as OwnedTrait<'static>>::Reader>,
} |
I'd like to work on this. |
I wonder if #50159 is related? It's not the same failure, but it's another failure when synthesizing impls for rustdoc, and it also deals with associated types as type parameters in struct fields. |
Initial thoughts: The issue seems to be related to the fact that the auto trait finder picks up the following two bounds;
The first bounds is part of the initial param env ( Once both of these predicates have been added to the I'm not entirely certain what the best way to resolve this is. One solution might be to inspect the generated |
Some further thoughts: I think I can make the de-duplication approach work. Given two trait predicates that differ only in their lifetime substations, we should always choose the 'more strict' one. This means always choosing a predicate involving a HRTB over one involving 'static. Requiring that we be able to choose any lifetime in the type means that it's fine to pick 'static. If I'm correct in my understanding of trait selection and fulfillment, this shouldn't lead to any 'unsound' (not actually sufficient) bounds being displayed to user. This de-duplication will take place before we run |
Just wondering: is there any way to work around this issue and produce documentation for a crate depending on |
The workaround is to “rustup install 1.25.0” and then “rustup run 1.25.0 cargo doc —open”
|
@coder543 Ah, great, thanks! 😄 |
Hi, is anyone fixing this issue? My project requires nightly so I cannot use 1.25.0 . I think I can try to fix this issue, I will need some guides, though (first time editing rustc's code). |
A better workaround, if you're not exporting the |
@QuietMisdreavus Thanks! That works! |
@QuietMisdreavus that's not really a solution, since I need to be able to see the docs for my dependencies. Relying on It would be super duper appreciated if this could at least get fixed on nightly, somehow. This issue is a very serious workflow impediment. |
Tagging as @rust-lang/compiler @Aaron1011 Can we get some renewed attention on this? |
I'm taking a look at this now. |
Fix ICE when rustdoc encounters certain usages of HRTBs Fixes #51236 Under certain circumstances, `AutoTraitFinder` could end up computing a `ParamEnv` involving two trait predicates that differed only in the region parameters involved. One of these parameters would be a HRTB, while the other would be a normal region parameter. When this `ParamEnv` was later passed to `SelectionContext`, an `Ambiguity` error would occur, since the erased versions of these predicates would be identical. To solve the issue, we de-duplicate our list of predicates as we build it up. Whenever we encounter two predicates that differ only in their assignment of region parameters (a HRTB vs a normal lifetime parameter), we pick the HRTB. This corresponds to selecting a 'stricter' bound to display in the generated documentation: we're requiring that a particular type works for all possible lifetime parameters if it's going to implement a particular auto trait.
@Aaron1011 Thanks! it looks like there wasn't a new nightly last night, so I can't test it yet, but I look forward to it! |
Cargo.toml:
Result when run
cargo doc
:rustc version: nightly-x86_64-unknown-linux-gnu (5d0631a 2018-05-30)
Also happen in nightly-2018-05-29 and nightly-2018-05-23.
The text was updated successfully, but these errors were encountered: