rust-lang / rust

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

rustdoc: ICE: synthetic auto trait impls: `unable to fulfill trait […]` due to ambiguity involving higher-ranked lifetimes & projection predicates #110741

Open matthiaskrgr opened 1 year ago

matthiaskrgr commented 1 year ago

Code

mod foo {
    pub trait MyTrait<'a> {
        type MyItem: ?Sized;
    }

    pub struct Inner<'a, Q, R: ?Sized> {
        field: Q,
        field3: &'a u8,
        my_foo: Foo<Q>,
        field2: R,
    }

    pub struct Outer<'a, T, K: for<'b> Fn((&'b bool, &'a u8)) -> &'b i8> {
        my_inner: Inner<'a, T, K>,
    }

    pub struct Foo<T> {
        myfield: T,
    }
}

pub use foo::{Foo, Inner as NotInner, MyTrait as NotMyTrait, Outer as NotOuter};

unsafe impl<T> Send for Foo<T> where T: NotMyTrait<'static> {}

unsafe impl<'a, Q, R: ?Sized> Send for NotInner<'a, Q, R>
where
    Q: NotMyTrait<'a>,
    <Q as NotMyTrait<'a>>::MyItem: Copy,
    R: for<'b> Fn((&'b bool, &'a u8)) -> &'b i8,
    Foo<Q>: Send,
{
}

Meta

rustc --version --verbose:

rustdoc 1.71.0-nightly (b628260df 2023-04-22)
binary: rustdoc
commit-hash: b628260df0587ae559253d8640ecb8738d3de613
commit-date: 2023-04-22
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

Error output

<output>
Backtrace

