Skip to content

Commit

Permalink
rollup merge of rust-lang#20723: pnkfelix/feature-gate-box-syntax
Browse files Browse the repository at this point in the history
Conflicts:
	src/compiletest/compiletest.rs
	src/libcollections/lib.rs
	src/libserialize/lib.rs
	src/libsyntax/feature_gate.rs
  • Loading branch information
alexcrichton committed Jan 8, 2015
2 parents d11bfba + ae4bcd4 commit 373cbab
Show file tree
Hide file tree
Showing 287 changed files with 784 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
// except according to those terms.

#![crate_type = "bin"]
#![feature(slicing_syntax)]
#![allow(unknown_features)]
#![feature(slicing_syntax, unboxed_closures)]
#![feature(box_syntax)]

#![deny(warnings)]

Expand Down
29 changes: 19 additions & 10 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ pub static HEAP: () = ();
#[stable]
pub struct Box<T>(Unique<T>);

#[unstable]
impl<T> Box<T> {
/// Moves `x` into a freshly allocated box on the global exchange heap.
#[unstable]
pub fn new(x: T) -> Box<T> {
box x
}
}

#[stable]
impl<T: Default> Default for Box<T> {
#[stable]
Expand Down Expand Up @@ -186,36 +195,36 @@ impl<T: ?Sized> DerefMut for Box<T> {
mod test {
#[test]
fn test_owned_clone() {
let a = box 5i;
let a = Box::new(5i);
let b: Box<int> = a.clone();
assert!(a == b);
}

#[test]
fn any_move() {
let a = box 8u as Box<Any>;
let b = box Test as Box<Any>;
let a = Box::new(8u) as Box<Any>;
let b = Box::new(Test) as Box<Any>;

match a.downcast::<uint>() {
Ok(a) => { assert!(a == box 8u); }
Ok(a) => { assert!(a == Box::new(8u)); }
Err(..) => panic!()
}
match b.downcast::<Test>() {
Ok(a) => { assert!(a == box Test); }
Ok(a) => { assert!(a == Box::new(Test)); }
Err(..) => panic!()
}

let a = box 8u as Box<Any>;
let b = box Test as Box<Any>;
let a = Box::new(8u) as Box<Any>;
let b = Box::new(Test) as Box<Any>;

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

#[test]
fn test_show() {
let a = box 8u as Box<Any>;
let b = box Test as Box<Any>;
let a = Box::new(8u) as Box<Any>;
let b = Box::new(Test) as Box<Any>;
let a_str = a.to_str();
let b_str = b.to_str();
assert_eq!(a_str, "Box<Any>");
Expand All @@ -232,6 +241,6 @@ mod test {
#[test]
fn deref() {
fn homura<T: Deref<Target=i32>>(_: T) { }
homura(box 765i32);
homura(Box::new(765i32));
}
}
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#![no_std]
#![allow(unknown_features)]
#![feature(lang_items, unsafe_destructor)]
#![feature(box_syntax)]

#[macro_use]
extern crate core;
Expand Down
1 change: 1 addition & 0 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#![allow(unknown_features)]
#![feature(unsafe_destructor, slicing_syntax)]
#![feature(box_syntax)]
#![feature(unboxed_closures)]
#![feature(old_impl_check)]
#![no_std]
Expand Down
3 changes: 3 additions & 0 deletions src/liblog/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]

#![allow(unknown_features)]
#![feature(slicing_syntax)]
#![feature(box_syntax)]
#![deny(missing_docs)]

extern crate regex;
Expand Down
1 change: 1 addition & 0 deletions src/libregex/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#![allow(unknown_features)]
#![feature(slicing_syntax)]
#![feature(box_syntax)]
#![deny(missing_docs)]

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#![allow(unknown_features)]
#![feature(quote)]
#![feature(slicing_syntax, unsafe_destructor)]
#![feature(box_syntax)]
#![feature(rustc_diagnostic_macros)]
#![feature(old_impl_check)]

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]

#![allow(unknown_features)]
#![feature(quote)]
#![feature(slicing_syntax, unsafe_destructor)]
#![feature(box_syntax)]
#![feature(rustc_diagnostic_macros)]

extern crate arena;
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]

#![allow(unknown_features)]
#![feature(link_args)]
#![feature(box_syntax)]

extern crate libc;

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_trans/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]

#![allow(unknown_features)]
#![feature(quote)]
#![feature(slicing_syntax, unsafe_destructor)]
#![feature(box_syntax)]
#![feature(rustc_diagnostic_macros)]

extern crate arena;
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ This API is completely unstable and subject to change.
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]

#![allow(unknown_features)]
#![feature(quote)]
#![feature(slicing_syntax, unsafe_destructor)]
#![feature(box_syntax)]
#![feature(rustc_diagnostic_macros)]
#![allow(non_camel_case_types)]

Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(slicing_syntax)]
#![feature(box_syntax)]

extern crate arena;
extern crate getopts;
Expand Down
1 change: 1 addition & 0 deletions src/libserialize/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Core encoding and decoding interfaces.
html_playground_url = "http://play.rust-lang.org/")]
#![allow(unknown_features)]
#![cfg_attr(stage0, allow(unused_attributes))]
#![feature(box_syntax)]
#![feature(old_impl_check)]
#![feature(slicing_syntax)]

Expand Down
1 change: 1 addition & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
#![feature(linkage, thread_local, asm)]
#![feature(lang_items, unsafe_destructor)]
#![feature(slicing_syntax, unboxed_closures)]
#![feature(box_syntax)]
#![feature(old_impl_check)]

// Don't link to std. We are std.
Expand Down
17 changes: 16 additions & 1 deletion src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
("tuple_indexing", Accepted),
("associated_types", Accepted),
("visible_private_types", Active),
("slicing_syntax", Accepted),
("slicing_syntax", Active),
("box_syntax", Active),

("if_let", Accepted),
("while_let", Accepted),
Expand Down Expand Up @@ -337,6 +338,15 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
}

fn visit_expr(&mut self, e: &ast::Expr) {
match e.node {
ast::ExprBox(..) | ast::ExprUnary(ast::UnOp::UnUniq, _) => {
self.gate_feature("box_syntax",
e.span,
"box expression syntax is experimental in alpha release; \
you can call `Box::new` instead.");
}
_ => {}
}
visit::walk_expr(self, e);
}

Expand All @@ -357,6 +367,11 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
but at the end of a slice (e.g. \
`[0, ..xs, 0]` are experimental")
}
ast::PatBox(..) => {
self.gate_feature("box_syntax",
pattern.span,
"box pattern syntax is experimental in alpha release");
}
_ => {}
}
visit::walk_pat(self, pattern)
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#![allow(unknown_features)]
#![feature(slicing_syntax)]
#![feature(box_syntax)]
#![feature(quote, unsafe_destructor)]

extern crate arena;
Expand Down
1 change: 1 addition & 0 deletions src/libterm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

#![allow(unknown_features)]
#![feature(slicing_syntax)]
#![feature(box_syntax)]
#![deny(missing_docs)]

#[macro_use] extern crate log;
Expand Down
2 changes: 2 additions & 0 deletions src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![allow(unknown_features)]
#![feature(asm, slicing_syntax)]
#![feature(box_syntax)]

extern crate getopts;
extern crate regex;
Expand Down
2 changes: 2 additions & 0 deletions src/test/auxiliary/cci_nested_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(unknown_features)]
#![feature(box_syntax)]

use std::cell::RefCell;

Expand Down
2 changes: 2 additions & 0 deletions src/test/auxiliary/issue-2380.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#![crate_name="a"]
#![crate_type = "lib"]

#![allow(unknown_features)]
#![feature(box_syntax)]

pub trait i<T> { }

Expand Down
3 changes: 3 additions & 0 deletions src/test/auxiliary/method_self_arg1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#![crate_type = "lib"]

#![allow(unknown_features)]
#![feature(box_syntax)]

static mut COUNT: u64 = 1;

pub fn get_count() -> u64 { unsafe { COUNT } }
Expand Down
3 changes: 3 additions & 0 deletions src/test/auxiliary/method_self_arg2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#![crate_type = "lib"]

#![allow(unknown_features)]
#![feature(box_syntax)]

static mut COUNT: u64 = 1;

pub fn get_count() -> u64 { unsafe { COUNT } }
Expand Down
3 changes: 3 additions & 0 deletions src/test/compile-fail/autoderef-full-lval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(unknown_features)]
#![feature(box_syntax)]

struct clam {
x: Box<isize>,
y: Box<isize>,
Expand Down
3 changes: 3 additions & 0 deletions src/test/compile-fail/borrow-tuple-fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(unknown_features)]
#![feature(box_syntax)]

struct Foo(Box<int>, int);

struct Bar(int, int);
Expand Down
3 changes: 3 additions & 0 deletions src/test/compile-fail/borrowck-array-double-move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(unknown_features)]
#![feature(box_syntax)]

fn f() {
let mut a = [box 0i, box 1i];
drop(a[0]);
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/borrowck-loan-in-overloaded-op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(box_syntax)]

use std::ops::Add;

#[derive(Clone)]
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/borrowck-vec-pattern-nesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

#![feature(advanced_slice_patterns)]
#![feature(box_syntax)]

fn a() {
let mut vec = [box 1i, box 2, box 3];
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/destructure-trait-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// The regression test for #15031 to make sure destructuring trait
// reference work properly.

#![feature(box_syntax)]

trait T {}
impl T for int {}

Expand Down
23 changes: 23 additions & 0 deletions src/test/compile-fail/feature-gate-box-expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
use std::boxed::HEAP;

let x = box 'c'; //~ ERROR box expression syntax is experimental in alpha release
println!("x: {}", x);

let x = box () 'c'; //~ ERROR box expression syntax is experimental in alpha release
println!("x: {}", x);

let x = box (HEAP) 'c'; //~ ERROR box expression syntax is experimental in alpha release
println!("x: {}", x);
}

14 changes: 14 additions & 0 deletions src/test/compile-fail/feature-gate-box-pat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental in alpha release
println!("x: {}", x);
}
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-12116.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(box_syntax)]

enum IntList {
Cons(int, Box<IntList>),
Nil
Expand Down
Loading

0 comments on commit 373cbab

Please sign in to comment.