Skip to content

ICE: tried to select method from HRTB with non-lifetime bound vars #121597

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(non_lifetime_binders)]

trait Foo: for<T> Bar<T> {}

trait Bar<T: ?Sized> {
    fn method(&self) {}
}

fn needs_bar(_: *mut Type2) {}

fn main() {
    let x: &dyn Foo = &();

    needs_bar(x);
}

original:

#![feature(non_lifetime_binders)]
//~^ WARN the feature `non_lifetime_binders` is incomplete

trait Foo: for<T> Bar<T> {}

trait Bar<T: ?Sized> {
    fn method(&self) {}
}

fn needs_bar(_: *mut Type2) {
    x.method();
}

impl Foo for () {}

impl<T: ?Sized> Bar<T> for () {}

fn main() {
    let x: &dyn Foo = &();
    //~^ ERROR the trait `Foo` cannot be made into an object
    //~| ERROR the trait `Foo` cannot be made into an object
    needs_bar(x);
    //~^ ERROR the trait `Foo` cannot be made into an object
}

Version information

rustc 1.78.0-nightly (26cd5d862 2024-02-25)
binary: rustc
commit-hash: 26cd5d862e22c013ecb3396b177d3af80e95c836
commit-date: 2024-02-25
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0412]: cannot find type `Type2` in this scope
 --> /tmp/icemaker_global_tempdir.6WS8gItM5jly/rustc_testrunner_tmpdir_reporting.dbAqHJzMl0ez/mvce.rs:9:22
  |
9 | fn needs_bar(_: *mut Type2) {}
  |                      ^^^^^ not found in this scope

warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.6WS8gItM5jly/rustc_testrunner_tmpdir_reporting.dbAqHJzMl0ez/mvce.rs:1:12
  |
1 | #![feature(non_lifetime_binders)]
  |            ^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
  = note: `#[warn(incomplete_features)]` on by default

error[E0038]: the trait `Foo` cannot be made into an object
  --> /tmp/icemaker_global_tempdir.6WS8gItM5jly/rustc_testrunner_tmpdir_reporting.dbAqHJzMl0ez/mvce.rs:12:23
   |
12 |     let x: &dyn Foo = &();
   |                       ^^^ `Foo` cannot be made into an object
   |
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
  --> /tmp/icemaker_global_tempdir.6WS8gItM5jly/rustc_testrunner_tmpdir_reporting.dbAqHJzMl0ez/mvce.rs:3:12
   |
3  | trait Foo: for<T> Bar<T> {}
   |       ---  ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables
   |       |
   |       this trait cannot be made into an object...
   = note: required for the cast from `&()` to `&dyn Foo`

error[E0038]: the trait `Foo` cannot be made into an object
  --> /tmp/icemaker_global_tempdir.6WS8gItM5jly/rustc_testrunner_tmpdir_reporting.dbAqHJzMl0ez/mvce.rs:12:12
   |
12 |     let x: &dyn Foo = &();
   |            ^^^^^^^^ `Foo` cannot be made into an object
   |
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
  --> /tmp/icemaker_global_tempdir.6WS8gItM5jly/rustc_testrunner_tmpdir_reporting.dbAqHJzMl0ez/mvce.rs:3:12
   |
3  | trait Foo: for<T> Bar<T> {}
   |       ---  ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables
   |       |
   |       this trait cannot be made into an object...

error: internal compiler error: tried to select method from HRTB with non-lifetime bound vars
  --> /tmp/icemaker_global_tempdir.6WS8gItM5jly/rustc_testrunner_tmpdir_reporting.dbAqHJzMl0ez/mvce.rs:14:15
   |
