Skip to content

Commit b612ae9

Browse files
committed
rustc: [T, ..N] and [T, ..N+1] are not the same
This commit fixes a bug in the calculation of the hash of a type which didn't factor in the length of a constant-sized vector. As a result of this, a type placed into an Any of a fixed length could be peeled out with any other fixed length in a safe manner.
1 parent 00e1a69 commit b612ae9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/libcore/any.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ mod tests {
263263
let s = format!("{}", b);
264264
assert_eq!(s.as_slice(), "&Any");
265265
}
266+
267+
#[test]
268+
fn any_fixed_vec() {
269+
let test = [0u, ..8];
270+
let test = &test as &Any;
271+
assert!(test.is::<[uint, ..8]>());
272+
assert!(!test.is::<[uint, ..10]>());
273+
}
266274
}
267275

268276
#[cfg(test)]

src/librustc/middle/ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4514,9 +4514,10 @@ pub fn hash_crate_independent(tcx: &ctxt, t: t, svh: &Svh) -> u64 {
45144514
ty_uniq(_) => {
45154515
byte!(10);
45164516
}
4517-
ty_vec(m, Some(_)) => {
4517+
ty_vec(m, Some(n)) => {
45184518
byte!(11);
45194519
mt(&mut state, m);
4520+
n.hash(&mut state);
45204521
1u8.hash(&mut state);
45214522
}
45224523
ty_vec(m, None) => {

0 commit comments

Comments
 (0)