``` thread 'rustc' panicked at 'Unable to fulfill trait DefId(2:2667 ~ core[6cf6]::marker::Send) for 'foo::Outer<'a, T, K>': [FulfillmentError(Obligation(predicate=Binder(ProjectionPredicate(AliasTy { substs: [K, ((&'b bool, &u8),)], def_id: DefId(2:2941 ~ core[6cf6]::ops::function::FnOnce::Output) }, Term::Ty(&'b i8)), [Region(BrNamed(DefId(0:35 ~ 6FE45A2C6E5FED2D2D1DB7DB67AB01ACD3334D81EA9E40465D43C623BE26A177[00f4]::{impl#1}::'b), 'b))]), depth=1),Ambiguity)]', /rustc/b628260df0587ae559253d8640ecb8738d3de613/compiler/rustc_trait_selection/src/traits/auto_trait.rs:186:13 stack backtrace: 0: 0x7f1267168d93 - std::backtrace_rs::backtrace::libunwind::trace::hb9265895128f1f9c at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7f1267168d93 - std::backtrace_rs::backtrace::trace_unsynchronized::h028901cb3a0224b1 at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f1267168d93 - std::sys_common::backtrace::_print_fmt::hfa5c37f64d314fee at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7f1267168d93 - ::fmt::h5b30f1684e8bd3e6 at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f12671c977f - core::fmt::write::h997ecd0e22e2af7a at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/core/src/fmt/mod.rs:1247:17 5: 0x7f126715bde1 - std::io::Write::write_fmt::h291317e85b978e13 at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/io/mod.rs:1698:15 6: 0x7f1267168ba5 - std::sys_common::backtrace::_print::h0133b24def7b99d9 at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:47:5 7: 0x7f1267168ba5 - std::sys_common::backtrace::print::h4a42174c7f3bd207 at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:34:9 8: 0x7f126716b69f - std::panicking::default_hook::{{closure}}::h0847452fe926d6e5 9: 0x7f126716b357 - std::panicking::default_hook::hbcdd7833994c05d0 at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:293:9 10: 0x7f126a42a815 - >::call_once::{shim:vtable#0} 11: 0x7f126716be55 - as core::ops::function::Fn>::call::hd538136c3a298239 at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/alloc/src/boxed.rs:1976:9 12: 0x7f126716be55 - std::panicking::rust_panic_with_hook::hb55c52c8e21298f0 at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:704:13 13: 0x7f126716bbc3 - std::panicking::begin_panic_handler::{{closure}}::h51ad0ee3ee1b4d02 at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:595:13 14: 0x7f12671691d6 - std::sys_common::backtrace::__rust_end_short_backtrace::hd1006853c72eedaf at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys_common/backtrace.rs:150:18 15: 0x7f126716b8c2 - rust_begin_unwind at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/panicking.rs:584:5 16: 0x7f12671c5a13 - core::panicking::panic_fmt::h0405aceea833a54b at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/core/src/panicking.rs:67:14 17: 0x562dff19f504 - ::find_auto_trait_generics::::generate_for_trait::{closure#0}> 18: 0x562dfef32a2d - ::generate_for_trait 19: 0x562dff0cae81 - as alloc[dc090090a0f7fcb0]::vec::spec_from_iter::SpecFromIter, ::get_auto_trait_impls::{closure#0}>>>::from_iter 20: 0x562dfef333a7 - ::get_auto_trait_impls 21: 0x562dff030521 - rustdoc[528331f52b1a723d]::clean::utils::get_auto_trait_and_blanket_impls 22: 0x562dff2276ef - ::visit_item 23: 0x562dff2277fa - ::visit_item 24: 0x562dff2277fa - ::visit_item 25: 0x562dff22c0f6 - ::visit_crate 26: 0x562dff0edc31 - ::time::, rustdoc[528331f52b1a723d]::passes::collect_trait_impls::collect_trait_impls::{closure#0}> 27: 0x562dff2246a9 - rustdoc[528331f52b1a723d]::passes::collect_trait_impls::collect_trait_impls 28: 0x562dff0ede42 - ::time:: 29: 0x562dff19770f - rustdoc[528331f52b1a723d]::core::run_global_ctxt 30: 0x562dff0ee0be - ::time::<(rustdoc[528331f52b1a723d]::clean::types::Crate, rustdoc[528331f52b1a723d]::config::RenderOptions, rustdoc[528331f52b1a723d]::formats::cache::Cache), rustdoc[528331f52b1a723d]::main_args::{closure#1}::{closure#0}::{closure#0}::{closure#0}> 31: 0x562dfef5f9a0 - ::enter::> 32: 0x562dfeff89aa - ::enter::> 33: 0x562dff198d2b - rustc_span[2bbd0fdc9680f436]::set_source_map::, rustc_interface[f51b23ce14955e2d]::interface::run_compiler, rustdoc[528331f52b1a723d]::main_args::{closure#1}>::{closure#0}::{closure#0}> 34: 0x562dfeffa66d - >::set::, rustdoc[528331f52b1a723d]::main_args::{closure#1}>::{closure#0}, core[6cf684c3b560543b]::result::Result<(), rustc_span[2bbd0fdc9680f436]::ErrorGuaranteed>> 35: 0x562dfef148e9 - std[7eada91b7b6d60d5]::sys_common::backtrace::__rust_begin_short_backtrace::, rustdoc[528331f52b1a723d]::main_args::{closure#1}>::{closure#0}, core[6cf684c3b560543b]::result::Result<(), rustc_span[2bbd0fdc9680f436]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6cf684c3b560543b]::result::Result<(), rustc_span[2bbd0fdc9680f436]::ErrorGuaranteed>> 36: 0x562dff24ab5d - <::spawn_unchecked_, rustdoc[528331f52b1a723d]::main_args::{closure#1}>::{closure#0}, core[6cf684c3b560543b]::result::Result<(), rustc_span[2bbd0fdc9680f436]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6cf684c3b560543b]::result::Result<(), rustc_span[2bbd0fdc9680f436]::ErrorGuaranteed>>::{closure#1} as core[6cf684c3b560543b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 37: 0x7f1267176255 - as core::ops::function::FnOnce>::call_once::he5dc381da166b1f4 at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/alloc/src/boxed.rs:1962:9 38: 0x7f1267176255 - as core::ops::function::FnOnce>::call_once::h2873f5088eb028a4 at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/alloc/src/boxed.rs:1962:9 39: 0x7f1267176255 - std::sys::unix::thread::Thread::new::thread_start::h737c68bdf349b13b at /rustc/b628260df0587ae559253d8640ecb8738d3de613/library/std/src/sys/unix/thread.rs:108:17 40: 0x7f1266e28bb5 - 41: 0x7f1266eaad90 - 42: 0x0 - error: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md note: rustc 1.71.0-nightly (b628260df 2023-04-22) running on x86_64-unknown-linux-gnu note: compiler flags: --crate-type lib query stack during panic: end of query stack ```

matthiaskrgr commented 1 year ago

crashing since at least mid 2020 :sweat_smile:

fmease commented 1 year ago

Further minimized:

pub struct Outer<'a, R>(Inner<'a, R>)
where
    R: for<'b> Fn(&'b bool, &'a u8);

pub struct Inner<'a, R>(&'a (), R);

unsafe impl<'a, R> Send for Inner<'a, R>
where
    R: for<'b> Fn(&'b bool, &'a u8)
{}

@rustbot label A-auto-traits A-synthetic-impls @rustbot claim