From 82af2a1847fd51dd82f38666283ec9ff174d7a74 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 7 Jan 2015 01:10:50 +0100 Subject: Add `Box::new` method. Prereq for feature-gating `box ` itself. --- src/liballoc/boxed.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/liballoc') diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index d46f18abf97..cec49fa6186 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -49,6 +49,15 @@ pub static HEAP: () = (); #[stable] pub struct Box(Unique); +#[unstable] +impl Box { + /// Moves `x` into a freshly allocated box on the global exchange heap. + #[unstable] + pub fn new(x: T) -> Box { + box x + } +} + #[stable] impl Default for Box { #[stable] -- cgit 1.4.1-3-g733a5 From 4a31aaddb364f5ab8280242a1016bdd3d10dcaed Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 7 Jan 2015 15:15:34 +0100 Subject: Added `box_syntax` feature gate; added to std and rustc crates for bootstrap. To avoid using the feauture, change uses of `box ` to `Box::new()` alternative, as noted by the feature gate message. (Note that box patterns have no analogous trivial replacement, at least not in general; you need to revise the code to do a partial match, deref, and then the rest of the match.) [breaking-change] --- src/liballoc/lib.rs | 1 + src/libcollections/lib.rs | 1 + src/liblog/lib.rs | 1 + src/libregex/lib.rs | 1 + src/librustc/lib.rs | 1 + src/librustc_trans/lib.rs | 1 + src/librustc_typeck/lib.rs | 1 + src/librustdoc/lib.rs | 1 + src/libserialize/lib.rs | 1 + src/libstd/lib.rs | 1 + src/libsyntax/feature_gate.rs | 12 ++++++++++++ src/libsyntax/lib.rs | 1 + src/libterm/lib.rs | 1 + src/libtest/lib.rs | 1 + 14 files changed, 25 insertions(+) (limited to 'src/liballoc') diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index ba6e89cdd76..402a542a92b 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -66,6 +66,7 @@ #![no_std] #![allow(unknown_features)] #![feature(lang_items, unsafe_destructor)] +#![feature(box_syntax)] #[macro_use] extern crate core; diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 6eab36d8844..37bc37b84df 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -24,6 +24,7 @@ #![allow(unknown_features)] #![feature(unsafe_destructor, slicing_syntax)] #![feature(old_impl_check)] +#![feature(box_syntax)] #![feature(unboxed_closures)] #![no_std] diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 08b01e956e1..ca61e3d1655 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -164,6 +164,7 @@ html_root_url = "http://doc.rust-lang.org/nightly/", html_playground_url = "http://play.rust-lang.org/")] #![feature(slicing_syntax)] +#![feature(box_syntax)] #![deny(missing_docs)] extern crate regex; diff --git a/src/libregex/lib.rs b/src/libregex/lib.rs index c039abc9aff..bd93816a26d 100644 --- a/src/libregex/lib.rs +++ b/src/libregex/lib.rs @@ -24,6 +24,7 @@ #![allow(unknown_features)] #![feature(slicing_syntax)] +#![feature(box_syntax)] #![deny(missing_docs)] #[cfg(test)] diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index a3a041c2497..7b57544d9d1 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -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)] diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index b6f90a4c2f5..e5f8334049b 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -24,6 +24,7 @@ #![feature(quote)] #![feature(slicing_syntax, unsafe_destructor)] +#![feature(box_syntax)] #![feature(rustc_diagnostic_macros)] extern crate arena; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index ae8731dfa47..950b3e4da86 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -73,6 +73,7 @@ This API is completely unstable and subject to change. #![feature(quote)] #![feature(slicing_syntax, unsafe_destructor)] +#![feature(box_syntax)] #![feature(rustc_diagnostic_macros)] #![allow(non_camel_case_types)] diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index ee65ef06623..d71dd00dc85 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -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; diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 139170fc012..39a6471aac6 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -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))] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index eef5bdb60ee..d34f497bbea 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -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))] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index f10113254de..fbff5e16ef5 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -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), @@ -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); @@ -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) diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 9e14f9dd1ea..b6516254dbf 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -24,6 +24,7 @@ #![allow(unknown_features)] #![feature(slicing_syntax)] +#![feature(box_syntax)] #![feature(quote, unsafe_destructor)] extern crate arena; diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index c953f591d80..8f486ea8c02 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -49,6 +49,7 @@ #![allow(unknown_features)] #![feature(slicing_syntax)] +#![feature(box_syntax)] #![deny(missing_docs)] #[macro_use] extern crate log; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 68d06cc4dab..506a625beb6 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -31,6 +31,7 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] #![feature(asm, slicing_syntax)] +#![feature(box_syntax)] extern crate getopts; extern crate regex; -- cgit 1.4.1-3-g733a5 From 3fd6bfa8f7a1d193316956b5be8818c47bb874b7 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 7 Jan 2015 23:04:12 +0100 Subject: Switch to using `Box::new` in the tests in `alloc::boxed`. --- src/liballoc/boxed.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index cec49fa6186..f3ce50ec051 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -186,27 +186,27 @@ impl DerefMut for Box { mod test { #[test] fn test_owned_clone() { - let a = box 5i; + let a = Box::new(5i); let b: Box = a.clone(); assert!(a == b); } #[test] fn any_move() { - let a = box 8u as Box; - let b = box Test as Box; + let a = Box::new(8u) as Box; + let b = Box::new(Test) as Box; match a.downcast::() { - Ok(a) => { assert!(a == box 8u); } + Ok(a) => { assert!(a == Box::new(8u)); } Err(..) => panic!() } match b.downcast::() { - Ok(a) => { assert!(a == box Test); } + Ok(a) => { assert!(a == Box::new(Test)); } Err(..) => panic!() } - let a = box 8u as Box; - let b = box Test as Box; + let a = Box::new(8u) as Box; + let b = Box::new(Test) as Box; assert!(a.downcast::>().is_err()); assert!(b.downcast::>().is_err()); @@ -214,8 +214,8 @@ mod test { #[test] fn test_show() { - let a = box 8u as Box; - let b = box Test as Box; + let a = Box::new(8u) as Box; + let b = Box::new(Test) as Box; let a_str = a.to_str(); let b_str = b.to_str(); assert_eq!(a_str, "Box"); @@ -232,6 +232,6 @@ mod test { #[test] fn deref() { fn homura>(_: T) { } - homura(box 765i32); + homura(Box::new(765i32)); } } -- cgit 1.4.1-3-g733a5