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

Internal compiler error while fighting with traits #22312

Closed
nefigah opened this issue Feb 14, 2015 · 3 comments
Closed

Internal compiler error while fighting with traits #22312

nefigah opened this issue Feb 14, 2015 · 3 comments
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

@nefigah
Copy link

nefigah commented Feb 14, 2015

rustc 1.0.0-nightly (3ef8ff1 2015-02-12 00:38:24 +0000)
binary: rustc
commit-hash: 3ef8ff1
commit-date: 2015-02-12 00:38:24 +0000
host: x86_64-apple-darwin
release: 1.0.0-nightly

src/util.rs:44:25: 44:30 error: mismatched types:
 expected `&_`,
    found `Self`
(expected &-ptr,
    found Self) [E0308]
src/util.rs:44         let indexer = &(*self as &Index<usize, Output = <Self as Index<usize>>::Output>);
                                       ^~~~~
src/util.rs:44:25: 44:30 error: internal compiler error: expected appropriate reference type
src/util.rs:44         let indexer = &(*self as &Index<usize, Output = <Self as Index<usize>>::Output>);
                                       ^~~~~
note: the compiler unexpectedly panicked. this is a bug.

Having a hell of a time getting some code to typecheck, and apparently broke the compiler with one attempt. Here's the code:

pub trait Array2D: Index<usize> {
    fn rows(&self) -> usize;
    fn columns(&self) -> usize;
    fn get<'a>(&'a self, y: usize, x: usize) -> Option<&'a <Self as Index<usize>>::Output> {
        if y >= self.rows() || x >= self.columns() {
            return None;
        }
        let i = y * self.columns() + x;
        let indexer = &(*self as &Index<usize, Output = <Self as Index<usize>>::Output>);
        Some(indexer.index(&i))
    }
}
@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Feb 14, 2015
@tamird
Copy link
Contributor

tamird commented Apr 22, 2015

@nefigah this example is incomplete. Can you add the definition of Index?

@nefigah
Copy link
Author

nefigah commented Apr 22, 2015

@tamird I'm afraid I don't understand. The bound on my trait is just referring to std::ops::Index – (which was recently changed to take the argument of index() by value, instead of by reference like at the time I reported this issue and previously)

@tamird
Copy link
Contributor

tamird commented Apr 22, 2015

@nefigah ah, thanks.

Triage: no longer ICEs.

use std::ops::Index;

pub trait Array2D: Index<usize> {
    fn rows(&self) -> usize;
    fn columns(&self) -> usize;
    fn get<'a>(&'a self, y: usize, x: usize) -> Option<&'a <Self as Index<usize>>::Output> {
        if y >= self.rows() || x >= self.columns() {
            return None;
        }
        let i = y * self.columns() + x;
        let indexer = &(*self as &Index<usize, Output = <Self as Index<usize>>::Output>);
        Some(indexer.index(i))
    }
}

fn main() {
    // Add code here
}
$ rustc main.rs
main.rs:11:25: 11:88 error: non-scalar cast: `Self` as `&core::ops::Index<usize, Output=<Self as core::ops::Index<usize>>::Output>`
main.rs:11         let indexer = &(*self as &Index<usize, Output = <Self as Index<usize>>::Output>);
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

@arielb1 arielb1 added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jul 8, 2015
@bors bors closed this as completed in 26ef17d Jul 17, 2015
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