rust-lang / rust

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

rustdoc: ICE: synthetic auto trait impls: `unexpected result when selecting […] obligation` involving (nested) projections #116539

Open drahnr opened 1 year ago

drahnr commented 1 year ago

Related

https://github.com/rust-lang/rust/issues/114657

and a possible duplicate of

https://github.com/rust-lang/rust/issues/114097 , https://github.com/rust-lang/rust/issues/107715

with the main difference that they still reproduce with the compiler toolchain versions listed below.

Code

<very large>

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

same as +nightly

rustc 1.75.0-nightly (cae0791da 2023-10-05)
binary: rustc
commit-hash: cae0791da47bb01f16885eb233dcd66b0093a6e1
commit-date: 2023-10-05
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.2

Error output / Backtrace

...
 Documenting xyz v0.1.0 (/media/supersonic1t/projects/foo)
thread 'rustc' panicked at compiler/rustc_trait_selection/src/traits/auto_trait.rs:748:33:
Unexpected result when selecting pallet::GenesisConfig<T> Obligation(predicate=Binder { value: ProjectionPredicate(AliasTy { args: [T], def_id: DefId(286:1375 ~ frame_system[5a5f]::pallet::Config::AccountId) }, Term::Ty(_)), bound_vars: [] }, depth=2)
stack backtrace:
   0:     0x7f347456349c - std::backtrace_rs::backtrace::libunwind::trace::he43a6a3949163f8c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f347456349c - std::backtrace_rs::backtrace::trace_unsynchronized::h50db52ca99f692e7
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f347456349c - std::sys_common::backtrace::_print_fmt::hd37d595f2ceb2d3c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f347456349c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h678bbcf9da6d7d75
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f34745c93fc - core::fmt::rt::Argument::fmt::h3a159adc080a6fc9
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/rt.rs:138:9
   5:     0x7f34745c93fc - core::fmt::write::hb8eaf5a8e45a738e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f347455612e - std::io::Write::write_fmt::h9663fe36b2ee08f9
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/io/mod.rs:1714:15
   7:     0x7f3474563284 - std::sys_common::backtrace::_print::hcd4834796ee88ad2
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f3474563284 - std::sys_common::backtrace::print::h1360e9450e4f922a
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f3474566193 - std::panicking::default_hook::{{closure}}::h2609fa95cd5ab1f4
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:270:22
  10:     0x7f3474565eac - std::panicking::default_hook::h6d75f5747cab6e8d
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:290:9
  11:     0x7f3477730a3e - <alloc[98253621d83cbf53]::boxed::Box<rustc_driver_impl[566d207f92c3d9d2]::install_ice_hook::{closure#0}> as core[d28c4e8d9c4eebaa]::ops::function::Fn<(&dyn for<'a, 'b> core[d28c4e8d9c4eebaa]::ops::function::Fn<(&'a core[d28c4e8d9c4eebaa]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[d28c4e8d9c4eebaa]::marker::Sync + core[d28c4e8d9c4eebaa]::marker::Send, &core[d28c4e8d9c4eebaa]::panic::panic_info::PanicInfo)>>::call
  12:     0x7f34745669be - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h05249de742e1768e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2021:9
  13:     0x7f34745669be - std::panicking::rust_panic_with_hook::h57e78470c47c84de
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:711:13
  14:     0x7f3474566747 - std::panicking::begin_panic_handler::{{closure}}::h3dfd2453cf356ecb
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:599:13
  15:     0x7f34745639c6 - std::sys_common::backtrace::__rust_end_short_backtrace::hdb177d43678e4d7e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7f3474566492 - rust_begin_unwind
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:595:5
  17:     0x7f34745c5803 - core::panicking::panic_fmt::hd1e971d8d7c78e0e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14
  18:     0x7f34783267e1 - <rustc_trait_selection[48b7f7e13fbddf35]::traits::auto_trait::AutoTraitFinder>::evaluate_predicates
  19:     0x559856acd8cb - <rustc_trait_selection[48b7f7e13fbddf35]::traits::auto_trait::AutoTraitFinder>::find_auto_trait_generics::<rustdoc[4b10bf8a9158300e]::clean::types::Generics, <rustdoc[4b10bf8a9158300e]::clean::auto_trait::AutoTraitFinder>::generate_for_trait::{closure#0}>
  20:     0x559856ab49f5 - <rustdoc[4b10bf8a9158300e]::clean::auto_trait::AutoTraitFinder>::generate_for_trait
  21:     0x5598569d2a70 - <alloc[98253621d83cbf53]::vec::Vec<rustdoc[4b10bf8a9158300e]::clean::types::Item> as alloc[98253621d83cbf53]::vec::spec_from_iter::SpecFromIter<rustdoc[4b10bf8a9158300e]::clean::types::Item, core[d28c4e8d9c4eebaa]::iter::adapters::filter_map::FilterMap<alloc[98253621d83cbf53]::vec::into_iter::IntoIter<rustc_span[4c9f011e8b033119]::def_id::DefId>, <rustdoc[4b10bf8a9158300e]::clean::auto_trait::AutoTraitFinder>::get_auto_trait_impls::{closure#0}>>>::from_iter
  22:     0x559856ab524d - <rustdoc[4b10bf8a9158300e]::clean::auto_trait::AutoTraitFinder>::get_auto_trait_impls
  23:     0x559856b64c03 - rustdoc[4b10bf8a9158300e]::clean::utils::get_auto_trait_and_blanket_impls
  24:     0x559856bc8f77 - <rustdoc[4b10bf8a9158300e]::passes::collect_trait_impls::SyntheticImplCollector as rustdoc[4b10bf8a9158300e]::visit::DocVisitor>::visit_item
  25:     0x559856bc907a - <rustdoc[4b10bf8a9158300e]::passes::collect_trait_impls::SyntheticImplCollector as rustdoc[4b10bf8a9158300e]::visit::DocVisitor>::visit_item
  26:     0x559856bc907a - <rustdoc[4b10bf8a9158300e]::passes::collect_trait_impls::SyntheticImplCollector as rustdoc[4b10bf8a9158300e]::visit::DocVisitor>::visit_item
  27:     0x559856bc603e - rustdoc[4b10bf8a9158300e]::passes::collect_trait_impls::collect_trait_impls
  28:     0x559856b7b0d6 - <rustc_session[f1e1083633086c54]::session::Session>::time::<(rustdoc[4b10bf8a9158300e]::clean::types::Crate, rustdoc[4b10bf8a9158300e]::config::RenderOptions, rustdoc[4b10bf8a9158300e]::formats::cache::Cache), rustdoc[4b10bf8a9158300e]::main_args::{closure#1}::{closure#0}::{closure#0}::{closure#0}>
  29:     0x559856aa0392 - <rustc_middle[5935fdd60c99b3fe]::ty::context::GlobalCtxt>::enter::<rustdoc[4b10bf8a9158300e]::main_args::{closure#1}::{closure#0}::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>
  30:     0x559856b7f99c - <scoped_tls[3409080448444679]::ScopedKey<rustc_span[4c9f011e8b033119]::SessionGlobals>>::set::<rustc_interface[5bdd18de9f5858d8]::interface::run_compiler<core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>, rustdoc[4b10bf8a9158300e]::main_args::{closure#1}>::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>
  31:     0x559856a595f9 - std[3759e478f3a6c4f2]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[5bdd18de9f5858d8]::util::run_in_thread_pool_with_globals<rustc_interface[5bdd18de9f5858d8]::interface::run_compiler<core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>, rustdoc[4b10bf8a9158300e]::main_args::{closure#1}>::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>
  32:     0x559856c62d11 - <<std[3759e478f3a6c4f2]::thread::Builder>::spawn_unchecked_<rustc_interface[5bdd18de9f5858d8]::util::run_in_thread_pool_with_globals<rustc_interface[5bdd18de9f5858d8]::interface::run_compiler<core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>, rustdoc[4b10bf8a9158300e]::main_args::{closure#1}>::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>::{closure#1} as core[d28c4e8d9c4eebaa]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7f3474571295 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::haadd4e5af2ab0d62
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  34:     0x7f3474571295 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he4ba1fb09c16d807
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  35:     0x7f3474571295 - std::sys::unix::thread::Thread::new::thread_start::he524ecf4b47bee95
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys/unix/thread.rs:108:17
  36:     0x7f3474200947 - start_thread
  37:     0x7f3474286860 - __clone3
  38:                0x0 - <unknown>

The project in question is rather large and still under wraps, so this is pending a minimal verifiable example and I am still working on cutting it down.

rustc-ice-2023-10-08T18:55:36.409984428Z-305658.txt

drahnr commented 1 year ago

https://github.com/drahnr/rustdoc-failure-116539 contains a somewhat MCVE example @GuillaumeGomez , I'll keep trimming it at some point later this week, but it's already significantly smaller, not quite single page just yet

GuillaumeGomez commented 1 year ago

It's a good start indeed. Problem is mostly proc-macro. Without proc-macro, it'd be good enough already.

drahnr commented 1 year ago
pub trait IdentifyAccount {
    type AccountId;
}
pub trait Verify {
    type Signer;
}
pub struct RealSigner {}
impl IdentifyAccount for RealSigner {
    type AccountId = u32;
}
pub struct RealSignature {}
impl Verify for RealSignature {
    type Signer = RealSigner;
}
pub type RealAccountId = <<RealSignature as Verify>::Signer as IdentifyAccount>::AccountId;

pub struct Pallet<T>(std::marker::PhantomData<T>);

pub struct BaseEvent<T: ?Sized> {
    _x: std::marker::PhantomData<T>,
}

pub mod inner {
    pub trait Config {
        type RuntimeEvent;
        type AccountId;
    }
}
pub trait IsType<T>: From<T> + Into<T> {}

pub trait Config: inner::Config<AccountId = RealAccountId> {
    type RuntimeEvent: From<BaseEvent<Self>> + IsType<<Self as inner::Config>::RuntimeEvent>;
}

pub struct GenesisConfig<T: Config> {
    pub shelves: Vec<<T as inner::Config>::AccountId>,
}

showcases the issue, repo got updated

GuillaumeGomez commented 1 year ago

Thanks! I'm working on another issue at the moment but I'll try to get back to this one as soon as possible.

drahnr commented 1 year ago

If you could point me in a general direction I'd be up for taking a look into it

GuillaumeGomez commented 1 year ago

It's a failing compiler query which is run in clean::auto_trait::AutoTraitFinder. Maybe start checking there?

drahnr commented 1 year ago
pub trait IdentifyAccount {
    type A;
}
pub struct RealSigner {}

impl IdentifyAccount for RealSigner {
    type A = u32;
}

pub type RealAccountId = <RealSigner as IdentifyAccount>::A;

pub trait BaseConfig {
    type B;
}

pub trait Config: BaseConfig<B = RealAccountId> {}

pub struct GenesisConfig<T: Config> {
    pub shelves: Vec<<T as BaseConfig>::B>,
}
kpreid commented 10 months ago

@rustbot label -E-needs-mcve

https://github.com/rust-lang/rust/issues/116539#issuecomment-1756309287 is a MCVE for this