Skip to content

Feature gate box syntax #20723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 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"]
#![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 @@ -177,36 +186,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 @@ -223,6 +232,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 @@ -66,6 +66,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(old_impl_check)]
#![feature(box_syntax)]
#![feature(unboxed_closures)]
#![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 @@ -163,7 +163,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 @@ -24,6 +24,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 @@ -25,6 +25,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 @@ -22,8 +22,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 @@ -21,7 +21,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 @@ -22,8 +22,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 @@ -71,8 +71,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 @@ -17,6 +17,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 @@ -24,6 +24,7 @@ Core encoding and decoding interfaces.
html_playground_url = "http://play.rust-lang.org/")]
#![allow(unknown_features)]
#![feature(slicing_syntax)]
#![feature(box_syntax)]
#![feature(old_impl_check)]
#![cfg_attr(stage0, allow(unused_attributes))]

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

Expand Down
12 changes: 12 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
("associated_types", Accepted),
("visible_private_types", Active),
("slicing_syntax", Active),
("box_syntax", Active),

("if_let", Accepted),
("while_let", Accepted),
Expand Down Expand Up @@ -343,6 +344,12 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
e.span,
"range syntax is experimental");
}
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 @@ -365,6 +372,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 @@ -24,6 +24,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 @@ -49,6 +49,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 @@ -30,7 +30,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
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-14084.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)]

fn main() {
box ( () ) 0;
//~^ ERROR: only the managed heap and exchange heap are currently supported
Expand Down
Loading