Closed
Description
The col[i]
syntax seems to do some autodereferencing of col
, but it doesn't work with &&
and Rc
. This is confusing because method calls dereference as much as necessary:
use std::rc::Rc;
fn main() {
let v = vec![1u, 2, 3];
println!("first item: {}", v[0]); // OK
let v_ref = &v;
println!("first item: {}", v_ref[0]); // OK
let v_ref_ref = &&v;
println!("first item: {}", v_ref_ref.index(&0)); // OK
// Fails, should be equivalent to the above:
println!("first item: {}", v_ref_ref[0]);
// error: cannot index a value of type `&&collections::vec::Vec<uint>`
// println!("first item: {}", v_ref_ref[0]);
// ^~~~~~~~~~~~
let v_rc = Rc::new(vec![1u, 2, 3]);
println!("first item: {}", v_rc.index(&0)); // OK
// Fails, should be equivalent to the above:
println!("first item: {}", v_rc[0]);
// error: cannot index a value of type `alloc::rc::Rc<collections::vec::Vec<uint>>`
// println!("first item: {}", v_rc[0]);
// ^~~~~~~
}
I'm not sure if this is related to issue #15734. The circumstances seem different, but the underlying cause might be the same.
$ rustc --version
rustc 0.12.0-pre-nightly (459ffc2adc74f5e8b64a76f5670edb419b9f65da 2014-07-17 01:16:19 +0000)