rust-lang / rust-lang/rust

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

Open
#130,524 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-dyn-trait A-GATs A-higher-ranked A-lifetimes A-trait-system C-bug fixed-by-next-solver I-ICE S-bug-has-test T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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<T>
   |            ---- fields in this struct
...
13 |     transform: T,
   |     ^^^^^^^^^
14 |     children: Vec<Child<T>>,
   |     ^^^^^^^^
   |
   = 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<dyn [Binder { value: Trait(Propagate<()>), 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<dyn [Binder { value: Trait(Propagate<<main::Noop as Transform>::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: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         4: <rustc_borrowck::type_check::TypeChecker>::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::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
         9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, 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::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, 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::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        16: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, 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: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, 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: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2070:9
        19: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::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: <unknown>
        22: <unknown>
  --> 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the minimal example from the issue in src/lib.rs or src/main.rs, then start at rustc_borrowck/src/type_check/mod.rs:2570 and follow the MIR borrow-checking path shown in the query stack. The issue is resolved when this HRTB-over-GAT trait-object example no longer produces a broken-MIR NoSolution internal compiler error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.