14 |     needs_bar(x);
   |               ^

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/method/probe.rs:807:28:
Box<dyn Any>
stack backtrace:
   0:     0x7efcc778ca06 - std::backtrace_rs::backtrace::libunwind::trace::h2b754d54d1bde505
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7efcc778ca06 - std::backtrace_rs::backtrace::trace_unsynchronized::h543e1ca101948fd5
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7efcc778ca06 - std::sys_common::backtrace::_print_fmt::h530a113cbf476cc2
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7efcc778ca06 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdaaebae0c7e457dd
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7efcc77dd98c - core::fmt::rt::Argument::fmt::h986a5c541218a991
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/core/src/fmt/rt.rs:142:9
   5:     0x7efcc77dd98c - core::fmt::write::h0480b093981ac277
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/core/src/fmt/mod.rs:1120:17
   6:     0x7efcc77813cf - std::io::Write::write_fmt::he3dd140cfd4aef89
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/std/src/io/mod.rs:1846:15
   7:     0x7efcc778c7b4 - std::sys_common::backtrace::_print::hdac374456098a97e
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7efcc778c7b4 - std::sys_common::backtrace::print::ha7f20ab884506926
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7efcc778f4fb - std::panicking::default_hook::{{closure}}::h300a405277525f5d
  10:     0x7efcc778f249 - std::panicking::default_hook::hde1c193b2da6a81c
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/std/src/panicking.rs:292:9
  11:     0x7efcca68892c - std[555420183d371a7f]::panicking::update_hook::<alloc[b9bf11d30073d6dd]::boxed::Box<rustc_driver_impl[633500a3532990b7]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7efcc778fc60 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h68a9e4d741c266fd
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/alloc/src/boxed.rs:2030:9
  13:     0x7efcc778fc60 - std::panicking::rust_panic_with_hook::h8ba518db0741b55a
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/std/src/panicking.rs:783:13
  14:     0x7efcca6b4fd4 - std[555420183d371a7f]::panicking::begin_panic::<rustc_errors[69c26c4f67726645]::ExplicitBug>::{closure#0}
  15:     0x7efcca6b1ef6 - std[555420183d371a7f]::sys_common::backtrace::__rust_end_short_backtrace::<std[555420183d371a7f]::panicking::begin_panic<rustc_errors[69c26c4f67726645]::ExplicitBug>::{closure#0}, !>
  16:     0x7efcca6b1bd6 - std[555420183d371a7f]::panicking::begin_panic::<rustc_errors[69c26c4f67726645]::ExplicitBug>
  17:     0x7efcca6beb21 - <rustc_errors[69c26c4f67726645]::diagnostic::BugAbort as rustc_errors[69c26c4f67726645]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7efccc2de675 - <rustc_hir_typeck[2ba3259e05449eae]::method::probe::ProbeContext>::assemble_inherent_candidates
  19:     0x7efcca8510e4 - <rustc_hir_typeck[2ba3259e05449eae]::fn_ctxt::FnCtxt>::get_conversion_methods
  20:     0x7efcca869331 - <rustc_hir_typeck[2ba3259e05449eae]::fn_ctxt::FnCtxt>::suggest_deref_ref_or_into
  21:     0x7efcca849c44 - <rustc_hir_typeck[2ba3259e05449eae]::fn_ctxt::FnCtxt>::emit_type_mismatch_suggestions
  22:     0x7efcca84d99d - <rustc_hir_typeck[2ba3259e05449eae]::fn_ctxt::FnCtxt>::emit_coerce_suggestions
  23:     0x7efcca86235f - <rustc_hir_typeck[2ba3259e05449eae]::fn_ctxt::FnCtxt>::report_arg_errors
  24:     0x7efccc540b78 - <rustc_hir_typeck[2ba3259e05449eae]::fn_ctxt::FnCtxt>::check_argument_types
  25:     0x7efccc2c6947 - <rustc_hir_typeck[2ba3259e05449eae]::fn_ctxt::FnCtxt>::check_call
  26:     0x7efccc4944e3 - <rustc_hir_typeck[2ba3259e05449eae]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  27:     0x7efccbfa669b - <rustc_hir_typeck[2ba3259e05449eae]::fn_ctxt::FnCtxt>::check_block_with_expected
  28:     0x7efccc4949c6 - <rustc_hir_typeck[2ba3259e05449eae]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  29:     0x7efccc2f8a08 - rustc_hir_typeck[2ba3259e05449eae]::check::check_fn
  30:     0x7efccbb406ad - rustc_hir_typeck[2ba3259e05449eae]::typeck
  31:     0x7efccbb3f98b - rustc_query_impl[2c9e1b0525c9d953]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2c9e1b0525c9d953]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[73325823477bd615]::query::erase::Erased<[u8; 8usize]>>
  32:     0x7efccbd0e570 - rustc_query_system[dfd6c8aac03f3724]::query::plumbing::try_execute_query::<rustc_query_impl[2c9e1b0525c9d953]::DynamicConfig<rustc_query_system[dfd6c8aac03f3724]::query::caches::VecCache<rustc_span[dc6b5ece0d38defd]::def_id::LocalDefId, rustc_middle[73325823477bd615]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[2c9e1b0525c9d953]::plumbing::QueryCtxt, false>
  33:     0x7efccbd0e08c - rustc_query_impl[2c9e1b0525c9d953]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7efccc3cd4d2 - <rustc_middle[73325823477bd615]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[7c1425229e6d6e04]::check_crate::{closure#6}>::{closure#0}
  35:     0x7efccc3cbd9d - rustc_hir_analysis[7c1425229e6d6e04]::check_crate
  36:     0x7efccc6059af - rustc_interface[27abfdff6e6b27c2]::passes::analysis
  37:     0x7efccc605619 - rustc_query_impl[2c9e1b0525c9d953]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2c9e1b0525c9d953]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[73325823477bd615]::query::erase::Erased<[u8; 1usize]>>
  38:     0x7efccc71f8e5 - rustc_query_system[dfd6c8aac03f3724]::query::plumbing::try_execute_query::<rustc_query_impl[2c9e1b0525c9d953]::DynamicConfig<rustc_query_system[dfd6c8aac03f3724]::query::caches::SingleCache<rustc_middle[73325823477bd615]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2c9e1b0525c9d953]::plumbing::QueryCtxt, false>
  39:     0x7efccc71f649 - rustc_query_impl[2c9e1b0525c9d953]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7efccc72eb16 - rustc_interface[27abfdff6e6b27c2]::interface::run_compiler::<core[421030ac42e8f54b]::result::Result<(), rustc_span[dc6b5ece0d38defd]::ErrorGuaranteed>, rustc_driver_impl[633500a3532990b7]::run_compiler::{closure#0}>::{closure#0}
  41:     0x7efccc9c8cc5 - std[555420183d371a7f]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[27abfdff6e6b27c2]::util::run_in_thread_with_globals<rustc_interface[27abfdff6e6b27c2]::util::run_in_thread_pool_with_globals<rustc_interface[27abfdff6e6b27c2]::interface::run_compiler<core[421030ac42e8f54b]::result::Result<(), rustc_span[dc6b5ece0d38defd]::ErrorGuaranteed>, rustc_driver_impl[633500a3532990b7]::run_compiler::{closure#0}>::{closure#0}, core[421030ac42e8f54b]::result::Result<(), rustc_span[dc6b5ece0d38defd]::ErrorGuaranteed>>::{closure#0}, core[421030ac42e8f54b]::result::Result<(), rustc_span[dc6b5ece0d38defd]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[421030ac42e8f54b]::result::Result<(), rustc_span[dc6b5ece0d38defd]::ErrorGuaranteed>>
  42:     0x7efccc9c8af2 - <<std[555420183d371a7f]::thread::Builder>::spawn_unchecked_<rustc_interface[27abfdff6e6b27c2]::util::run_in_thread_with_globals<rustc_interface[27abfdff6e6b27c2]::util::run_in_thread_pool_with_globals<rustc_interface[27abfdff6e6b27c2]::interface::run_compiler<core[421030ac42e8f54b]::result::Result<(), rustc_span[dc6b5ece0d38defd]::ErrorGuaranteed>, rustc_driver_impl[633500a3532990b7]::run_compiler::{closure#0}>::{closure#0}, core[421030ac42e8f54b]::result::Result<(), rustc_span[dc6b5ece0d38defd]::ErrorGuaranteed>>::{closure#0}, core[421030ac42e8f54b]::result::Result<(), rustc_span[dc6b5ece0d38defd]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[421030ac42e8f54b]::result::Result<(), rustc_span[dc6b5ece0d38defd]::ErrorGuaranteed>>::{closure#1} as core[421030ac42e8f54b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x7efcc7799635 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h176656733d324092
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/alloc/src/boxed.rs:2016:9
  44:     0x7efcc7799635 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2cb067df8c4b40c7
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/alloc/src/boxed.rs:2016:9
  45:     0x7efcc7799635 - std::sys::pal::unix::thread::Thread::new::thread_start::h9c4fa792b58c770f
                               at /rustc/26cd5d862e22c013ecb3396b177d3af80e95c836/library/std/src/sys/pal/unix/thread.rs:108:17
  46:     0x7efcc758155a - <unknown>
  47:     0x7efcc75fea3c - <unknown>
  48:                0x0 - <unknown>

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.78.0-nightly (26cd5d862 2024-02-25) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors; 1 warning emitted

Some errors have detailed explanations: E0038, E0412.
For more information about an error, try `rustc --explain E0038`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-non_lifetime_binders`#![feature(non_lifetime_binders)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions