Skip to content

Compiler error on get_vtable_index_of_object_method #97381

Closed
@elonzyy

Description

I tried this code:

use std::ops::Deref;

trait MyTrait: Deref<Target = u32> {}

struct MyStruct(u32);

impl MyTrait for MyStruct {}

impl Deref for MyStruct {
    type Target = u32;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

fn get_concrete_value(i: u32) -> MyStruct {
    MyStruct(i)
}

fn get_boxed_value(i: u32) -> Box<dyn MyTrait> {
    Box::new(get_concrete_value(i))
}

fn main() {
    let v = [1, 2, 3]
        .iter()
        .map(|i| get_boxed_value(*i))
        .collect::<Vec<_>>();

    let el = &v[0];

    for _ in v {
        // this triggers bug
        println!("{}", ***el > 0);
    }
}

I expected to see this happen: 'el' will be derefed as u32

Instead, this happened: compiler complains

Meta

rustc --version --verbose:

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-unknown-linux-gnu
release: 1.61.0
LLVM version: 14.0.0
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1279:9
stack backtrace:
   0:     0x7f1624d741cd - std::backtrace_rs::backtrace::libunwind::trace::h22893a5306c091b4
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f1624d741cd - std::backtrace_rs::backtrace::trace_unsynchronized::h29c3bc6f9e91819d
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f1624d741cd - std::sys_common::backtrace::_print_fmt::he497d8a0ec903793
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f1624d741cd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9c2a9d2774d81873
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f1624dce01c - core::fmt::write::hba4337c43d992f49
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/fmt/mod.rs:1194:17
   5:     0x7f1624d657c1 - std::io::Write::write_fmt::heb73de6e02cfabed
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/io/mod.rs:1655:15
   6:     0x7f1624d772b5 - std::sys_common::backtrace::_print::h63c8b24acdd8e8ce
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f1624d772b5 - std::sys_common::backtrace::print::h426700d6240cdcc2
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f1624d772b5 - std::panicking::default_hook::{{closure}}::hc9a76eed0b18f82b
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:295:22
   9:     0x7f1624d76f69 - std::panicking::default_hook::h2e88d02087fae196
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:314:9
  10:     0x7f16254f41d1 - rustc_driver[413d55b6344850e3]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f1624d77a00 - std::panicking::rust_panic_with_hook::habfdcc2e90f9fd4c
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:702:17
  12:     0x7f16265c4141 - std[3b302b3c9093c22]::panicking::begin_panic::<rustc_errors[a7dbbf867eaca825]::ExplicitBug>::{closure#0}
  13:     0x7f16265c3e96 - std[3b302b3c9093c22]::sys_common::backtrace::__rust_end_short_backtrace::<std[3b302b3c9093c22]::panicking::begin_panic<rustc_errors[a7dbbf867eaca825]::ExplicitBug>::{closure#0}, !>
  14:     0x7f16265cb406 - std[3b302b3c9093c22]::panicking::begin_panic::<rustc_errors[a7dbbf867eaca825]::ExplicitBug>
  15:     0x7f16265d7ec6 - std[3b302b3c9093c22]::panic::panic_any::<rustc_errors[a7dbbf867eaca825]::ExplicitBug>
  16:     0x7f16265d9673 - <rustc_errors[a7dbbf867eaca825]::HandlerInner>::bug
  17:     0x7f16265d90d0 - <rustc_errors[a7dbbf867eaca825]::Handler>::bug
  18:     0x7f1626518636 - rustc_middle[9ca07169fec39ed9]::ty::context::tls::with_opt::<rustc_middle[9ca07169fec39ed9]::util::bug::opt_span_bug_fmt<rustc_span[7238ca7210ca999e]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7f162651b746 - rustc_middle[9ca07169fec39ed9]::util::bug::opt_span_bug_fmt::<rustc_span[7238ca7210ca999e]::span_encoding::Span>
  20:     0x7f162651b6c3 - rustc_middle[9ca07169fec39ed9]::util::bug::bug_fmt
  21:     0x7f16276f06e9 - rustc_trait_selection[2e17e0f1454142da]::traits::util::get_vtable_index_of_object_method::<()>
  22:     0x7f1626a27cea - rustc_ty_utils[1a711ca447a2a51a]::instance::inner_resolve_instance
  23:     0x7f1626a2602f - rustc_ty_utils[1a711ca447a2a51a]::instance::resolve_instance
  24:     0x7f1626e4fa54 - rustc_query_system[ac245aac4c1950a0]::query::plumbing::get_query::<rustc_query_impl[b0f4194b24b225ee]::queries::resolve_instance, rustc_query_impl[b0f4194b24b225ee]::plumbing::QueryCtxt>
  25:     0x7f1626f04868 - <rustc_query_impl[b0f4194b24b225ee]::Queries as rustc_middle[9ca07169fec39ed9]::ty::query::QueryEngine>::resolve_instance
  26:     0x7f162727aa00 - <rustc_middle[9ca07169fec39ed9]::ty::instance::Instance>::resolve
  27:     0x7f1625cc5cbb - rustc_const_eval[10f0603c48acc95d]::util::call_kind::call_kind
  28:     0x7f1625affe9f - <rustc_borrowck[20c91c3baf1e28a2]::MirBorrowckCtxt>::move_spans
  29:     0x7f1625af780f - <rustc_borrowck[20c91c3baf1e28a2]::MirBorrowckCtxt>::explain_why_borrow_contains_point
  30:     0x7f1625aef995 - <rustc_borrowck[20c91c3baf1e28a2]::MirBorrowckCtxt>::report_move_out_while_borrowed
  31:     0x7f16277ec105 - <rustc_borrowck[20c91c3baf1e28a2]::MirBorrowckCtxt as rustc_mir_dataflow[6b276981176d0a5e]::framework::visitor::ResultsVisitor>::visit_statement_before_primary_effect
  32:     0x7f1626beda48 - rustc_mir_dataflow[6b276981176d0a5e]::framework::visitor::visit_results::<rustc_borrowck[20c91c3baf1e28a2]::dataflow::BorrowckAnalyses<rustc_index[db082642455f6dc9]::bit_set::BitSet<rustc_borrowck[20c91c3baf1e28a2]::dataflow::BorrowIndex>, rustc_index[db082642455f6dc9]::bit_set::ChunkedBitSet<rustc_mir_dataflow[6b276981176d0a5e]::move_paths::MovePathIndex>, rustc_index[db082642455f6dc9]::bit_set::ChunkedBitSet<rustc_mir_dataflow[6b276981176d0a5e]::move_paths::InitIndex>>, rustc_borrowck[20c91c3baf1e28a2]::dataflow::BorrowckAnalyses<rustc_mir_dataflow[6b276981176d0a5e]::framework::engine::Results<rustc_borrowck[20c91c3baf1e28a2]::dataflow::Borrows>, rustc_mir_dataflow[6b276981176d0a5e]::framework::engine::Results<rustc_mir_dataflow[6b276981176d0a5e]::impls::MaybeUninitializedPlaces>, rustc_mir_dataflow[6b276981176d0a5e]::framework::engine::Results<rustc_mir_dataflow[6b276981176d0a5e]::impls::EverInitializedPlaces>>, core[a3420257622cd381]::iter::adapters::map::Map<rustc_middle[9ca07169fec39ed9]::mir::traversal::ReversePostorder, rustc_borrowck[20c91c3baf1e28a2]::do_mir_borrowck::{closure#2}>, rustc_borrowck[20c91c3baf1e28a2]::MirBorrowckCtxt>
  33:     0x7f1626c99fb3 - rustc_borrowck[20c91c3baf1e28a2]::do_mir_borrowck
  34:     0x7f1626c8df19 - rustc_borrowck[20c91c3baf1e28a2]::mir_borrowck
  35:     0x7f1626c8abb0 - <rustc_borrowck[20c91c3baf1e28a2]::provide::{closure#0} as core[a3420257622cd381]::ops::function::FnOnce<(rustc_middle[9ca07169fec39ed9]::ty::context::TyCtxt, rustc_span[7238ca7210ca999e]::def_id::LocalDefId)>>::call_once
  36:     0x7f1626e21461 - rustc_query_system[ac245aac4c1950a0]::query::plumbing::try_execute_query::<rustc_query_impl[b0f4194b24b225ee]::plumbing::QueryCtxt, rustc_query_system[ac245aac4c1950a0]::query::caches::DefaultCache<rustc_span[7238ca7210ca999e]::def_id::LocalDefId, &rustc_middle[9ca07169fec39ed9]::mir::query::BorrowCheckResult>>
  37:     0x7f1626f017ca - <rustc_query_impl[b0f4194b24b225ee]::Queries as rustc_middle[9ca07169fec39ed9]::ty::query::QueryEngine>::mir_borrowck
  38:     0x7f162672184f - <rustc_session[8df92abe178df33c]::session::Session>::time::<(), rustc_interface[550884b2b179878f]::passes::analysis::{closure#2}>
  39:     0x7f16273f6b45 - rustc_interface[550884b2b179878f]::passes::analysis
  40:     0x7f16278bcdee - rustc_query_system[ac245aac4c1950a0]::query::plumbing::try_execute_query::<rustc_query_impl[b0f4194b24b225ee]::plumbing::QueryCtxt, rustc_query_system[ac245aac4c1950a0]::query::caches::DefaultCache<(), core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>>
  41:     0x7f16278ffdfe - rustc_query_system[ac245aac4c1950a0]::query::plumbing::get_query::<rustc_query_impl[b0f4194b24b225ee]::queries::analysis, rustc_query_impl[b0f4194b24b225ee]::plumbing::QueryCtxt>
  42:     0x7f16273bc881 - <rustc_interface[550884b2b179878f]::passes::QueryContext>::enter::<rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>
  43:     0x7f16273d6a58 - <rustc_interface[550884b2b179878f]::interface::Compiler>::enter::<rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}::{closure#2}, core[a3420257622cd381]::result::Result<core[a3420257622cd381]::option::Option<rustc_interface[550884b2b179878f]::queries::Linker>, rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>
  44:     0x7f16273bc03f - rustc_span[7238ca7210ca999e]::with_source_map::<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_interface[550884b2b179878f]::interface::create_compiler_and_run<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#1}>
  45:     0x7f16273d80a4 - rustc_interface[550884b2b179878f]::interface::create_compiler_and_run::<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>
  46:     0x7f16273ba7c2 - <scoped_tls[7ed3ce20ede545d8]::ScopedKey<rustc_span[7238ca7210ca999e]::SessionGlobals>>::set::<rustc_interface[550884b2b179878f]::interface::run_compiler<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>
  47:     0x7f16273d038f - std[3b302b3c9093c22]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[550884b2b179878f]::util::run_in_thread_pool_with_globals<rustc_interface[550884b2b179878f]::interface::run_compiler<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>
  48:     0x7f16273bbaf9 - <<std[3b302b3c9093c22]::thread::Builder>::spawn_unchecked_<rustc_interface[550884b2b179878f]::util::run_in_thread_pool_with_globals<rustc_interface[550884b2b179878f]::interface::run_compiler<core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>, rustc_driver[413d55b6344850e3]::run_compiler::{closure#1}>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>::{closure#0}, core[a3420257622cd381]::result::Result<(), rustc_errors[a7dbbf867eaca825]::ErrorGuaranteed>>::{closure#1} as core[a3420257622cd381]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  49:     0x7f1624d81bf3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha99802c2c52ada61
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/alloc/src/boxed.rs:1861:9
  50:     0x7f1624d81bf3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha39aea1c57e28a15
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/alloc/src/boxed.rs:1861:9
  51:     0x7f1624d81bf3 - std::sys::unix::thread::Thread::new::thread_start::h9f8e3d72b1f7662f
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys/unix/thread.rs:108:17
  52:     0x7f1624b4c8ca - start_thread
  53:     0x7f1624aec500 - __GI___clone3
  54:                0x0 - <unknown>

Rust playground link for the same code:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a6b3700bf032c4433b98e4ea0e29c77a

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    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.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions