Skip to content

Commit b4197ae

Browse files
committed
auto merge of #10511 : cmr/rust/addtests, r=huonw
Commit messages have all
2 parents 2c9e56f + ed34cd1 commit b4197ae

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

src/librustc/middle/check_const.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
117117
ExprUnary(_, UnDeref, _) => { }
118118
ExprUnary(_, UnBox(_), _) | ExprUnary(_, UnUniq, _) => {
119119
sess.span_err(e.span,
120-
"disallowed operator in constant expression");
120+
"cannot do allocations in constant expressions");
121121
return;
122122
}
123123
ExprLit(@codemap::Spanned {node: lit_str(*), _}) => { }
@@ -191,7 +191,13 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
191191
e.span,
192192
"borrowed pointers in constants may only refer to \
193193
immutable values");
194-
}
194+
},
195+
ExprVstore(_, ExprVstoreUniq) |
196+
ExprVstore(_, ExprVstoreBox) |
197+
ExprVstore(_, ExprVstoreMutBox) => {
198+
sess.span_err(e.span, "cannot allocate vectors in constant expressions")
199+
},
200+
195201
_ => {
196202
sess.span_err(e.span,
197203
"constant contains unimplemented expression type");

src/test/compile-fail/issue-10487.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 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+
#[feature(managed_boxes)];
12+
13+
static x: ~[int] = ~[123, 456]; //~ ERROR: cannot allocate vectors in constant expressions
14+
static y: @[int] = @[123, 456]; //~ ERROR: cannot allocate vectors in constant expressions
15+
static z: @mut [int] = @mut [123, 456]; //~ ERROR: cannot allocate vectors in constant expressions
16+
17+
fn main() {}

src/test/compile-fail/static-mut-not-constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
static mut a: ~int = ~3; //~ ERROR: disallowed operator in constant
11+
static mut a: ~int = ~3; //~ ERROR: cannot do allocations in constant expressions
1212

1313
fn main() {}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2012 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+
#[feature(macro_rules)];
12+
13+
macro_rules! define_vec (
14+
() => (
15+
mod foo {
16+
#[deriving(Eq)]
17+
pub struct bar;
18+
}
19+
)
20+
)
21+
22+
define_vec!()
23+
24+
pub fn main() {}

0 commit comments

Comments
 (0)