rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.63k stars 12.63k forks source link

index out of bounds: the len is 1 but the index is 1 #8601

Closed carl-eastlund closed 11 years ago

carl-eastlund commented 11 years ago

From this program:

#[deriving (Clone,ToStr)]
enum Type<T> { Constant }

trait Trait<K,V> {
    fn method(&self,Type<(K,V)>) -> ();
}

impl<V:Clone+'static> Trait<u8,V> for () {
    fn method( &self, xs:Type<(u8,V)> ) -> () {
        *self; @xs;
    }
}

fn function<V:Clone+'static>( x:@Trait<V,V> ) -> () {
    x.method(Constant);
}

fn instance<V:Clone+'static>() -> @Trait<u8,V> {
    @() as @Trait<u8,V>
}

fn main () {
    function(instance());
}

...I get this error:

task <unnamed> failed at 'index out of bounds: the len is 1 but the index is 1', /Users/cce/git/rust/lang/src/librustc/middle/ty.rs:1509
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1 to get further details and report the results to github.com/mozilla/rust/issues
task <unnamed> failed at 'explicit failure', /Users/cce/git/rust/lang/src/librustc/rustc.rs:371
alexcrichton commented 11 years ago

Slightly smaller version with the same error:

enum Type<T> { Constant }

trait Trait<K,V> {
    fn method(&self,Type<(K,V)>);
}

impl<V:Clone+'static> Trait<u8,V> for () {
    fn method(&self, _: Type<(u8,V)>) {}
}

fn main () {
    let a = @() as @Trait<u8, u8>;
    a.method(Constant);
}

cc @msullivan