Skip to content

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

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
apoelstra opened this issue Dec 13, 2013 · 2 comments · Fixed by #11386
Closed

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

apoelstra opened this issue Dec 13, 2013 · 2 comments · Fixed by #11386
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@apoelstra
Copy link
Contributor

There is another bug by the same name, but that one was fixed. After searching about 10 minutes, I couldn't find any duplicates.

The code

fn main () {
    let arr: ~[u8] = ~[ 1, 2, 3 ];
    let iter = &arr.iter() as &Iterator<&u8>
}

Fails to compile with the following error

task 'rustc' failed at 'index out of bounds: the len is 1 but the index is 1', /home/username/dload/code/rust/src/librustc/middle/ty.rs:1432
error: internal compiler error: unexpected failure
This message reflects a bug in the Rust compiler. 
We would appreciate a bug report: https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report
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 '' failed at 'explicit failure', /home/username/dload/code/rust/src/librustc/lib.rs:398

I am running rustc 0.9-pre (e5f4904 2013-12-13 07:51:42 -0800) on Fedora 19 (Linux 3.11.6-200.fc19.x86_64 #1 SMP). This is latest git HEAD as of about an hour ago.

@nikomatsakis
Copy link
Contributor

cc me

@rcatolino
Copy link
Contributor

This happens anytime you cast a generic struct to a trait containing a generic method implementation:


trait Tr {
  fn dostuff<A>(&self, v: A) -> A {
    v
  }
}

struct St <T> {
  val: T,
}

impl<T> Tr for St <T> {}

fn main () {
  let a = St { val: 1 };
  let b = &a as &Tr;
}

From what i understand, during the vtable generation, before dostuff is discarded for being generic, we try to perform its type parameter substitution, which goes to hell because there's no type to substitute to A.

I'm not sure why there's a call to ty::subst_tps from trans::meth::emit_vtable_methods for generic methods, since those are discarded just afterward.

@bors bors closed this as completed in ebc079c Jan 9, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 31, 2023
…exendoo,blyxyas

new lint [`redundant_guards`]

Closes rust-lang#7825, maybe somebody else can get the ranges lint in the comments?

changelog: New lint [`redundant_guards`]
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

Successfully merging a pull request may close this issue.

3 participants