Skip to content

ICE when casting &mut Trait to *mut Trait, same for casting &Trait to *const Trait #19109

Closed
@tbu-

Description

@tbu-
trait Trait { }

fn function(t: &mut Trait) {
    t as *mut Trait
}

fn main() { }

This ICEs with the following message:

$ RUST_BACKTRACE=1 rustc a.rs 
a.rs:4:5: 4:6 error: internal compiler error: expected object type
a.rs:4     t as *mut Trait
           ^
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' panicked at 'Box<Any>', /home/hein/git/rust/src/libsyntax/diagnostic.rs:116

stack backtrace:
   1:     0x7fba24ef8d50 - rt::backtrace::imp::write::h62769dcaa7983ed8FNs
   2:     0x7fba24efbdd0 - <unknown>
   3:     0x7fba256a43e0 - unwind::begin_unwind_inner::h3fca55fd1ce1f347o9c
   4:     0x7fba23e4f460 - <unknown>
   5:     0x7fba23e4f3e0 - diagnostic::SpanHandler::span_bug::hea3a64b392293aeaDRF
   6:     0x7fba25c49ad0 - driver::session::Session::span_bug::hb3878c8c794bf1dcHNC
   7:     0x7fba25f4a260 - middle::typeck::check::vtable::check_object_cast::h7d7ee59c0ae09980HKN
   8:     0x7fba25fb8090 - <unknown>
   9:     0x7fba25fe62b0 - <unknown>
  10:     0x7fba25fab4c0 - <unknown>
  11:     0x7fba25fa7eb0 - <unknown>
  12:     0x7fba25fa7bf0 - <unknown>
  13:     0x7fba25fa3cc0 - middle::typeck::check::check_item::h22ee00fbae37d0570pW
  14:     0x7fba25fa79b0 - middle::typeck::check::check_item_types::h7de0aa0b52df316614V
  15:     0x7fba25a9c960 - <unknown>
  16:     0x7fba262c69f0 - middle::typeck::check_crate::hee34369af2a06be9Unp
  17:     0x7fba2632e290 - driver::driver::phase_3_run_analysis_passes::h44dc3d0e5ab4847dJ4B
  18:     0x7fba263292b0 - driver::driver::compile_input::hb7d473b561e2b247vLB
  19:     0x7fba263afb50 - <unknown>
  20:     0x7fba263afa40 - <unknown>
  21:     0x7fba25ab5f60 - <unknown>
  22:     0x7fba25ab5d50 - <unknown>
  23:     0x7fba26c0aa00 - <unknown>
  24:     0x7fba25706aa0 - <unknown>
  25:     0x7fba25706a90 - rust_try
  26:     0x7fba256a1d60 - unwind::try::h0709f530ff508047aYc
  27:     0x7fba256a1bf0 - task::Task::run::h3302eb43beb0760es4b
  28:     0x7fba26c0a740 - <unknown>
  29:     0x7fba256a3400 - <unknown>
  30:     0x7fba20872250 - start_thread
  31:     0x7fba2537d3b9 - clone
  32:                0x0 - <unknown>

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions