Skip to content

Commit 373cbab

Browse files
committed
rollup merge of #20723: pnkfelix/feature-gate-box-syntax
Conflicts: src/compiletest/compiletest.rs src/libcollections/lib.rs src/libserialize/lib.rs src/libsyntax/feature_gate.rs
2 parents d11bfba + ae4bcd4 commit 373cbab

File tree

287 files changed

+784
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

287 files changed

+784
-15
lines changed

src/compiletest/compiletest.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
// except according to those terms.
1010

1111
#![crate_type = "bin"]
12-
#![feature(slicing_syntax)]
12+
#![allow(unknown_features)]
13+
#![feature(slicing_syntax, unboxed_closures)]
14+
#![feature(box_syntax)]
1315

1416
#![deny(warnings)]
1517

src/liballoc/boxed.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ pub static HEAP: () = ();
4949
#[stable]
5050
pub struct Box<T>(Unique<T>);
5151

52+
#[unstable]
53+
impl<T> Box<T> {
54+
/// Moves `x` into a freshly allocated box on the global exchange heap.
55+
#[unstable]
56+
pub fn new(x: T) -> Box<T> {
57+
box x
58+
}
59+
}
60+
5261
#[stable]
5362
impl<T: Default> Default for Box<T> {
5463
#[stable]
@@ -186,36 +195,36 @@ impl<T: ?Sized> DerefMut for Box<T> {
186195
mod test {
187196
#[test]
188197
fn test_owned_clone() {
189-
let a = box 5i;
198+
let a = Box::new(5i);
190199
let b: Box<int> = a.clone();
191200
assert!(a == b);
192201
}
193202

194203
#[test]
195204
fn any_move() {
196-
let a = box 8u as Box<Any>;
197-
let b = box Test as Box<Any>;
205+
let a = Box::new(8u) as Box<Any>;
206+
let b = Box::new(Test) as Box<Any>;
198207

199208
match a.downcast::<uint>() {
200-
Ok(a) => { assert!(a == box 8u); }
209+
Ok(a) => { assert!(a == Box::new(8u)); }
201210
Err(..) => panic!()
202211
}
203212
match b.downcast::<Test>() {
204-
Ok(a) => { assert!(a == box Test); }
213+
Ok(a) => { assert!(a == Box::new(Test)); }
205214
Err(..) => panic!()
206215
}
207216

208-
let a = box 8u as Box<Any>;
209-
let b = box Test as Box<Any>;
217+
let a = Box::new(8u) as Box<Any>;
218+
let b = Box::new(Test) as Box<Any>;
210219

211220
assert!(a.downcast::<Box<Test>>().is_err());
212221
assert!(b.downcast::<Box<uint>>().is_err());
213222
}
214223

215224
#[test]
216225
fn test_show() {
217-
let a = box 8u as Box<Any>;
218-
let b = box Test as Box<Any>;
226+
let a = Box::new(8u) as Box<Any>;
227+
let b = Box::new(Test) as Box<Any>;
219228
let a_str = a.to_str();
220229
let b_str = b.to_str();
221230
assert_eq!(a_str, "Box<Any>");
@@ -232,6 +241,6 @@ mod test {
232241
#[test]
233242
fn deref() {
234243
fn homura<T: Deref<Target=i32>>(_: T) { }
235-
homura(box 765i32);
244+
homura(Box::new(765i32));
236245
}
237246
}

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#![no_std]
6868
#![allow(unknown_features)]
6969
#![feature(lang_items, unsafe_destructor)]
70+
#![feature(box_syntax)]
7071

7172
#[macro_use]
7273
extern crate core;

src/libcollections/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#![allow(unknown_features)]
2626
#![feature(unsafe_destructor, slicing_syntax)]
27+
#![feature(box_syntax)]
2728
#![feature(unboxed_closures)]
2829
#![feature(old_impl_check)]
2930
#![no_std]

src/liblog/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@
164164
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
165165
html_root_url = "http://doc.rust-lang.org/nightly/",
166166
html_playground_url = "http://play.rust-lang.org/")]
167+
168+
#![allow(unknown_features)]
167169
#![feature(slicing_syntax)]
170+
#![feature(box_syntax)]
168171
#![deny(missing_docs)]
169172

170173
extern crate regex;

src/libregex/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#![allow(unknown_features)]
2727
#![feature(slicing_syntax)]
28+
#![feature(box_syntax)]
2829
#![deny(missing_docs)]
2930

3031
#[cfg(test)]

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#![allow(unknown_features)]
2727
#![feature(quote)]
2828
#![feature(slicing_syntax, unsafe_destructor)]
29+
#![feature(box_syntax)]
2930
#![feature(rustc_diagnostic_macros)]
3031
#![feature(old_impl_check)]
3132

src/librustc_driver/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2424
html_root_url = "http://doc.rust-lang.org/nightly/")]
2525

26+
#![allow(unknown_features)]
2627
#![feature(quote)]
2728
#![feature(slicing_syntax, unsafe_destructor)]
29+
#![feature(box_syntax)]
2830
#![feature(rustc_diagnostic_macros)]
2931

3032
extern crate arena;

src/librustc_llvm/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2323
html_root_url = "http://doc.rust-lang.org/nightly/")]
2424

25+
#![allow(unknown_features)]
2526
#![feature(link_args)]
27+
#![feature(box_syntax)]
2628

2729
extern crate libc;
2830

src/librustc_trans/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2424
html_root_url = "http://doc.rust-lang.org/nightly/")]
2525

26+
#![allow(unknown_features)]
2627
#![feature(quote)]
2728
#![feature(slicing_syntax, unsafe_destructor)]
29+
#![feature(box_syntax)]
2830
#![feature(rustc_diagnostic_macros)]
2931

3032
extern crate arena;

src/librustc_typeck/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ This API is completely unstable and subject to change.
7272
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
7373
html_root_url = "http://doc.rust-lang.org/nightly/")]
7474

75+
#![allow(unknown_features)]
7576
#![feature(quote)]
7677
#![feature(slicing_syntax, unsafe_destructor)]
78+
#![feature(box_syntax)]
7779
#![feature(rustc_diagnostic_macros)]
7880
#![allow(non_camel_case_types)]
7981

src/librustdoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
html_root_url = "http://doc.rust-lang.org/nightly/",
1919
html_playground_url = "http://play.rust-lang.org/")]
2020
#![feature(slicing_syntax)]
21+
#![feature(box_syntax)]
2122

2223
extern crate arena;
2324
extern crate getopts;

src/libserialize/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Core encoding and decoding interfaces.
2525
html_playground_url = "http://play.rust-lang.org/")]
2626
#![allow(unknown_features)]
2727
#![cfg_attr(stage0, allow(unused_attributes))]
28+
#![feature(box_syntax)]
2829
#![feature(old_impl_check)]
2930
#![feature(slicing_syntax)]
3031

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
#![feature(linkage, thread_local, asm)]
109109
#![feature(lang_items, unsafe_destructor)]
110110
#![feature(slicing_syntax, unboxed_closures)]
111+
#![feature(box_syntax)]
111112
#![feature(old_impl_check)]
112113

113114
// Don't link to std. We are std.

src/libsyntax/feature_gate.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
6969
("tuple_indexing", Accepted),
7070
("associated_types", Accepted),
7171
("visible_private_types", Active),
72-
("slicing_syntax", Accepted),
72+
("slicing_syntax", Active),
73+
("box_syntax", Active),
7374

7475
("if_let", Accepted),
7576
("while_let", Accepted),
@@ -337,6 +338,15 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
337338
}
338339

339340
fn visit_expr(&mut self, e: &ast::Expr) {
341+
match e.node {
342+
ast::ExprBox(..) | ast::ExprUnary(ast::UnOp::UnUniq, _) => {
343+
self.gate_feature("box_syntax",
344+
e.span,
345+
"box expression syntax is experimental in alpha release; \
346+
you can call `Box::new` instead.");
347+
}
348+
_ => {}
349+
}
340350
visit::walk_expr(self, e);
341351
}
342352

@@ -357,6 +367,11 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
357367
but at the end of a slice (e.g. \
358368
`[0, ..xs, 0]` are experimental")
359369
}
370+
ast::PatBox(..) => {
371+
self.gate_feature("box_syntax",
372+
pattern.span,
373+
"box pattern syntax is experimental in alpha release");
374+
}
360375
_ => {}
361376
}
362377
visit::walk_pat(self, pattern)

src/libsyntax/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#![allow(unknown_features)]
2727
#![feature(slicing_syntax)]
28+
#![feature(box_syntax)]
2829
#![feature(quote, unsafe_destructor)]
2930

3031
extern crate arena;

src/libterm/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
#![allow(unknown_features)]
5252
#![feature(slicing_syntax)]
53+
#![feature(box_syntax)]
5354
#![deny(missing_docs)]
5455

5556
#[macro_use] extern crate log;

src/libtest/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
3232
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
3333
html_root_url = "http://doc.rust-lang.org/nightly/")]
34+
#![allow(unknown_features)]
3435
#![feature(asm, slicing_syntax)]
36+
#![feature(box_syntax)]
3537

3638
extern crate getopts;
3739
extern crate regex;

src/test/auxiliary/cci_nested_lib.rs

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

11+
#![allow(unknown_features)]
12+
#![feature(box_syntax)]
1113

1214
use std::cell::RefCell;
1315

src/test/auxiliary/issue-2380.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#![crate_name="a"]
1212
#![crate_type = "lib"]
1313

14+
#![allow(unknown_features)]
15+
#![feature(box_syntax)]
1416

1517
pub trait i<T> { }
1618

src/test/auxiliary/method_self_arg1.rs

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
#![crate_type = "lib"]
1212

13+
#![allow(unknown_features)]
14+
#![feature(box_syntax)]
15+
1316
static mut COUNT: u64 = 1;
1417

1518
pub fn get_count() -> u64 { unsafe { COUNT } }

src/test/auxiliary/method_self_arg2.rs

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
#![crate_type = "lib"]
1212

13+
#![allow(unknown_features)]
14+
#![feature(box_syntax)]
15+
1316
static mut COUNT: u64 = 1;
1417

1518
pub fn get_count() -> u64 { unsafe { COUNT } }

src/test/compile-fail/autoderef-full-lval.rs

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

11+
#![allow(unknown_features)]
12+
#![feature(box_syntax)]
13+
1114
struct clam {
1215
x: Box<isize>,
1316
y: Box<isize>,

src/test/compile-fail/borrow-tuple-fields.rs

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

11+
#![allow(unknown_features)]
12+
#![feature(box_syntax)]
13+
1114
struct Foo(Box<int>, int);
1215

1316
struct Bar(int, int);

src/test/compile-fail/borrowck-array-double-move.rs

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

11+
#![allow(unknown_features)]
12+
#![feature(box_syntax)]
13+
1114
fn f() {
1215
let mut a = [box 0i, box 1i];
1316
drop(a[0]);

src/test/compile-fail/borrowck-loan-in-overloaded-op.rs

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

11+
#![feature(box_syntax)]
12+
1113
use std::ops::Add;
1214

1315
#[derive(Clone)]

src/test/compile-fail/borrowck-vec-pattern-nesting.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(advanced_slice_patterns)]
12+
#![feature(box_syntax)]
1213

1314
fn a() {
1415
let mut vec = [box 1i, box 2, box 3];

src/test/compile-fail/destructure-trait-ref.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
// The regression test for #15031 to make sure destructuring trait
1212
// reference work properly.
1313

14+
#![feature(box_syntax)]
15+
1416
trait T {}
1517
impl T for int {}
1618

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 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+
fn main() {
12+
use std::boxed::HEAP;
13+
14+
let x = box 'c'; //~ ERROR box expression syntax is experimental in alpha release
15+
println!("x: {}", x);
16+
17+
let x = box () 'c'; //~ ERROR box expression syntax is experimental in alpha release
18+
println!("x: {}", x);
19+
20+
let x = box (HEAP) 'c'; //~ ERROR box expression syntax is experimental in alpha release
21+
println!("x: {}", x);
22+
}
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2015 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+
fn main() {
12+
let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental in alpha release
13+
println!("x: {}", x);
14+
}

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

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

11+
#![feature(box_syntax)]
12+
1113
enum IntList {
1214
Cons(int, Box<IntList>),
1315
Nil

0 commit comments

Comments
 (0)