Skip to content

Compiler error involving HRTBs #115807

Closed
@dlubarov

Description

@dlubarov

Code

trait Chip: for<'a> TraitWithLifetime<'a> + SomeMarker {
    fn compute(&self);
}

trait SomeMarker {}

trait TraitWithLifetime<'a>: SomeMarker {}

trait Machine {
    fn run();
}

struct BasicMachine;

impl Machine for BasicMachine {
    fn run() {
        let chips: [&dyn Chip; 0] = [];
        let _ = chips.map(|chip| chip.compute());
    }
}

Meta

rustc --version --verbose:

rustc 1.72.0 (5680fa18f 2023-08-23)
binary: rustc
commit-hash: 5680fa18feaa87f3ff04063800aec256c3d4b4be
commit-date: 2023-08-23
host: aarch64-apple-darwin
release: 1.72.0
LLVM version: 16.0.5

The bug seems to be present in the latest nightly at well as stable.

Error output

error: internal compiler error: compiler/rustc_trait_selection/src/traits/vtable.rs:344:9: Failed to find info for expected trait in vtable
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/compiler/rustc_errors/src/lib.rs:1651:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::HandlerInner>::bug::<alloc::string::String>
   2: <rustc_errors::Handler>::bug::<alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_trait_selection::traits::vtable::vtable_trait_first_method_offset
   8: <rustc_trait_selection::traits::select::SelectionContext>::confirm_candidate
   9: <rustc_trait_selection::traits::select::SelectionContext>::poly_select
  10: <rustc_trait_selection::traits::fulfill::FulfillProcessor>::process_trait_obligation
  11: <rustc_trait_selection::traits::fulfill::FulfillProcessor as rustc_data_structures::obligation_forest::ObligationProcessor>::process_obligation
  12: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>
  13: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_where_possible
  14: rustc_traits::codegen::codegen_select_candidate
  15: rustc_ty_utils::instance::resolve_instance
  16: <rustc_middle::ty::instance::Instance>::resolve
  17: <rustc_middle::ty::instance::Instance>::expect_resolve
  18: <rustc_monomorphize::collector::MirUsedCollector as rustc_middle::mir::visit::Visitor>::visit_terminator
  19: rustc_monomorphize::collector::collect_used_items
  20: rustc_monomorphize::collector::collect_items_rec
  21: rustc_monomorphize::collector::collect_items_rec
  22: rustc_monomorphize::collector::collect_items_rec
  23: rustc_monomorphize::collector::collect_items_rec
  24: rustc_monomorphize::collector::collect_items_rec
  25: rustc_monomorphize::collector::collect_items_rec
  26: rustc_monomorphize::collector::collect_items_rec
  27: rustc_monomorphize::collector::collect_items_rec
  28: rustc_monomorphize::collector::collect_items_rec
  29: rustc_monomorphize::collector::collect_items_rec
  30: rustc_monomorphize::collector::collect_items_rec
  31: <core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::par_for_each_in<alloc::vec::Vec<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
  32: rustc_data_structures::sync::par_for_each_in::<alloc::vec::Vec<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
  33: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
  34: rustc_monomorphize::collector::collect_crate_mono_items
  35: rustc_monomorphize::partitioning::collect_and_partition_mono_items
  36: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  37: rustc_metadata::rmeta::encoder::encode_metadata_impl
  38: rustc_data_structures::sync::join::<rustc_metadata::rmeta::encoder::encode_metadata::{closure#0}, rustc_metadata::rmeta::encoder::encode_metadata::{closure#1}, (), ()>
  39: rustc_metadata::rmeta::encoder::encode_metadata
  40: rustc_metadata::fs::encode_and_write_metadata
  41: rustc_interface::passes::start_codegen
  42: <rustc_middle::ty::context::GlobalCtxt>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_span::ErrorGuaranteed>>
  43: <rustc_interface::queries::Queries>::ongoing_codegen
  44: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
  45: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.72.0 (5680fa18f 2023-08-23) running on aarch64-apple-darwin

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

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

query stack during panic:
#0 [codegen_select_candidate] computing candidate for `<dyn Chip as Chip>`
#1 [resolve_instance] resolving instance `<dyn Chip as Chip>::compute`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
#3 [exported_symbols] collecting exported symbols for crate `0`
end of query stack

Metadata

Metadata

Labels

C-bugCategory: This is a bug.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