Skip to content

ICE when attempting to explicitly type function pointer variable #24322

Closed
@maghoff

Description

@maghoff

I get an internal compiler error on the input detailed below.

I tried this code:

struct B;

impl B {
    fn func(&self) { }
}

fn main() {
    let x:&fn(&B) = &B::func;
}

I expected to see this happen: Maybe it should work like let x = &B::func, but I'm guessing that I have some error here. I get an error message when I try a variant of the above;

fn main() {
    let y = &B::func;
    let z:&fn(&B) = y;
}

This gives me the compile time error:

bug.rs:10:18: 10:19 error: mismatched types:
 expected `&fn(&B)`,
    found `&fn(&B) {B::func}`
(expected fn pointer,
    found fn item) [E0308]
bug.rs:10       let z:&fn(&B) = y;
                                ^
error: aborting due to previous error

Instead, this happened:

error: internal compiler error: unexpected panic
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 'path not fully resolved: PathResolution { base_def: DefTy(DefId { krate: 0, node: 4 }, false), last_private: LastMod(AllPublic), depth: 1 }', /build/buildd/rust-nightly-201504110408~93f7fe3~utopic/src/librustc/middle/def.rs:80

Meta

rustc --version --verbose:

rustc 1.0.0-dev (built 2015-04-11)
binary: rustc
commit-hash: unknown
commit-date: unknown
build-date: 2015-04-11
host: x86_64-unknown-linux-gnu
release: 1.0.0-dev

From the rust-nightly package here: https://launchpad.net/~hansjorg/+archive/ubuntu/rust

Backtrace:

Running RUST_BACKTRACE=1 rustc bug.rs gives me only this output:

Illegal instruction

Metadata

Metadata

Assignees

No one assigned

    Labels

    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