Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tbu- opened this issue Nov 19, 2014 · 6 comments
Closed
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@tbu-
Copy link
Contributor

tbu- commented Nov 19, 2014

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>
@oli-obk
Copy link
Contributor

oli-obk commented Nov 25, 2014

duplicate of #18998

@tbu-
Copy link
Contributor Author

tbu- commented Nov 25, 2014

@oli-obk
Is it? This one is a legitimate cast, the other issue is not.

@huonw huonw added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Nov 25, 2014
@oli-obk
Copy link
Contributor

oli-obk commented Nov 25, 2014

i don't think the legitimacy has anything to do with the error.
I'm not sure what you need an unsafe trait pointer for (which actually are two pointers. one to the vtable, one to the struct). I'm sure there are better ways, but that's not the issue here.

these are already implicitly converted. so the explicit conversion is unnecessary anyway.
if the rust-gods deem it necessary to exist, i'd implement it and add a notice that it's not necessary + hint using implicit cast.
but the ICE should be fixed to an error message (note: this is an explicit panic, it is expected to be happening there)

trait Trait { }

fn function_trait(t: &mut Trait) {
    let x : *mut Trait = t;
}

fn main() {}

@tbu-
Copy link
Contributor Author

tbu- commented Nov 25, 2014

That the implicit conversion works while the explicit one doesn't is an interesting observation…

Take this issue as "the explicit conversion does not work while it should" and the other one as "ICE when doing an incorrect type case to a raw trait pointer".

@oli-obk
Copy link
Contributor

oli-obk commented Nov 25, 2014

maybe the explicit conversion that are also implictly possible should be sugar for an implicit conversion instead of having its own code. Not sure how easy that is to detect.

@alexcrichton alexcrichton added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 20, 2015
@alexcrichton
Copy link
Member

Fixed now, just needs a test!

@bors bors closed this as completed in c81d8f9 May 4, 2015
lnicola pushed a commit to lnicola/rust that referenced this issue Feb 17, 2025
fix: Do not show safety hints for extern items lacking semantics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants