rust-lang / rust

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

ICE: "error performing operation: fully_perform" on type inference for trait object with HRTB over GAT #130797

Open arvidfm opened 5 days ago

arvidfm commented 5 days ago

Another ICE when using a HRTB in a trait object similar to #130524, but in a slightly different context and with a different error.

Code

trait Transform {
    type Output<'a>;
}
trait Propagate<O> {}
trait AddChild<C> {}

pub struct Node<T>(T);
impl<T> AddChild<Box<dyn for<'b> Propagate<T::Output<'b>>>> for Node<T> where
    T: Transform
{
}

fn make_graph_root() {
    add_children(Node(Dummy));
}

fn add_children<T, C>(_node: T)
where
    T: AddChild<C>,
{
}

struct Dummy;
impl Transform for Dummy {
    type Output<'a> = ();
}

Meta

rustc --version --verbose:

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

Also reproduced on nightly via the playground

Error output

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: error performing operation: fully_perform
  --> repro/src/lib.rs:14:5
   |
14 |     add_children(Node(Dummy));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: delayed at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs:85:25 - disabled backtrace
  --> repro/src/lib.rs:14:5
   |
14 |     add_children(Node(Dummy));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^

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.81.0 (eeb90cda1 2024-09-04) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
Backtrace

``` note: no errors encountered even though delayed bugs were created note: those delayed bugs will now be shown as internal compiler errors error: internal compiler error: error performing operation: fully_perform --> repro/src/lib.rs:14:5 | 14 | add_children(Node(Dummy)); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: delayed at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs:85:25 0: ::emit_diagnostic 1: ::emit_diagnostic 2: ::emit_producing_guarantee 3: ::span_delayed_bug:: 4: ::fully_perform_op::<(), rustc_middle::ty::ParamEnvAnd> 5: ::normalize_and_prove_instantiated_predicates 6: ::visit_const_operand 7: ::visit_body 8: rustc_borrowck::type_check::type_check 9: rustc_borrowck::nll::compute_regions 10: rustc_borrowck::do_mir_borrowck 11: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 12: rustc_query_system::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true> 13: rustc_query_impl::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace 14: rustc_interface::passes::analysis 15: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 16: rustc_query_system::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true> 17: rustc_query_impl::query_impl::analysis::get_query_incr::__rust_end_short_backtrace 18: rustc_interface::interface::run_compiler::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1} 19: std::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>> 20: <::spawn_unchecked_, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 21: as core::ops::function::FnOnce>::call_once at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9 22: as core::ops::function::FnOnce>::call_once at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9 23: std::sys::pal::unix::thread::Thread::new::thread_start at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/pal/unix/thread.rs:108:17 24: 25: --> repro/src/lib.rs:14:5 | 14 | add_children(Node(Dummy)); | ^^^^^^^^^^^^^^^^^^^^^^^^^ 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.81.0 (eeb90cda1 2024-09-04) running on x86_64-unknown-linux-gnu note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] note: some of the compiler flags provided by cargo are hidden query stack during panic: end of query stack ```

arvidfm commented 5 days ago

It also reproduces if I simply call a method defined for the trait:

trait Transform {
    type Output<'a>;
}
trait Propagate<O> {}
trait AddChild<C> {
    fn add_child(&self) {}
}

pub struct Node<T>(T);
impl<T> AddChild<Box<dyn for<'b> Propagate<T::Output<'b>>>> for Node<T> where T: Transform {}

fn make_graph_root() {
    Node(Dummy).add_child()
}

struct Dummy;
impl Transform for Dummy {
    type Output<'a> = ();
}