rust-lang / rust

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

ICE: broken MIR: NoSolution on HRTB over GAT in trait object #130524

Open arvidfm opened 6 days ago

arvidfm commented 6 days ago

Code

MWE below, also tested on nightly (via the playground). Interestingly the error goes away if I manually inline the Node::new calls. Minimised from a filter graph that uses trait objects for type erasure.

pub trait Transform {
    type Output<'a>;
}

pub trait Propagate<Input> {}

type Child<T> = Box<dyn for<'a> Propagate<<T as Transform>::Output<'a>>>;

pub struct Node<T>
where
    T: Transform,
{
    transform: T,
    children: Vec<Child<T>>,
}

impl<T> Node<T>
where
    T: Transform,
{
    pub fn new(transform: T, children: Vec<Child<T>>) -> Self {
        Node {
            transform,
            children,
        }
    }
}

impl<Input, T> Propagate<Input> for Node<T> where T: Transform {}

pub fn main() {
    struct Noop;

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

    let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))]));
}

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

Error output

error: internal compiler error: broken MIR in DefId(0:31 ~ playground[6f8d]::test::run#1) ([move _11]): std::boxed::Box<dyn [Binder { value: Trait(Propagate<()>), bound_vars: [Region(BrNamed(DefId(0:10 ~ playground[6f8d]::Child::'a), 'a))] }] + '?14, std::alloc::Global> is not a subtype of std::boxed::Box<dyn [Binder { value: Trait(Propagate<<test::Noop as Transform>::Output<'a>>), bound_vars: [Region(BrNamed(DefId(0:10 ~ playground[6f8d]::Child::'a), 'a))] }] + '?7, std::alloc::Global>: NoSolution
  --> src/lib.rs:43:45
   |
43 |         let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))]));
   |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:2570:17 - disabled backtrace
  --> src/lib.rs:43:45
   |
43 |         let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))]));
   |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error: internal compiler error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

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: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

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

query stack during panic:
end of query stack
Backtrace

``` Compiling my_test v0.1.0 (/tmp/my_test) warning: unused variable: `node` --> src/main.rs:38:9 | 38 | let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))])); | ^^^^ help: if this is intentional, prefix it with an underscore: `_node` | = note: `#[warn(unused_variables)]` on by default warning: fields `transform` and `children` are never read --> src/main.rs:13:5 | 9 | pub struct Node | ---- fields in this struct ... 13 | transform: T, | ^^^^^^^^^ 14 | children: Vec>, | ^^^^^^^^ | = note: `#[warn(dead_code)]` on by default 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: broken MIR in DefId(0:21 ~ my_test[db07]::main) ([move _11]): std::boxed::Box), bound_vars: [Region(BrNamed(DefId(0:10 ~ my_test[db07]::Child::'a), 'a))] }] + '?14, std::alloc::Global> is not a subtype of std::boxed::Box::Output<'a>>), bound_vars: [Region(BrNamed(DefId(0:10 ~ my_test[db07]::Child::'a), 'a))] }] + '?7, std::alloc::Global>: NoSolution --> src/main.rs:38:41 | 38 | let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))])); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:2570:17 0: ::emit_diagnostic 1: ::emit_diagnostic 2: ::emit_producing_guarantee 3: ::span_delayed_bug:: 4: ::typeck_mir 5: rustc_borrowck::type_check::type_check 6: rustc_borrowck::nll::compute_regions 7: rustc_borrowck::do_mir_borrowck 8: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 9: rustc_query_system::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true> 10: rustc_query_impl::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace 11: rustc_interface::passes::analysis 12: rustc_query_impl::plumbing::__rust_begin_short_backtrace::> 13: rustc_query_system::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true> 14: rustc_query_impl::query_impl::analysis::get_query_incr::__rust_end_short_backtrace 15: rustc_interface::interface::run_compiler::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1} 16: 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>> 17: <::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} 18: as core::ops::function::FnOnce>::call_once at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9 19: as core::ops::function::FnOnce>::call_once at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9 20: std::sys::pal::unix::thread::Thread::new::thread_start at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/pal/unix/thread.rs:108:17 21: 22: --> src/main.rs:38:41 | 38 | let node = Box::new(Node::new(Noop, vec![Box::new(Node::new(Noop, vec![]))])); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error: internal compiler error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) 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 bin -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 warning: `my_test` (bin "my_test") generated 2 warnings error: could not compile `my_test` (bin "my_test"); 2 warnings emitted ```

cyrgani commented 6 days ago

More reduction:

trait Transform {
    type Output<'a>;
}

trait Propagate<Input> {}

fn new_node<T: Transform>(_c: Vec<Box<dyn for<'a> Propagate<<T as Transform>::Output<'a>>>>) -> T {
    todo!()
}

impl<Input, T> Propagate<Input> for T {}
struct Noop;

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

fn main() {
    let _node: Noop = new_node(vec![Box::new(Noop)]);
}
matthiaskrgr commented 4 days ago

Regression in nightly-2021-07-17 commit[0] 2021-07-15: Auto merge of #83319 - tmiasko:packed-aligned, r=jackh726 commit[1] 2021-07-16: Auto merge of #86993 - jackh726:project-gat-binders, r=nikomatsakis commit[2] 2021-07-16: Auto merge of #87177 - ehuss:update-cargo, r=ehuss commit[3] 2021-07-16: Auto merge of #86662 - mockersf:fix-86620-link-unknown-location, r=jyn514 commit[4] 2021-07-16: Auto merge of #87182 - GuillaumeGomez:rollup-whwohua, r=GuillaumeGomez commit[5] 2021-07-16: Auto merge of #87140 - camsteffen:pat-slice-refs, r=oli-obk commit[6] 2021-07-16: Auto merge of #84623 - jackh726:gats-incomplete, r=nikomatsakis commit[7] 2021-07-16: Auto merge of #87201 - GuillaumeGomez:rollup-4loi2q9, r=GuillaumeGomez ERROR: no CI builds available between b1f8e27b74c541d3d555149c8efa4bfe9385cd56 and 74ef0c3e404cc72c08b2d1e14506f90d9e877269 within last 167 days

I would guess either #86993 or #84623 ?

arvidfm commented 4 days ago

I did come across #120811 and #110534 which may or may not be related? They both involve HRTBs, though no trait objects, and the regression date mentioned for the former one is later than when this regressed