Skip to content
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

ICE on casting to trait object pointer #25451

Closed
michaelwu opened this issue May 15, 2015 · 3 comments
Closed

ICE on casting to trait object pointer #25451

michaelwu opened this issue May 15, 2015 · 3 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@michaelwu
Copy link
Contributor

Playpen: http://is.gd/BpXFCU

trait Foo {
    fn get(&self) -> u32;
}

struct Bar {
    something: u32
}

impl Foo for Bar {
    fn get(&self) -> u32 {
        self.something
    }
}

fn main() {
    let x = Bar { something: 4 };
    let y = &x;
    let z: *const Foo = y as *const _ as *const _;
    let value = unsafe { (*z).get() };
    println!("Hello, world! {}", value);
}

Outputs:

error: internal compiler error: translating unsupported cast: *const Bar (cast_pointer) -> *const Foo (cast_other)
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:209
@luqmana
Copy link
Member

luqmana commented May 15, 2015

Probably addressed in #24333 or should be if it isn't.

But as a quick fix, you don't need that last as *const _ cast. The first one will take you to *const Bar and then since you have z: *const Foo it'll get coerced to a fat pointer there.

@luqmana luqmana added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label May 15, 2015
@Stebalien
Copy link
Contributor

This has already been fixed on nightly so it can't be #24333. #25038?

@michaelwu
Copy link
Contributor Author

Seems to be fixed on nightly according to playpen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants