From e1e683186ec5b1454daa508c91129f01fbaddf22 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 12 Jun 2014 10:27:44 -0700 Subject: [PATCH] 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. --- src/libcore/any.rs | 8 ++++++++ src/librustc/middle/ty.rs | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 2a03eacf13cb3..681aca5a5cd4d 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -261,6 +261,14 @@ mod tests { let s = format!("{}", b); assert_eq!(s.as_slice(), "&Any"); } + + #[test] + fn any_fixed_vec() { + let test = [0u, ..8]; + let test = &test as &Any; + assert!(test.is::<[uint, ..8]>()); + assert!(!test.is::<[uint, ..10]>()); + } } #[cfg(test)] diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 99c337946ae3b..d3bd719b7fc5e 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -4482,9 +4482,10 @@ pub fn hash_crate_independent(tcx: &ctxt, t: t, svh: &Svh) -> u64 { ty_uniq(_) => { byte!(10); } - ty_vec(m, Some(_)) => { + ty_vec(m, Some(n)) => { byte!(11); mt(&mut state, m); + n.hash(&mut state); 1u8.hash(&mut state); } ty_vec(m, None) => {