suppose we have a non-copy type
struct Foo{
x:i32,
}
This works:
let a=(Foo{x:4},Foo{x:4});
let b=a.0;
And this does not:
let a=[Foo{x:4},Foo{x:4}];
let b=a[0];
suppose we have a non-copy type
struct Foo{
x:i32,
}
This works:
let a=(Foo{x:4},Foo{x:4});
let b=a.0;
And this does not:
let a=[Foo{x:4},Foo{x:4}];
let b=a[0];
There's a big difference here in that a[0]
works via std::ops::Index
, but a.0
does not. So the array indexing calls into user code, while the tuple indexing does not.
Tuple indices are always constant, array indices are generally not. The compiler cannot reason about the two equally, even if the already-mentioned implications of Index
were not there.