Skip to content

Commit 6f3c202

Browse files
committed
rustc: check instantiability of fixed length vectors properly.
Previously, they were treated like ~[] and &[] (which can have length 0), but fixed length vectors are fixed length, i.e. we know at compile time if it's possible to have length zero (which is only for [T, .. 0]). Fixes #11659.
1 parent d0f6ef0 commit 6f3c202

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/librustc/middle/ty.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,12 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
22872287
::util::ppaux::ty_to_str(cx, ty));
22882288

22892289
let r = match get(ty).sty {
2290+
// fixed length vectors need special treatment compared to
2291+
// normal vectors, since they don't necessarily have the
2292+
// possibilty to have length zero.
2293+
ty_vec(_, vstore_fixed(0)) => false, // don't need no contents
2294+
ty_vec(mt, vstore_fixed(_)) => type_requires(cx, seen, r_ty, mt.ty),
2295+
22902296
ty_nil |
22912297
ty_bot |
22922298
ty_bool |
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// issue #11659, the compiler needs to know that a fixed length vector
12+
// always requires instantiable contents to instantiable itself
13+
// (unlike a ~[] vector which can have length zero).
14+
15+
// ~ to avoid infinite size.
16+
struct Uninstantiable { //~ ERROR cannot be instantiated without an instance of itself
17+
p: ~[Uninstantiable, .. 1]
18+
}
19+
20+
struct Instantiable { p: ~[Instantiable, .. 0] }
21+
22+
23+
fn main() {
24+
let _ = None::<Uninstantiable>;
25+
let _ = Instantiable { p: ~([]) };
26+
}

0 commit comments

Comments
 (0)