1
Fork 0

Switched to Box::new in many places.

Many of the modifications putting in `Box::new` calls also include a
pointer to Issue 22405, which tracks going back to `box <expr>` if
possible in the future.

(Still tried to use `Box<_>` where it sufficed; thus some tests still
have `box_syntax` enabled, as they use a mix of `box` and `Box::new`.)

Precursor for overloaded-`box` and placement-`in`; see Issue 22181.
This commit is contained in:
Felix S. Klock II 2015-02-15 09:52:21 +01:00
parent b03279aaa2
commit 0d5bcb14ad
118 changed files with 349 additions and 373 deletions

View file

@ -157,7 +157,7 @@ impl<T: Default> Default for Box<T> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Box<[T]> { impl<T> Default for Box<[T]> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
fn default() -> Box<[T]> { box [] } fn default() -> Box<[T]> { Box::<[T; 0]>::new([]) }
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]

View file

@ -64,7 +64,8 @@ fn test_writer_hasher() {
//assert_eq!(hasher.hash(& s), 97 + 0xFF); //assert_eq!(hasher.hash(& s), 97 + 0xFF);
let cs: &[u8] = &[1u8, 2u8, 3u8]; let cs: &[u8] = &[1u8, 2u8, 3u8];
assert_eq!(hash(& cs), 9); assert_eq!(hash(& cs), 9);
let cs: Box<[u8]> = box [1u8, 2u8, 3u8]; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let cs: Box<[u8]> = Box::new([1u8, 2u8, 3u8]);
assert_eq!(hash(& cs), 9); assert_eq!(hash(& cs), 9);
// FIXME (#18248) Add tests for hashing Rc<str> and Rc<[T]> // FIXME (#18248) Add tests for hashing Rc<str> and Rc<[T]>

View file

@ -404,7 +404,8 @@ fn test_collect() {
#[test] #[test]
fn test_all() { fn test_all() {
let v: Box<[int]> = box [1, 2, 3, 4, 5]; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let v: Box<[int]> = Box::new([1, 2, 3, 4, 5]);
assert!(v.iter().all(|&x| x < 10)); assert!(v.iter().all(|&x| x < 10));
assert!(!v.iter().all(|&x| x % 2 == 0)); assert!(!v.iter().all(|&x| x % 2 == 0));
assert!(!v.iter().all(|&x| x > 100)); assert!(!v.iter().all(|&x| x > 100));
@ -413,7 +414,8 @@ fn test_all() {
#[test] #[test]
fn test_any() { fn test_any() {
let v: Box<[int]> = box [1, 2, 3, 4, 5]; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let v: Box<[int]> = Box::new([1, 2, 3, 4, 5]);
assert!(v.iter().any(|&x| x < 10)); assert!(v.iter().any(|&x| x < 10));
assert!(v.iter().any(|&x| x % 2 == 0)); assert!(v.iter().any(|&x| x % 2 == 0));
assert!(!v.iter().any(|&x| x > 100)); assert!(!v.iter().any(|&x| x > 100));
@ -581,7 +583,8 @@ fn test_rposition() {
#[test] #[test]
#[should_fail] #[should_fail]
fn test_rposition_panic() { fn test_rposition_panic() {
let v = [(box 0, box 0), (box 0, box 0), let v: [(Box<_>, Box<_>); 4] =
[(box 0, box 0), (box 0, box 0),
(box 0, box 0), (box 0, box 0)]; (box 0, box 0), (box 0, box 0)];
let mut i = 0; let mut i = 0;
v.iter().rposition(|_elt| { v.iter().rposition(|_elt| {

View file

@ -79,7 +79,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
None => {} None => {}
} }
let expr_id = match csearch::maybe_get_item_ast(tcx, enum_def, let expr_id = match csearch::maybe_get_item_ast(tcx, enum_def,
box |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) { Box::new(|a, b, c, d| astencode::decode_inlined_item(a, b, c, d))) {
csearch::FoundAst::Found(&ast::IIItem(ref item)) => match item.node { csearch::FoundAst::Found(&ast::IIItem(ref item)) => match item.node {
ast::ItemEnum(ast::EnumDef { ref variants }, _) => { ast::ItemEnum(ast::EnumDef { ref variants }, _) => {
// NOTE this doesn't do the right thing, it compares inlined // NOTE this doesn't do the right thing, it compares inlined
@ -119,7 +119,7 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId)
None => {} None => {}
} }
let expr_id = match csearch::maybe_get_item_ast(tcx, def_id, let expr_id = match csearch::maybe_get_item_ast(tcx, def_id,
box |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) { Box::new(|a, b, c, d| astencode::decode_inlined_item(a, b, c, d))) {
csearch::FoundAst::Found(&ast::IIItem(ref item)) => match item.node { csearch::FoundAst::Found(&ast::IIItem(ref item)) => match item.node {
ast::ItemConst(_, ref const_expr) => Some(const_expr.id), ast::ItemConst(_, ref const_expr) => Some(const_expr.id),
_ => None _ => None

View file

@ -99,7 +99,7 @@ impl<'a> Registry<'a> {
/// It builds for you a `NormalTT` that calls `expander`, /// It builds for you a `NormalTT` that calls `expander`,
/// and also takes care of interning the macro's name. /// and also takes care of interning the macro's name.
pub fn register_macro(&mut self, name: &str, expander: MacroExpanderFn) { pub fn register_macro(&mut self, name: &str, expander: MacroExpanderFn) {
self.register_syntax_extension(token::intern(name), NormalTT(box expander, None)); self.register_syntax_extension(token::intern(name), NormalTT(Box::new(expander), None));
} }
/// Register a compiler lint pass. /// Register a compiler lint pass.

View file

@ -2969,7 +2969,7 @@ pub fn write_metadata(cx: &SharedCrateContext, krate: &ast::Crate) -> Vec<u8> {
} }
let encode_inlined_item: encoder::EncodeInlinedItem = let encode_inlined_item: encoder::EncodeInlinedItem =
box |ecx, rbml_w, ii| astencode::encode_inlined_item(ecx, rbml_w, ii); Box::new(|ecx, rbml_w, ii| astencode::encode_inlined_item(ecx, rbml_w, ii));
let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item); let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
let metadata = encoder::encode_metadata(encode_parms, krate); let metadata = encoder::encode_metadata(encode_parms, krate);

View file

@ -40,7 +40,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
let csearch_result = let csearch_result =
csearch::maybe_get_item_ast( csearch::maybe_get_item_ast(
ccx.tcx(), fn_id, ccx.tcx(), fn_id,
box |a,b,c,d| astencode::decode_inlined_item(a, b, c, d)); Box::new(|a,b,c,d| astencode::decode_inlined_item(a, b, c, d)));
let inline_def = match csearch_result { let inline_def = match csearch_result {
csearch::FoundAst::NotFound => { csearch::FoundAst::NotFound => {

View file

@ -152,12 +152,12 @@ fn try_overloaded_call_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
&closure_ty.sig).0; &closure_ty.sig).0;
fcx.record_deferred_call_resolution( fcx.record_deferred_call_resolution(
def_id, def_id,
box CallResolution {call_expr: call_expr, Box::new(CallResolution {call_expr: call_expr,
callee_expr: callee_expr, callee_expr: callee_expr,
adjusted_ty: adjusted_ty, adjusted_ty: adjusted_ty,
autoderefref: autoderefref, autoderefref: autoderefref,
fn_sig: fn_sig.clone(), fn_sig: fn_sig.clone(),
closure_def_id: def_id}); closure_def_id: def_id}));
return Some(CallStep::DeferredClosure(fn_sig)); return Some(CallStep::DeferredClosure(fn_sig));
} }
} }

View file

@ -547,8 +547,9 @@ mod tests {
let (tx, rx) = channel(); let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let _t = thread::spawn(move|| { let _t = thread::spawn(move|| {
set_stdout(box w); set_stdout(Box::new(w));
println!("hello!"); println!("hello!");
}); });
assert_eq!(r.read_to_string().unwrap(), "hello!\n"); assert_eq!(r.read_to_string().unwrap(), "hello!\n");
@ -560,8 +561,9 @@ mod tests {
let (tx, rx) = channel(); let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let _t = thread::spawn(move || -> () { let _t = thread::spawn(move || -> () {
set_stderr(box w); set_stderr(Box::new(w));
panic!("my special message"); panic!("my special message");
}); });
let s = r.read_to_string().unwrap(); let s = r.read_to_string().unwrap();

View file

@ -15,6 +15,7 @@
// FIXME: These functions take Durations but only pass ms to the backend impls. // FIXME: These functions take Durations but only pass ms to the backend impls.
use boxed::Box;
use sync::mpsc::{Receiver, Sender, channel}; use sync::mpsc::{Receiver, Sender, channel};
use time::Duration; use time::Duration;
use old_io::IoResult; use old_io::IoResult;
@ -143,7 +144,7 @@ impl Timer {
let (tx, rx) = channel(); let (tx, rx) = channel();
// Short-circuit the timer backend for 0 duration // Short-circuit the timer backend for 0 duration
if in_ms_u64(duration) != 0 { if in_ms_u64(duration) != 0 {
self.inner.oneshot(in_ms_u64(duration), box TimerCallback { tx: tx }); self.inner.oneshot(in_ms_u64(duration), Box::new(TimerCallback { tx: tx }));
} else { } else {
tx.send(()).unwrap(); tx.send(()).unwrap();
} }
@ -204,7 +205,7 @@ impl Timer {
// not clear what use a 0ms period is anyway... // not clear what use a 0ms period is anyway...
let ms = if ms == 0 { 1 } else { ms }; let ms = if ms == 0 { 1 } else { ms };
let (tx, rx) = channel(); let (tx, rx) = channel();
self.inner.period(ms, box TimerCallback { tx: tx }); self.inner.period(ms, Box::new(TimerCallback { tx: tx }));
return rx return rx
} }
} }

View file

@ -166,7 +166,7 @@ fn rust_panic(cause: Box<Any + Send + 'static>) -> ! {
rtdebug!("begin_unwind()"); rtdebug!("begin_unwind()");
unsafe { unsafe {
let exception = box Exception { let exception: Box<_> = box Exception {
uwe: uw::_Unwind_Exception { uwe: uw::_Unwind_Exception {
exception_class: rust_exception_class(), exception_class: rust_exception_class(),
exception_cleanup: exception_cleanup, exception_cleanup: exception_cleanup,
@ -506,7 +506,7 @@ pub fn begin_unwind_fmt(msg: fmt::Arguments, file_line: &(&'static str, uint)) -
let mut s = String::new(); let mut s = String::new();
let _ = write!(&mut s, "{}", msg); let _ = write!(&mut s, "{}", msg);
begin_unwind_inner(box s, file_line) begin_unwind_inner(Box::new(s), file_line)
} }
/// This is the entry point of unwinding for panic!() and assert!(). /// This is the entry point of unwinding for panic!() and assert!().
@ -521,7 +521,7 @@ pub fn begin_unwind<M: Any + Send>(msg: M, file_line: &(&'static str, uint)) ->
// panicking. // panicking.
// see below for why we do the `Any` coercion here. // see below for why we do the `Any` coercion here.
begin_unwind_inner(box msg, file_line) begin_unwind_inner(Box::new(msg), file_line)
} }
/// The core of the unwinding. /// The core of the unwinding.

View file

@ -33,7 +33,7 @@ impl<'a,A,R> Thunk<'a,A,R> {
where F : FnOnce(A) -> R, F : Send + 'a where F : FnOnce(A) -> R, F : Send + 'a
{ {
Thunk { Thunk {
invoke: box func invoke: Box::<F>::new(func)
} }
} }

View file

@ -223,7 +223,7 @@ pub fn mk_span_handler(handler: Handler, cm: codemap::CodeMap) -> SpanHandler {
pub fn default_handler(color_config: ColorConfig, pub fn default_handler(color_config: ColorConfig,
registry: Option<diagnostics::registry::Registry>, registry: Option<diagnostics::registry::Registry>,
can_emit_warnings: bool) -> Handler { can_emit_warnings: bool) -> Handler {
mk_handler(can_emit_warnings, box EmitterWriter::stderr(color_config, registry)) mk_handler(can_emit_warnings, Box::new(EmitterWriter::stderr(color_config, registry)))
} }
pub fn mk_handler(can_emit_warnings: bool, e: Box<Emitter + Send>) -> Handler { pub fn mk_handler(can_emit_warnings: bool, e: Box<Emitter + Send>) -> Handler {
@ -352,11 +352,11 @@ impl EmitterWriter {
if use_color { if use_color {
let dst = match term::stderr() { let dst = match term::stderr() {
Some(t) => Terminal(t), Some(t) => Terminal(t),
None => Raw(box stderr), None => Raw(Box::new(stderr)),
}; };
EmitterWriter { dst: dst, registry: registry } EmitterWriter { dst: dst, registry: registry }
} else { } else {
EmitterWriter { dst: Raw(box stderr), registry: registry } EmitterWriter { dst: Raw(Box::new(stderr)), registry: registry }
} }
} }

View file

@ -465,7 +465,7 @@ fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>)
-> SyntaxEnv { -> SyntaxEnv {
// utility function to simplify creating NormalTT syntax extensions // utility function to simplify creating NormalTT syntax extensions
fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension { fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
NormalTT(box f, None) NormalTT(Box::new(f), None)
} }
let mut syntax_expanders = SyntaxEnv::new(); let mut syntax_expanders = SyntaxEnv::new();
@ -489,9 +489,9 @@ fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>)
builtin_normal_expander( builtin_normal_expander(
ext::log_syntax::expand_syntax_ext)); ext::log_syntax::expand_syntax_ext));
syntax_expanders.insert(intern("derive"), syntax_expanders.insert(intern("derive"),
Decorator(box ext::deriving::expand_meta_derive)); Decorator(Box::new(ext::deriving::expand_meta_derive)));
syntax_expanders.insert(intern("deriving"), syntax_expanders.insert(intern("deriving"),
Decorator(box ext::deriving::expand_deprecated_deriving)); Decorator(Box::new(ext::deriving::expand_deprecated_deriving)));
if ecfg.enable_quotes() { if ecfg.enable_quotes() {
// Quasi-quoting expanders // Quasi-quoting expanders

View file

@ -40,9 +40,9 @@ pub fn expand_deriving_clone<F>(cx: &mut ExtCtxt,
args: Vec::new(), args: Vec::new(),
ret_ty: Self_, ret_ty: Self_,
attributes: attrs, attributes: attrs,
combine_substructure: combine_substructure(box |c, s, sub| { combine_substructure: combine_substructure(Box::new(|c, s, sub| {
cs_clone("Clone", c, s, sub) cs_clone("Clone", c, s, sub)
}), })),
} }
), ),
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -40,7 +40,7 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
cx.expr_binary(span, ast::BiAnd, subexpr, eq) cx.expr_binary(span, ast::BiAnd, subexpr, eq)
}, },
cx.expr_bool(span, true), cx.expr_bool(span, true),
box |cx, span, _, _| cx.expr_bool(span, false), Box::new(|cx, span, _, _| cx.expr_bool(span, false)),
cx, span, substr) cx, span, substr)
} }
fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> { fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
@ -57,7 +57,7 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
cx.expr_binary(span, ast::BiOr, subexpr, eq) cx.expr_binary(span, ast::BiOr, subexpr, eq)
}, },
cx.expr_bool(span, false), cx.expr_bool(span, false),
box |cx, span, _, _| cx.expr_bool(span, true), Box::new(|cx, span, _, _| cx.expr_bool(span, true)),
cx, span, substr) cx, span, substr)
} }
@ -72,9 +72,9 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
args: vec!(borrowed_self()), args: vec!(borrowed_self()),
ret_ty: Literal(path_local!(bool)), ret_ty: Literal(path_local!(bool)),
attributes: attrs, attributes: attrs,
combine_substructure: combine_substructure(box |a, b, c| { combine_substructure: combine_substructure(Box::new(|a, b, c| {
$f(a, b, c) $f(a, b, c)
}) }))
} }
} } } }
} }

View file

@ -38,9 +38,9 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
args: vec!(borrowed_self()), args: vec!(borrowed_self()),
ret_ty: Literal(path_local!(bool)), ret_ty: Literal(path_local!(bool)),
attributes: attrs, attributes: attrs,
combine_substructure: combine_substructure(box |cx, span, substr| { combine_substructure: combine_substructure(Box::new(|cx, span, substr| {
cs_op($op, $equal, cx, span, substr) cs_op($op, $equal, cx, span, substr)
}) }))
} }
} } } }
} }
@ -61,9 +61,9 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
args: vec![borrowed_self()], args: vec![borrowed_self()],
ret_ty: ret_ty, ret_ty: ret_ty,
attributes: attrs, attributes: attrs,
combine_substructure: combine_substructure(box |cx, span, substr| { combine_substructure: combine_substructure(Box::new(|cx, span, substr| {
cs_partial_cmp(cx, span, substr) cs_partial_cmp(cx, span, substr)
}) }))
}; };
let trait_def = TraitDef { let trait_def = TraitDef {
@ -175,13 +175,13 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
cx.expr_block(cx.block(span, vec!(assign), Some(if_))) cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
}, },
equals_expr.clone(), equals_expr.clone(),
box |cx, span, (self_args, tag_tuple), _non_self_args| { Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
if self_args.len() != 2 { if self_args.len() != 2 {
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`") cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
} else { } else {
some_ordering_collapsed(cx, span, PartialCmpOp, tag_tuple) some_ordering_collapsed(cx, span, PartialCmpOp, tag_tuple)
} }
}, }),
cx, span, substr) cx, span, substr)
} }
@ -223,7 +223,7 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
cx.expr_binary(span, ast::BiOr, cmp, and) cx.expr_binary(span, ast::BiOr, cmp, and)
}, },
cx.expr_bool(span, equal), cx.expr_bool(span, equal),
box |cx, span, (self_args, tag_tuple), _non_self_args| { Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
if self_args.len() != 2 { if self_args.len() != 2 {
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`") cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
} else { } else {
@ -233,6 +233,6 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
}; };
some_ordering_collapsed(cx, span, op, tag_tuple) some_ordering_collapsed(cx, span, op, tag_tuple)
} }
}, }),
cx, span, substr) cx, span, substr)
} }

View file

@ -32,7 +32,8 @@ pub fn expand_deriving_totaleq<F>(cx: &mut ExtCtxt,
let block = cx.block(span, stmts, None); let block = cx.block(span, stmts, None);
cx.expr_block(block) cx.expr_block(block)
}, },
box |cx, sp, _, _| cx.span_bug(sp, "non matching enums in derive(Eq)?"), Box::new(|cx, sp, _, _| {
cx.span_bug(sp, "non matching enums in derive(Eq)?") }),
cx, cx,
span, span,
substr) substr)
@ -57,9 +58,9 @@ pub fn expand_deriving_totaleq<F>(cx: &mut ExtCtxt,
args: vec!(), args: vec!(),
ret_ty: nil_ty(), ret_ty: nil_ty(),
attributes: attrs, attributes: attrs,
combine_substructure: combine_substructure(box |a, b, c| { combine_substructure: combine_substructure(Box::new(|a, b, c| {
cs_total_eq_assert(a, b, c) cs_total_eq_assert(a, b, c)
}) }))
} }
), ),
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -41,9 +41,9 @@ pub fn expand_deriving_totalord<F>(cx: &mut ExtCtxt,
args: vec!(borrowed_self()), args: vec!(borrowed_self()),
ret_ty: Literal(path_std!(cx, core::cmp::Ordering)), ret_ty: Literal(path_std!(cx, core::cmp::Ordering)),
attributes: attrs, attributes: attrs,
combine_substructure: combine_substructure(box |a, b, c| { combine_substructure: combine_substructure(Box::new(|a, b, c| {
cs_cmp(a, b, c) cs_cmp(a, b, c)
}), })),
} }
), ),
associated_types: Vec::new(), associated_types: Vec::new(),
@ -131,12 +131,12 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
cx.expr_block(cx.block(span, vec!(assign), Some(if_))) cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
}, },
cx.expr_path(equals_path.clone()), cx.expr_path(equals_path.clone()),
box |cx, span, (self_args, tag_tuple), _non_self_args| { Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
if self_args.len() != 2 { if self_args.len() != 2 {
cx.span_bug(span, "not exactly 2 arguments in `derives(Ord)`") cx.span_bug(span, "not exactly 2 arguments in `derives(Ord)`")
} else { } else {
ordering_collapsed(cx, span, tag_tuple) ordering_collapsed(cx, span, tag_tuple)
} }
}, }),
cx, span, substr) cx, span, substr)
} }

View file

@ -82,9 +82,9 @@ fn expand_deriving_decodable_imp<F>(cx: &mut ExtCtxt,
true true
)), )),
attributes: Vec::new(), attributes: Vec::new(),
combine_substructure: combine_substructure(box |a, b, c| { combine_substructure: combine_substructure(Box::new(|a, b, c| {
decodable_substructure(a, b, c, krate) decodable_substructure(a, b, c, krate)
}), })),
} }
), ),
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -40,9 +40,9 @@ pub fn expand_deriving_default<F>(cx: &mut ExtCtxt,
args: Vec::new(), args: Vec::new(),
ret_ty: Self_, ret_ty: Self_,
attributes: attrs, attributes: attrs,
combine_substructure: combine_substructure(box |a, b, c| { combine_substructure: combine_substructure(Box::new(|a, b, c| {
default_substructure(a, b, c) default_substructure(a, b, c)
}) }))
} }
), ),
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -158,9 +158,9 @@ fn expand_deriving_encodable_imp<F>(cx: &mut ExtCtxt,
true true
)), )),
attributes: Vec::new(), attributes: Vec::new(),
combine_substructure: combine_substructure(box |a, b, c| { combine_substructure: combine_substructure(Box::new(|a, b, c| {
encodable_substructure(a, b, c) encodable_substructure(a, b, c)
}), })),
} }
), ),
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -45,9 +45,9 @@ pub fn expand_deriving_hash<F>(cx: &mut ExtCtxt,
args: vec!(Ptr(box Literal(arg), Borrowed(None, MutMutable))), args: vec!(Ptr(box Literal(arg), Borrowed(None, MutMutable))),
ret_ty: nil_ty(), ret_ty: nil_ty(),
attributes: vec![], attributes: vec![],
combine_substructure: combine_substructure(box |a, b, c| { combine_substructure: combine_substructure(Box::new(|a, b, c| {
hash_substructure(a, b, c) hash_substructure(a, b, c)
}) }))
} }
), ),
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -45,9 +45,9 @@ pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
true)), true)),
// #[inline] liable to cause code-bloat // #[inline] liable to cause code-bloat
attributes: attrs.clone(), attributes: attrs.clone(),
combine_substructure: combine_substructure(box |c, s, sub| { combine_substructure: combine_substructure(Box::new(|c, s, sub| {
cs_from("i64", c, s, sub) cs_from("i64", c, s, sub)
}), })),
}, },
MethodDef { MethodDef {
name: "from_u64", name: "from_u64",
@ -60,9 +60,9 @@ pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
true)), true)),
// #[inline] liable to cause code-bloat // #[inline] liable to cause code-bloat
attributes: attrs, attributes: attrs,
combine_substructure: combine_substructure(box |c, s, sub| { combine_substructure: combine_substructure(Box::new(|c, s, sub| {
cs_from("u64", c, s, sub) cs_from("u64", c, s, sub)
}), })),
} }
), ),
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -55,9 +55,9 @@ pub fn expand_deriving_rand<F>(cx: &mut ExtCtxt,
), ),
ret_ty: Self_, ret_ty: Self_,
attributes: Vec::new(), attributes: Vec::new(),
combine_substructure: combine_substructure(box |a, b, c| { combine_substructure: combine_substructure(Box::new(|a, b, c| {
rand_substructure(a, b, c) rand_substructure(a, b, c)
}) }))
} }
), ),
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -46,9 +46,9 @@ pub fn expand_deriving_show<F>(cx: &mut ExtCtxt,
args: vec!(fmtr), args: vec!(fmtr),
ret_ty: Literal(path_std!(cx, core::fmt::Result)), ret_ty: Literal(path_std!(cx, core::fmt::Result)),
attributes: Vec::new(), attributes: Vec::new(),
combine_substructure: combine_substructure(box |a, b, c| { combine_substructure: combine_substructure(Box::new(|a, b, c| {
show_substructure(a, b, c) show_substructure(a, b, c)
}) }))
} }
], ],
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -479,7 +479,7 @@ pub fn parse(sess: &ParseSess,
} }
rdr.next_token(); rdr.next_token();
} else /* bb_eis.len() == 1 */ { } else /* bb_eis.len() == 1 */ {
let mut rust_parser = Parser::new(sess, cfg.clone(), box rdr.clone()); let mut rust_parser = Parser::new(sess, cfg.clone(), Box::new(rdr.clone()));
let mut ei = bb_eis.pop().unwrap(); let mut ei = bb_eis.pop().unwrap();
match ei.top_elts.get_tt(ei.idx) { match ei.top_elts.get_tt(ei.idx) {

View file

@ -180,7 +180,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
Some(named_matches), Some(named_matches),
imported_from, imported_from,
rhs); rhs);
let mut p = Parser::new(cx.parse_sess(), cx.cfg(), box trncbr); let mut p = Parser::new(cx.parse_sess(), cx.cfg(), Box::new(trncbr));
p.check_unknown_macro_variable(); p.check_unknown_macro_variable();
// Let the context choose how to interpret the result. // Let the context choose how to interpret the result.
// Weird, but useful for X-macros. // Weird, but useful for X-macros.
@ -267,7 +267,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
_ => cx.span_bug(def.span, "wrong-structured rhs") _ => cx.span_bug(def.span, "wrong-structured rhs")
}; };
let exp = box MacroRulesMacroExpander { let exp: Box<_> = box MacroRulesMacroExpander {
name: def.ident, name: def.ident,
imported_from: def.imported_from, imported_from: def.imported_from,
lhses: lhses, lhses: lhses,

View file

@ -30,7 +30,7 @@ impl<T:fmt::Debug> fmt::Debug for OwnedSlice<T> {
impl<T> OwnedSlice<T> { impl<T> OwnedSlice<T> {
pub fn empty() -> OwnedSlice<T> { pub fn empty() -> OwnedSlice<T> {
OwnedSlice { data: box [] } OwnedSlice { data: Box::new([]) }
} }
#[inline(never)] #[inline(never)]

View file

@ -1484,8 +1484,9 @@ mod test {
use std::old_io::util; use std::old_io::util;
fn mk_sh() -> diagnostic::SpanHandler { fn mk_sh() -> diagnostic::SpanHandler {
let emitter = diagnostic::EmitterWriter::new(box util::NullWriter, None); // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let handler = diagnostic::mk_handler(true, box emitter); let emitter = diagnostic::EmitterWriter::new(Box::new(util::NullWriter), None);
let handler = diagnostic::mk_handler(true, Box::new(emitter));
diagnostic::mk_span_handler(handler, CodeMap::new()) diagnostic::mk_span_handler(handler, CodeMap::new())
} }

View file

@ -36,10 +36,12 @@ pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("identity", expand_identity); reg.register_macro("identity", expand_identity);
reg.register_syntax_extension( reg.register_syntax_extension(
token::intern("into_foo"), token::intern("into_foo"),
Modifier(box expand_into_foo)); // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
Modifier(Box::new(expand_into_foo)));
reg.register_syntax_extension( reg.register_syntax_extension(
token::intern("into_multi_foo"), token::intern("into_multi_foo"),
MultiModifier(box expand_into_foo_multi)); // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
MultiModifier(Box::new(expand_into_foo_multi)));
} }
fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])

View file

@ -46,5 +46,6 @@ impl TTMacroExpander for Expander {
pub fn plugin_registrar(reg: &mut Registry) { pub fn plugin_registrar(reg: &mut Registry) {
let args = reg.args().clone(); let args = reg.args().clone();
reg.register_syntax_extension(token::intern("plugin_args"), reg.register_syntax_extension(token::intern("plugin_args"),
NormalTT(box Expander { args: args, }, None)); // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
NormalTT(Box::new(Expander { args: args, }), None));
} }

View file

@ -16,9 +16,10 @@ extern crate collections;
use std::collections::HashMap; use std::collections::HashMap;
fn main() { fn main() {
let tmp; let tmp: Box<_>;
let mut buggy_map: HashMap<usize, &usize> = HashMap::new(); let mut buggy_map: HashMap<usize, &usize> = HashMap::new();
buggy_map.insert(42, &*box 1); //~ ERROR borrowed value does not live long enough // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
buggy_map.insert(42, &*Box::new(1)); //~ ERROR borrowed value does not live long enough
// but it is ok if we use a temporary // but it is ok if we use a temporary
tmp = box 2; tmp = box 2;

View file

@ -11,7 +11,6 @@
// Ensure that invoking a closure counts as a unique immutable borrow // Ensure that invoking a closure counts as a unique immutable borrow
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
#![feature(box_syntax)]
type Fn<'a> = Box<FnMut() + 'a>; type Fn<'a> = Box<FnMut() + 'a>;
@ -19,11 +18,12 @@ struct Test<'a> {
f: Box<FnMut() + 'a> f: Box<FnMut() + 'a>
} }
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
fn call<F>(mut f: F) where F: FnMut(Fn) { fn call<F>(mut f: F) where F: FnMut(Fn) {
f(box || { f(Box::new(|| {
//~^ ERROR: cannot borrow `f` as mutable more than once //~^ ERROR: cannot borrow `f` as mutable more than once
f(box || {}) f((Box::new(|| {})))
}); }));
} }
fn test1() { fn test1() {
@ -58,11 +58,12 @@ fn test6() {
fn test7() { fn test7() {
fn foo<F>(_: F) where F: FnMut(Box<FnMut(isize)>, isize) {} fn foo<F>(_: F) where F: FnMut(Box<FnMut(isize)>, isize) {}
let mut f = |g: Box<FnMut(isize)>, b: isize| {}; let mut f = |g: Box<FnMut(isize)>, b: isize| {};
f(box |a| { // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
f(Box::new(|a| {
foo(f); foo(f);
//~^ ERROR cannot move `f` into closure because it is borrowed //~^ ERROR cannot move `f` into closure because it is borrowed
//~| ERROR cannot move out of captured outer variable in an `FnMut` closure //~| ERROR cannot move out of captured outer variable in an `FnMut` closure
}, 3); }), 3);
} }
fn main() {} fn main() {}

View file

@ -11,14 +11,13 @@
// Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is // Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is
// forbidden when `T` is a trait. // forbidden when `T` is a trait.
#![feature(box_syntax)]
struct Foo; struct Foo;
trait Trait { fn foo(&self) {} } trait Trait { fn foo(&self) {} }
impl Trait for Foo {} impl Trait for Foo {}
pub fn main() { pub fn main() {
let x: Box<Trait> = box Foo; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let x: Box<Trait> = Box::new(Foo);
let _y: &Trait = x; //~ ERROR mismatched types let _y: &Trait = x; //~ ERROR mismatched types
//~| expected `&Trait` //~| expected `&Trait`
//~| found `Box<Trait>` //~| found `Box<Trait>`

View file

@ -10,8 +10,6 @@
// Forbid assignment into a dynamically sized type. // Forbid assignment into a dynamically sized type.
#![feature(box_syntax)]
struct Fat<T: ?Sized> { struct Fat<T: ?Sized> {
f1: isize, f1: isize,
f2: &'static str, f2: &'static str,
@ -43,7 +41,8 @@ impl ToBar for Bar1 {
pub fn main() { pub fn main() {
// Assignment. // Assignment.
let f5: &mut Fat<ToBar> = &mut Fat { f1: 5, f2: "some str", ptr: Bar1 {f :42} }; let f5: &mut Fat<ToBar> = &mut Fat { f1: 5, f2: "some str", ptr: Bar1 {f :42} };
let z: Box<ToBar> = box Bar1 {f: 36}; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let z: Box<ToBar> = Box::new(Bar1 {f: 36});
f5.ptr = *z; f5.ptr = *z;
//~^ ERROR the trait `core::marker::Sized` is not implemented //~^ ERROR the trait `core::marker::Sized` is not implemented
} }

View file

@ -10,8 +10,6 @@
// Forbid assignment into a dynamically sized type. // Forbid assignment into a dynamically sized type.
#![feature(box_syntax)]
struct Fat<T: ?Sized> { struct Fat<T: ?Sized> {
f1: isize, f1: isize,
f2: &'static str, f2: &'static str,
@ -43,7 +41,8 @@ impl ToBar for Bar1 {
pub fn main() { pub fn main() {
// Assignment. // Assignment.
let f5: &mut Fat<ToBar> = &mut Fat { f1: 5, f2: "some str", ptr: Bar1 {f :42} }; let f5: &mut Fat<ToBar> = &mut Fat { f1: 5, f2: "some str", ptr: Bar1 {f :42} };
let z: Box<ToBar> = box Bar1 {f: 36}; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let z: Box<ToBar> = Box::new(Bar1 {f: 36});
f5.ptr = Bar1 {f: 36}; f5.ptr = Bar1 {f: 36};
//~^ ERROR mismatched types //~^ ERROR mismatched types
//~| expected `ToBar` //~| expected `ToBar`

View file

@ -8,13 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
fn test<'x>(x: &'x isize) { fn test<'x>(x: &'x isize) {
drop::<Box<for<'z> FnMut(&'z isize) -> &'z isize>>(box |z| { // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
drop::<Box<for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {
x x
//~^ ERROR cannot infer an appropriate lifetime //~^ ERROR cannot infer an appropriate lifetime
}); }));
} }
fn main() {} fn main() {}

View file

@ -15,6 +15,7 @@ struct Test {
} }
fn main() { fn main() {
let closure: Box<Fn()+'static> = box || (); // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let closure: Box<Fn()+'static> = Box::new(|| ());
let test = box Test { func: closure }; //~ ERROR mismatched types let test = box Test { func: closure }; //~ ERROR mismatched types
} }

View file

@ -8,18 +8,20 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
fn main() { fn main() {
let _foo = &[1_usize, 2] as [usize]; let _foo = &[1_usize, 2] as [usize];
//~^ ERROR cast to unsized type: `&[usize; 2]` as `[usize]` //~^ ERROR cast to unsized type: `&[usize; 2]` as `[usize]`
//~^^ HELP consider using an implicit coercion to `&[usize]` instead //~^^ HELP consider using an implicit coercion to `&[usize]` instead
let _bar = box 1_usize as std::fmt::Debug;
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let _bar = Box::new(1_usize) as std::fmt::Debug;
//~^ ERROR cast to unsized type: `Box<usize>` as `core::fmt::Debug` //~^ ERROR cast to unsized type: `Box<usize>` as `core::fmt::Debug`
//~^^ HELP did you mean `Box<core::fmt::Debug>`? //~^^ HELP did you mean `Box<core::fmt::Debug>`?
let _baz = 1_usize as std::fmt::Debug; let _baz = 1_usize as std::fmt::Debug;
//~^ ERROR cast to unsized type: `usize` as `core::fmt::Debug` //~^ ERROR cast to unsized type: `usize` as `core::fmt::Debug`
//~^^ HELP consider using a box or reference as appropriate //~^^ HELP consider using a box or reference as appropriate
let _quux = [1_usize, 2] as [usize]; let _quux = [1_usize, 2] as [usize];
//~^ ERROR cast to unsized type: `[usize; 2]` as `[usize]` //~^ ERROR cast to unsized type: `[usize; 2]` as `[usize]`
//~^^ HELP consider using a box or reference as appropriate //~^^ HELP consider using a box or reference as appropriate

View file

@ -11,10 +11,8 @@
// Test that moves of unsized values within closures are caught // Test that moves of unsized values within closures are caught
// and rejected. // and rejected.
#![feature(box_syntax)]
fn main() { fn main() {
(|| box *[0_usize].as_slice())(); // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
//~^ ERROR cannot move out of borrowed content (|| Box::new(*[0_usize].as_slice()))();
//~^^ ERROR cannot move a value of type [usize] //~^ ERROR the trait `core::marker::Sized` is not implemented for the type `[usize]`
} }

View file

@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
use std::cell::RefCell; use std::cell::RefCell;
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
fn main() { fn main() {
let mut y = 1_usize; let mut y = 1_usize;
let c = RefCell::new(vec![]); let c = RefCell::new(vec![]);
c.push(box || y = 0); c.push(Box::new(|| y = 0));
c.push(box || y = 0); c.push(Box::new(|| y = 0));
//~^ ERROR cannot borrow `y` as mutable more than once at a time //~^ ERROR cannot borrow `y` as mutable more than once at a time
} }
@ -24,8 +24,8 @@ fn ufcs() {
let mut y = 1_usize; let mut y = 1_usize;
let c = RefCell::new(vec![]); let c = RefCell::new(vec![]);
Push::push(&c, box || y = 0); Push::push(&c, Box::new(|| y = 0));
Push::push(&c, box || y = 0); Push::push(&c, Box::new(|| y = 0));
//~^ ERROR cannot borrow `y` as mutable more than once at a time //~^ ERROR cannot borrow `y` as mutable more than once at a time
} }

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
mod my_mod { mod my_mod {
pub struct MyStruct { pub struct MyStruct {
priv_field: isize priv_field: isize
@ -26,10 +24,15 @@ fn main() {
let my_struct = my_mod::MyStruct(); let my_struct = my_mod::MyStruct();
let _woohoo = (&my_struct).priv_field; let _woohoo = (&my_struct).priv_field;
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private //~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private
let _woohoo = (box my_struct).priv_field;
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let _woohoo = (Box::new(my_struct)).priv_field;
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private //~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private
(&my_struct).happyfun(); //~ ERROR method `happyfun` is private (&my_struct).happyfun(); //~ ERROR method `happyfun` is private
(box my_struct).happyfun(); //~ ERROR method `happyfun` is private
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
(Box::new(my_struct)).happyfun(); //~ ERROR method `happyfun` is private
let nope = my_struct.priv_field; let nope = my_struct.priv_field;
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private //~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private
} }

View file

@ -9,12 +9,12 @@
// except according to those terms. // except according to those terms.
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
#![feature(box_syntax)]
fn id<T>(t: T) -> T { t } fn id<T>(t: T) -> T { t }
fn f<'r, T>(v: &'r T) -> Box<FnMut() -> T + 'r> { fn f<'r, T>(v: &'r T) -> Box<FnMut() -> T + 'r> {
id(box || *v) // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
id(Box::new(|| *v))
//~^ ERROR `v` does not live long enough //~^ ERROR `v` does not live long enough
//~| ERROR cannot move out of borrowed content //~| ERROR cannot move out of borrowed content
} }

View file

@ -8,13 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
trait Foo { fn foo(&self) {} } trait Foo { fn foo(&self) {} }
impl Foo for u8 {} impl Foo for u8 {}
fn main() { fn main() {
let r: Box<Foo> = box 5; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let r: Box<Foo> = Box::new(5);
let _m: Box<Foo> = r as Box<Foo>; let _m: Box<Foo> = r as Box<Foo>;
//~^ ERROR `core::marker::Sized` is not implemented for the type `Foo` //~^ ERROR `core::marker::Sized` is not implemented for the type `Foo`
} }

View file

@ -26,6 +26,7 @@ impl<K, V> Map<K, V> for HashMap<K, V> {}
fn main() { fn main() {
let x: Box<HashMap<isize, isize>> = box HashMap::new(); let x: Box<HashMap<isize, isize>> = box HashMap::new();
let x: Box<Map<isize, isize>> = x; let x: Box<Map<isize, isize>> = x;
let y: Box<Map<usize, isize>> = box x; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let y: Box<Map<usize, isize>> = Box::new(x);
//~^ ERROR the trait `Map<usize, isize>` is not implemented //~^ ERROR the trait `Map<usize, isize>` is not implemented
} }

View file

@ -12,7 +12,6 @@
// bound must be noncopyable. For details see // bound must be noncopyable. For details see
// http://smallcultfollowing.com/babysteps/blog/2013/04/30/the-case-of-the-recurring-closure/ // http://smallcultfollowing.com/babysteps/blog/2013/04/30/the-case-of-the-recurring-closure/
#![feature(box_syntax)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
struct R<'a> { struct R<'a> {
@ -41,7 +40,8 @@ fn innocent_looking_victim() {
} }
fn conspirator<F>(mut f: F) where F: FnMut(&mut R, bool) { fn conspirator<F>(mut f: F) where F: FnMut(&mut R, bool) {
let mut r = R {c: box f}; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let mut r = R {c: Box::new(f)};
f(&mut r, false) //~ ERROR use of moved value f(&mut r, false) //~ ERROR use of moved value
} }

View file

@ -11,32 +11,36 @@
// Test that attempts to implicitly coerce a value into an // Test that attempts to implicitly coerce a value into an
// object respect the lifetime bound on the object type. // object respect the lifetime bound on the object type.
#![feature(box_syntax)]
trait Foo : ::std::marker::MarkerTrait {} trait Foo : ::std::marker::MarkerTrait {}
impl<'a> Foo for &'a [u8] {} impl<'a> Foo for &'a [u8] {}
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
fn a(v: &[u8]) -> Box<Foo + 'static> { fn a(v: &[u8]) -> Box<Foo + 'static> {
let x: Box<Foo + 'static> = box v; //~ ERROR does not fulfill the required lifetime let x: Box<Foo + 'static> = Box::new(v);
//~^ ERROR cannot infer an appropriate lifetime due to conflicting
x x
} }
fn b(v: &[u8]) -> Box<Foo + 'static> { fn b(v: &[u8]) -> Box<Foo + 'static> {
box v //~ ERROR does not fulfill the required lifetime Box::new(v)
//~^ ERROR cannot infer an appropriate lifetime due to conflicting
} }
fn c(v: &[u8]) -> Box<Foo> { fn c(v: &[u8]) -> Box<Foo> {
// same as previous case due to RFC 599 // same as previous case due to RFC 599
box v //~ ERROR does not fulfill the required lifetime Box::new(v)
//~^ ERROR cannot infer an appropriate lifetime due to conflicting
} }
fn d<'a,'b>(v: &'a [u8]) -> Box<Foo+'b> { fn d<'a,'b>(v: &'a [u8]) -> Box<Foo+'b> {
box v //~ ERROR does not fulfill the required lifetime Box::new(v)
//~^ ERROR cannot infer an appropriate lifetime due to conflicting
} }
fn e<'a:'b,'b>(v: &'a [u8]) -> Box<Foo+'b> { fn e<'a:'b,'b>(v: &'a [u8]) -> Box<Foo+'b> {
box v // OK, thanks to 'a:'b Box::new(v) // OK, thanks to 'a:'b
} }
fn main() { } fn main() { }

View file

@ -10,6 +10,8 @@
#![feature(box_syntax)] #![feature(box_syntax)]
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
use std::marker::MarkerTrait; use std::marker::MarkerTrait;
trait X : MarkerTrait {} trait X : MarkerTrait {}
@ -24,48 +26,48 @@ trait Iter {
fn bad1<T: Iter>(v: T) -> Box<X+'static> fn bad1<T: Iter>(v: T) -> Box<X+'static>
{ {
let item = v.into_item(); let item = v.into_item();
box item //~ ERROR associated type `<T as Iter>::Item` may not live long enough Box::new(item) //~ ERROR associated type `<T as Iter>::Item` may not live long enough
} }
fn bad2<T: Iter>(v: T) -> Box<X+'static> fn bad2<T: Iter>(v: T) -> Box<X+'static>
where Box<T::Item> : X where Box<T::Item> : X
{ {
let item = box v.into_item(); let item: Box<_> = box v.into_item();
box item //~ ERROR associated type `<T as Iter>::Item` may not live long enough Box::new(item) //~ ERROR associated type `<T as Iter>::Item` may not live long enough
} }
fn bad3<'a, T: Iter>(v: T) -> Box<X+'a> fn bad3<'a, T: Iter>(v: T) -> Box<X+'a>
{ {
let item = v.into_item(); let item = v.into_item();
box item //~ ERROR associated type `<T as Iter>::Item` may not live long enough Box::new(item) //~ ERROR associated type `<T as Iter>::Item` may not live long enough
} }
fn bad4<'a, T: Iter>(v: T) -> Box<X+'a> fn bad4<'a, T: Iter>(v: T) -> Box<X+'a>
where Box<T::Item> : X where Box<T::Item> : X
{ {
let item = box v.into_item(); let item: Box<_> = box v.into_item();
box item //~ ERROR associated type `<T as Iter>::Item` may not live long enough Box::new(item) //~ ERROR associated type `<T as Iter>::Item` may not live long enough
} }
fn ok1<'a, T: Iter>(v: T) -> Box<X+'a> fn ok1<'a, T: Iter>(v: T) -> Box<X+'a>
where T::Item : 'a where T::Item : 'a
{ {
let item = v.into_item(); let item = v.into_item();
box item // OK, T::Item : 'a is declared Box::new(item) // OK, T::Item : 'a is declared
} }
fn ok2<'a, T: Iter>(v: &T, w: &'a T::Item) -> Box<X+'a> fn ok2<'a, T: Iter>(v: &T, w: &'a T::Item) -> Box<X+'a>
where T::Item : Clone where T::Item : Clone
{ {
let item = Clone::clone(w); let item = Clone::clone(w);
box item // OK, T::Item : 'a is implied Box::new(item) // OK, T::Item : 'a is implied
} }
fn ok3<'a, T: Iter>(v: &'a T) -> Box<X+'a> fn ok3<'a, T: Iter>(v: &'a T) -> Box<X+'a>
where T::Item : Clone + 'a where T::Item : Clone + 'a
{ {
let item = Clone::clone(v.as_item()); let item = Clone::clone(v.as_item());
box item // OK, T::Item : 'a was declared Box::new(item) // OK, T::Item : 'a was declared
} }
fn meh1<'a, T: Iter>(v: &'a T) -> Box<X+'a> fn meh1<'a, T: Iter>(v: &'a T) -> Box<X+'a>
@ -78,7 +80,7 @@ fn meh1<'a, T: Iter>(v: &'a T) -> Box<X+'a>
// T::Item`. But we're not that smart at present. // T::Item`. But we're not that smart at present.
let item = Clone::clone(v.as_item()); let item = Clone::clone(v.as_item());
box item //~ ERROR associated type `<T as Iter>::Item` may not live Box::new(item) //~ ERROR associated type `<T as Iter>::Item` may not live
} }
fn main() {} fn main() {}

View file

@ -8,32 +8,32 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)] // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
trait X { fn foo(&self) {} } trait X { fn foo(&self) {} }
fn p1<T>(v: T) -> Box<X+'static> fn p1<T>(v: T) -> Box<X+'static>
where T : X where T : X
{ {
box v //~ ERROR parameter type `T` may not live long enough Box::new(v) //~ ERROR parameter type `T` may not live long enough
} }
fn p2<T>(v: Box<T>) -> Box<X+'static> fn p2<T>(v: Box<T>) -> Box<X+'static>
where Box<T> : X where Box<T> : X
{ {
box v //~ ERROR parameter type `T` may not live long enough Box::new(v) //~ ERROR parameter type `T` may not live long enough
} }
fn p3<'a,T>(v: T) -> Box<X+'a> fn p3<'a,T>(v: T) -> Box<X+'a>
where T : X where T : X
{ {
box v //~ ERROR parameter type `T` may not live long enough Box::new(v) //~ ERROR parameter type `T` may not live long enough
} }
fn p4<'a,T>(v: Box<T>) -> Box<X+'a> fn p4<'a,T>(v: Box<T>) -> Box<X+'a>
where Box<T> : X where Box<T> : X
{ {
box v //~ ERROR parameter type `T` may not live long enough Box::new(v) //~ ERROR parameter type `T` may not live long enough
} }
fn main() {} fn main() {}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)] // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
fn ignore<T>(t: T) {} fn ignore<T>(t: T) {}
@ -16,17 +16,17 @@ fn nested<'x>(x: &'x isize) {
let y = 3; let y = 3;
let mut ay = &y; let mut ay = &y;
ignore::<Box<for<'z> FnMut(&'z isize)>>(box |z| { ignore::<Box<for<'z> FnMut(&'z isize)>>(Box::new(|z| {
ay = x; //~ ERROR cannot infer ay = x; //~ ERROR cannot infer
ay = &y; ay = &y;
ay = z; ay = z;
}); }));
ignore::< Box<for<'z> FnMut(&'z isize) -> &'z isize>>(box |z| { ignore::< Box<for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {
if false { return x; } //~ ERROR cannot infer an appropriate lifetime for automatic if false { return x; } //~ ERROR cannot infer an appropriate lifetime for automatic
if false { return ay; } if false { return ay; }
return z; return z;
}); }));
} }
fn main() {} fn main() {}

View file

@ -8,17 +8,17 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)] // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
fn borrowed_proc<'a>(x: &'a isize) -> Box<FnMut()->(isize) + 'a> { fn borrowed_proc<'a>(x: &'a isize) -> Box<FnMut()->(isize) + 'a> {
// This is legal, because the region bound on `proc` // This is legal, because the region bound on `proc`
// states that it captures `x`. // states that it captures `x`.
box move|| { *x } Box::new(move|| { *x })
} }
fn static_proc(x: &isize) -> Box<FnMut()->(isize) + 'static> { fn static_proc(x: &isize) -> Box<FnMut()->(isize) + 'static> {
// This is illegal, because the region bound on `proc` is 'static. // This is illegal, because the region bound on `proc` is 'static.
box move|| { *x } //~ ERROR captured variable `x` does not outlive the enclosing closure Box::new(move|| { *x }) //~ ERROR captured variable `x` does not outlive the enclosing closure
} }
fn main() { } fn main() { }

View file

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
struct closure_box<'a> { struct closure_box<'a> {
@ -22,7 +21,8 @@ fn box_it<'r>(x: Box<FnMut() + 'r>) -> closure_box<'r> {
fn main() { fn main() {
let mut cl_box = { let mut cl_box = {
let mut i = 3; let mut i = 3;
box_it(box || i += 1) //~ ERROR `i` does not live long enough // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
box_it(Box::new(|| i += 1)) //~ ERROR `i` does not live long enough
}; };
cl_box.cl.call_mut(()); cl_box.cl.call_mut(());
} }

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
struct Struct { struct Struct {
person: &'static str person: &'static str
} }
@ -25,7 +23,8 @@ impl Trait<&'static str> for Struct {
} }
fn main() { fn main() {
let s: Box<Trait<isize>> = box Struct { person: "Fred" }; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let s: Box<Trait<isize>> = Box::new(Struct { person: "Fred" });
//~^ ERROR the trait `Trait<isize>` is not implemented for the type `Struct` //~^ ERROR the trait `Trait<isize>` is not implemented for the type `Struct`
s.f(1); s.f(1);
} }

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
struct Struct { struct Struct {
person: &'static str person: &'static str
} }
@ -27,6 +25,7 @@ impl Trait<&'static str> for Struct {
fn main() { fn main() {
let person = "Fred".to_string(); let person = "Fred".to_string();
let person: &str = &person; //~ ERROR `person` does not live long enough let person: &str = &person; //~ ERROR `person` does not live long enough
let s: Box<Trait<&'static str>> = box Struct { person: person }; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let s: Box<Trait<&'static str>> = Box::new(Struct { person: person });
} }

View file

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
// Tests that we can't move out of an unboxed closure environment // Tests that we can't move out of an unboxed closure environment
@ -19,31 +18,33 @@ fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
fn to_fn_mut<A,F:FnMut<A>>(f: F) -> F { f } fn to_fn_mut<A,F:FnMut<A>>(f: F) -> F { f }
fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f } fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
fn main() { fn main() {
// By-ref cases // By-ref cases
{ {
let x = box 0_usize; let x = Box::new(0_usize);
let f = to_fn(|| drop(x)); //~ ERROR cannot move let f = to_fn(|| drop(x)); //~ ERROR cannot move
} }
{ {
let x = box 0_usize; let x = Box::new(0_usize);
let f = to_fn_mut(|| drop(x)); //~ ERROR cannot move let f = to_fn_mut(|| drop(x)); //~ ERROR cannot move
} }
{ {
let x = box 0_usize; let x = Box::new(0_usize);
let f = to_fn_once(|| drop(x)); // OK -- FnOnce let f = to_fn_once(|| drop(x)); // OK -- FnOnce
} }
// By-value cases // By-value cases
{ {
let x = box 0_usize; let x = Box::new(0_usize);
let f = to_fn(move || drop(x)); //~ ERROR cannot move let f = to_fn(move || drop(x)); //~ ERROR cannot move
} }
{ {
let x = box 0_usize; let x = Box::new(0_usize);
let f = to_fn_mut(move || drop(x)); //~ ERROR cannot move let f = to_fn_mut(move || drop(x)); //~ ERROR cannot move
} }
{ {
let x = box 0_usize; let x = Box::new(0_usize);
let f = to_fn_once(move || drop(x)); // this one is ok let f = to_fn_once(move || drop(x)); // this one is ok
} }
} }

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
#[derive(Debug)] #[derive(Debug)]
struct r { struct r {
b: bool, b: bool,
@ -20,7 +18,8 @@ impl Drop for r {
} }
fn main() { fn main() {
let i = box r { b: true }; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let i = Box::new(r { b: true });
let _j = i.clone(); //~ ERROR not implement let _j = i.clone(); //~ ERROR not implement
println!("{:?}", i); println!("{:?}", i);
} }

View file

@ -8,15 +8,14 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
use std::rc::Rc; use std::rc::Rc;
fn f<T:Send>(__isize: T) { fn f<T:Send>(__isize: T) {
} }
fn main() { fn main() {
let i = box Rc::new(100); // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let i = Box::new(Rc::new(100));
f(i); f(i);
//~^ ERROR `core::marker::Send` is not implemented //~^ ERROR `core::marker::Send` is not implemented
} }

View file

@ -10,8 +10,6 @@
#![feature(unsafe_destructor)] #![feature(unsafe_destructor)]
#![feature(box_syntax)]
use std::cell::Cell; use std::cell::Cell;
#[derive(Debug)] #[derive(Debug)]
@ -36,8 +34,9 @@ fn clone<T: Clone>(t: &T) -> T { t.clone() }
fn main() { fn main() {
let i1 = &Cell::new(0); let i1 = &Cell::new(0);
let i2 = &Cell::new(1); let i2 = &Cell::new(1);
let r1 = vec!(box r { i: i1 }); // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let r2 = vec!(box r { i: i2 }); let r1 = vec!(Box::new(r { i: i1 }));
let r2 = vec!(Box::new(r { i: i2 }));
f(clone(&r1), clone(&r2)); f(clone(&r1), clone(&r2));
//~^ ERROR the trait `core::clone::Clone` is not implemented for the type //~^ ERROR the trait `core::clone::Clone` is not implemented for the type
//~^^ ERROR the trait `core::clone::Clone` is not implemented for the type //~^^ ERROR the trait `core::clone::Clone` is not implemented for the type

View file

@ -60,7 +60,7 @@ fn some_generic_fun<T1, T2>(a: T1, b: T2) -> (T2, T1) {
fn main() { fn main() {
some_generic_fun(0.5f64, 10); some_generic_fun(0.5f64, 10);
some_generic_fun(&29, box 110); some_generic_fun(&29, Box::new(110));
} }
fn zzz() { () } fn zzz() { () }

View file

@ -10,9 +10,6 @@
// error-pattern:panicked at 'Box<Any>' // error-pattern:panicked at 'Box<Any>'
#![allow(unknown_features)]
#![feature(box_syntax)]
fn main() { fn main() {
panic!(box 612_i64); panic!(Box::new(612_i64));
} }

View file

@ -10,7 +10,4 @@
// error-pattern: panic // error-pattern: panic
#![allow(unknown_features)] fn main() { Box::new(panic!()); }
#![feature(box_syntax)]
fn main() { box panic!(); }

View file

@ -10,14 +10,11 @@
// error-pattern:fail // error-pattern:fail
#![allow(unknown_features)]
#![feature(box_syntax)]
fn failfn() { fn failfn() {
panic!(); panic!();
} }
fn main() { fn main() {
box 0; Box::new(0);
failfn(); failfn();
} }

View file

@ -245,9 +245,10 @@ fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
let x = 32.0f32; let x = 32.0f32;
let _ = (x + ((x * x) + 1.0).sqrt()).ln(); let _ = (x + ((x * x) + 1.0).sqrt()).ln();
let s: Box<SomeTrait> = box some_fields {field1: 43}; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let s: Box<SomeTrait> = Box::new(some_fields {field1: 43});
let s2: Box<some_fields> = box some_fields {field1: 43}; let s2: Box<some_fields> = box some_fields {field1: 43};
let s3 = box nofields; let s3: Box<_> = box nofields;
s.Method(43); s.Method(43);
s3.Method(43); s3.Method(43);
@ -282,7 +283,7 @@ pub struct blah {
} }
fn main() { // foo fn main() { // foo
let s = box some_fields {field1: 43}; let s: Box<_> = box some_fields {field1: 43};
hello((43, "a".to_string()), *s); hello((43, "a".to_string()), *s);
sub::sub2::hello(); sub::sub2::hello();
sub2::sub3::hello(); sub2::sub3::hello();

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
static mut DROP_RAN: bool = false; static mut DROP_RAN: bool = false;
struct Foo; struct Foo;
@ -28,7 +26,8 @@ struct Fat<T: ?Sized> {
pub fn main() { pub fn main() {
{ {
let _x: Box<Fat<Trait>> = box Fat { f: Foo }; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let _x: Box<Fat<Trait>> = Box::<Fat<Foo>>::new(Fat { f: Foo });
} }
unsafe { unsafe {
assert!(DROP_RAN); assert!(DROP_RAN);

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
static mut DROP_RAN: int = 0; static mut DROP_RAN: int = 0;
struct Foo; struct Foo;
@ -25,7 +23,8 @@ struct Fat<T: ?Sized> {
pub fn main() { pub fn main() {
{ {
let _x: Box<Fat<[Foo]>> = box Fat { f: [Foo, Foo, Foo] }; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let _x: Box<Fat<[Foo]>> = Box::<Fat<[Foo; 3]>>::new(Fat { f: [Foo, Foo, Foo] });
} }
unsafe { unsafe {
assert!(DROP_RAN == 3); assert!(DROP_RAN == 3);

View file

@ -8,15 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
struct Point { x : int } struct Point { x : int }
pub fn main() { pub fn main() {
assert_eq!(14,14); assert_eq!(14,14);
assert_eq!("abc".to_string(),"abc".to_string()); assert_eq!("abc".to_string(),"abc".to_string());
assert_eq!(box Point{x:34},box Point{x:34}); assert_eq!(Box::new(Point{x:34}),Box::new(Point{x:34}));
assert_eq!(&Point{x:34},&Point{x:34}); assert_eq!(&Point{x:34},&Point{x:34});
} }

View file

@ -25,6 +25,7 @@ fn pairwise_sub(mut t: Box<DoubleEndedIterator<Item=int>>) -> int {
fn main() { fn main() {
let v = vec!(1, 2, 3, 4, 5, 6); let v = vec!(1, 2, 3, 4, 5, 6);
let r = pairwise_sub(box v.into_iter()); // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let r = pairwise_sub(Box::new(v.into_iter()));
assert_eq!(r, 9); assert_eq!(r, 9);
} }

View file

@ -17,12 +17,21 @@ use std::fmt::Debug;
// rvalue expressions to be unsized. See #20169 for more information. // rvalue expressions to be unsized. See #20169 for more information.
pub fn main() { pub fn main() {
let _: Box<[int]> = box { [1, 2, 3] }; // FIXME #22405: We cannot infer the type `Box<[int; k]>` for
let _: Box<[int]> = box if true { [1, 2, 3] } else { [1, 3, 4] }; // the r-value expression from the context `Box<[int]>`, and
let _: Box<[int]> = box match true { true => [1, 2, 3], false => [1, 3, 4] }; // therefore the `box EXPR` desugaring breaks down.
let _: Box<Fn(int) -> _> = box { |x| (x as u8) }; //
let _: Box<Debug> = box if true { false } else { true }; // One could reasonably claim that the `box EXPR` desugaring is
let _: Box<Debug> = box match true { true => 'a', false => 'b' }; // effectively regressing half of Issue #20169. Hopefully we will
// eventually fix that, at which point the `Box::new` calls below
// should be replaced wth uses of `box`.
let _: Box<[int]> = Box::new({ [1, 2, 3] });
let _: Box<[int]> = Box::new(if true { [1, 2, 3] } else { [1, 3, 4] });
let _: Box<[int]> = Box::new(match true { true => [1, 2, 3], false => [1, 3, 4] });
let _: Box<Fn(int) -> _> = Box::new({ |x| (x as u8) });
let _: Box<Debug> = Box::new(if true { false } else { true });
let _: Box<Debug> = Box::new(match true { true => 'a', false => 'b' });
let _: &[int] = &{ [1, 2, 3] }; let _: &[int] = &{ [1, 2, 3] };
let _: &[int] = &if true { [1, 2, 3] } else { [1, 3, 4] }; let _: &[int] = &if true { [1, 2, 3] } else { [1, 3, 4] };
@ -36,6 +45,6 @@ pub fn main() {
let _: Vec<Box<Fn(int) -> _>> = vec![ let _: Vec<Box<Fn(int) -> _>> = vec![
Box::new(|x| (x as u8)), Box::new(|x| (x as u8)),
box |x| (x as i16 as u8), Box::new(|x| (x as i16 as u8)),
]; ];
} }

View file

@ -11,9 +11,6 @@
// Make sure const bounds work on things, and test that a few types // Make sure const bounds work on things, and test that a few types
// are const. // are const.
#![allow(unknown_features)]
#![feature(box_syntax)]
fn foo<T: Sync>(x: T) -> T { x } fn foo<T: Sync>(x: T) -> T { x }
struct F { field: int } struct F { field: int }
@ -25,5 +22,5 @@ pub fn main() {
foo(F{field: 42}); foo(F{field: 42});
foo((1, 2_usize)); foo((1, 2_usize));
foo(@1);*/ foo(@1);*/
foo(box 1); foo(Box::new(1));
} }

View file

@ -20,6 +20,7 @@ struct A {
pub fn main() { pub fn main() {
let a: A = Default::default(); let a: A = Default::default();
let b: Box<[_]> = box []; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let b: Box<[_]> = Box::<[bool; 0]>::new([]);
assert_eq!(a.foo, b); assert_eq!(a.foo, b);
} }

View file

@ -23,7 +23,8 @@ struct A {
} }
fn main() { fn main() {
let obj = A { foo: box [true, false] }; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let obj = A { foo: Box::new([true, false]) };
let s = json::encode(&obj).unwrap(); let s = json::encode(&obj).unwrap();
let obj2: A = json::decode(&s).unwrap(); let obj2: A = json::decode(&s).unwrap();
assert!(obj.foo == obj2.foo); assert!(obj.foo == obj2.foo);

View file

@ -8,15 +8,13 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
#[derive(PartialEq, PartialOrd, Eq, Ord)] #[derive(PartialEq, PartialOrd, Eq, Ord)]
struct Foo(Box<[u8]>); struct Foo(Box<[u8]>);
pub fn main() { pub fn main() {
let a = Foo(box [0, 1, 2]); // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let b = Foo(box [0, 1, 2]); let a = Foo(Box::new([0, 1, 2]));
let b = Foo(Box::new([0, 1, 2]));
assert!(a == b); assert!(a == b);
println!("{}", a != b); println!("{}", a != b);
println!("{}", a < b); println!("{}", a < b);

View file

@ -10,9 +10,6 @@
// Test that a custom deref with a fat pointer return type does not ICE // Test that a custom deref with a fat pointer return type does not ICE
#![allow(unknown_features)]
#![feature(box_syntax)]
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
pub struct Arr { pub struct Arr {
@ -41,6 +38,7 @@ pub fn foo(arr: &mut Arr) {
} }
fn main() { fn main() {
let mut a = Arr { ptr: box [1, 2, 3] }; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let mut a = Arr { ptr: Box::new([1, 2, 3]) };
foo(&mut a); foo(&mut a);
} }

View file

@ -10,9 +10,6 @@
// Test that a custom deref with a fat pointer return type does not ICE // Test that a custom deref with a fat pointer return type does not ICE
#![allow(unknown_features)]
#![feature(box_syntax)]
use std::ops::Deref; use std::ops::Deref;
pub struct Arr { pub struct Arr {
@ -36,6 +33,7 @@ pub fn foo(arr: &Arr) {
} }
fn main() { fn main() {
let a = Arr { ptr: box [1, 2, 3] }; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let a = Arr { ptr: Box::new([1, 2, 3]) };
foo(&a); foo(&a);
} }

View file

@ -115,7 +115,7 @@ pub fn main() {
foo3(f5); foo3(f5);
// Box. // Box.
let f1 = box [1, 2, 3]; let f1 = Box::new([1, 2, 3]);
assert!((*f1)[1] == 2); assert!((*f1)[1] == 2);
let f2: Box<[int]> = f1; let f2: Box<[int]> = f1;
assert!((*f2)[1] == 2); assert!((*f2)[1] == 2);
@ -125,6 +125,9 @@ pub fn main() {
foo(&*f1); foo(&*f1);
let f2 : Box<Fat<[int]>> = f1; let f2 : Box<Fat<[int]>> = f1;
foo(&*f2); foo(&*f2);
let f3 : Box<Fat<[int]>> = box Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] };
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let f3 : Box<Fat<[int]>> =
Box::<Fat<[_; 3]>>::new(Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] });
foo(&*f3); foo(&*f3);
} }

View file

@ -95,7 +95,9 @@ pub fn main() {
assert!(f6.ptr.to_bar() == Bar); assert!(f6.ptr.to_bar() == Bar);
// &* // &*
let f7: Box<ToBar> = box Bar1 {f :42}; //
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let f7: Box<ToBar> = Box::new(Bar1 {f :42});
bar(&*f7); bar(&*f7);
// Deep nesting // Deep nesting

View file

@ -8,18 +8,17 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(unknown_features)] // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
#![feature(box_syntax)]
pub fn main() { pub fn main() {
assert!(Some(box() ()).is_some()); assert!(Some(Box::new(())).is_some());
let xs: Box<[()]> = box []; let xs: Box<[()]> = Box::<[(); 0]>::new([]);
assert!(Some(xs).is_some()); assert!(Some(xs).is_some());
struct Foo; struct Foo;
assert!(Some(box Foo).is_some()); assert!(Some(Box::new(Foo)).is_some());
let ys: Box<[Foo]> = box []; let ys: Box<[Foo]> = Box::<[Foo; 0]>::new([]);
assert!(Some(ys).is_some()); assert!(Some(ys).is_some());
} }

View file

@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
pub fn main() { pub fn main() {
let x = *box() (); let x = *Box::new(());
} }

View file

@ -9,7 +9,6 @@
// except according to those terms. // except according to those terms.
#![allow(unknown_features)] #![allow(unknown_features)]
#![feature(box_syntax)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
/** /**
@ -61,7 +60,8 @@ mod map_reduce {
} }
let ctrl_clone = ctrl.clone(); let ctrl_clone = ctrl.clone();
::map(input, box |a,b| emit(&mut intermediates, ctrl.clone(), a, b) ); // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
::map(input, Box::new(|a,b| emit(&mut intermediates, ctrl.clone(), a, b)));
ctrl_clone.send(ctrl_proto::mapper_done).unwrap(); ctrl_clone.send(ctrl_proto::mapper_done).unwrap();
} }

View file

@ -9,7 +9,6 @@
// except according to those terms. // except according to those terms.
#![allow(unknown_features)] #![allow(unknown_features)]
#![feature(box_syntax)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
// Test that `Fn(int) -> int + 'static` parses as `(Fn(int) -> int) + // Test that `Fn(int) -> int + 'static` parses as `(Fn(int) -> int) +
@ -17,7 +16,8 @@
// cause a compilation error. Issue #18772. // cause a compilation error. Issue #18772.
fn adder(y: int) -> Box<Fn(int) -> int + 'static> { fn adder(y: int) -> Box<Fn(int) -> int + 'static> {
box move |x| y + x // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
Box::new(move |x| y + x)
} }
fn main() {} fn main() {}

View file

@ -9,8 +9,8 @@
// except according to those terms. // except according to those terms.
#![allow(dead_code)] #![allow(dead_code)]
#![allow(unknown_features)]
#![feature(box_syntax)] // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
trait Foo { fn dummy(&self) { } } trait Foo { fn dummy(&self) { } }
impl Foo for int {} impl Foo for int {}
@ -39,16 +39,16 @@ fn main() {
let r = &1; let r = &1;
foog(x, &[r]); foog(x, &[r]);
let x: [Box<Foo>; 2] = [box 1, box 2]; let x: [Box<Foo>; 2] = [Box::new(1), Box::new(2)];
bar(x); bar(x);
bar([box 1, box 2]); bar([Box::new(1), Box::new(2)]);
let x: &[Box<Foo>] = &[box 1, box 2]; let x: &[Box<Foo>] = &[Box::new(1), Box::new(2)];
bars(x); bars(x);
bars(&[box 1, box 2]); bars(&[Box::new(1), Box::new(2)]);
let x: &[Box<Foo>] = &[box 1, box 2]; let x: &[Box<Foo>] = &[Box::new(1), Box::new(2)];
foog(x, &[box 1]); foog(x, &[Box::new(1)]);
struct T<'a> { struct T<'a> {
t: [&'a (Foo+'a); 2] t: [&'a (Foo+'a); 2]
@ -85,9 +85,9 @@ fn main() {
t: &'a [Box<Foo+'static>] t: &'a [Box<Foo+'static>]
} }
let _n = M { let _n = M {
t: &[box 1, box 2] t: &[Box::new(1), Box::new(2)]
}; };
let x: [Box<Foo>; 2] = [box 1, box 2]; let x: [Box<Foo>; 2] = [Box::new(1), Box::new(2)];
let _n = M { let _n = M {
t: &x t: &x
}; };

View file

@ -9,8 +9,6 @@
// except according to those terms. // except according to those terms.
#![allow(dead_code)] #![allow(dead_code)]
#![allow(unknown_features)]
#![feature(box_syntax)]
// this code used to cause an ICE // this code used to cause an ICE
@ -28,5 +26,6 @@ impl X<int> for F {
} }
fn main() { fn main() {
S {f: box F, g: box F}; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
S {f: Box::new(F), g: Box::new(F) };
} }

View file

@ -8,10 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
fn main() { fn main() {
fn test() -> Box<std::any::Any + 'static> { box 1 } // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
fn test() -> Box<std::any::Any + 'static> { Box::new(1) }
println!("{:?}", test()) println!("{:?}", test())
} }

View file

@ -8,16 +8,14 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
struct Foo<'a> { struct Foo<'a> {
listener: Box<FnMut() + 'a>, listener: Box<FnMut() + 'a>,
} }
impl<'a> Foo<'a> { impl<'a> Foo<'a> {
fn new<F>(listener: F) -> Foo<'a> where F: FnMut() + 'a { fn new<F>(listener: F) -> Foo<'a> where F: FnMut() + 'a {
Foo { listener: box listener } // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
Foo { listener: Box::new(listener) }
} }
} }

View file

@ -11,13 +11,12 @@
// All 3 expressions should work in that the argument gets // All 3 expressions should work in that the argument gets
// coerced to a trait object // coerced to a trait object
#![allow(unknown_features)] // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
#![feature(box_syntax)]
fn main() { fn main() {
send::<Box<Foo>>(box Output(0)); send::<Box<Foo>>(Box::new(Output(0)));
Test::<Box<Foo>>::foo(box Output(0)); Test::<Box<Foo>>::foo(Box::new(Output(0)));
Test::<Box<Foo>>::new().send(box Output(0)); Test::<Box<Foo>>::new().send(Box::new(Output(0)));
} }
fn send<T>(_: T) {} fn send<T>(_: T) {}

View file

@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
trait Matcher { trait Matcher {
fn next_match(&mut self) -> Option<(uint, uint)>; fn next_match(&mut self) -> Option<(uint, uint)>;
} }
@ -32,9 +29,10 @@ trait IntoMatcher<'a, T> {
impl<'a, 'b, F> IntoMatcher<'a, CharPredMatcher<'a, 'b>> for F where F: FnMut(char) -> bool + 'b { impl<'a, 'b, F> IntoMatcher<'a, CharPredMatcher<'a, 'b>> for F where F: FnMut(char) -> bool + 'b {
fn into_matcher(self, s: &'a str) -> CharPredMatcher<'a, 'b> { fn into_matcher(self, s: &'a str) -> CharPredMatcher<'a, 'b> {
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
CharPredMatcher { CharPredMatcher {
str: s, str: s,
pred: box self, pred: Box::new(self),
} }
} }
} }

View file

@ -12,7 +12,7 @@
#![feature(box_syntax)] #![feature(box_syntax)]
fn match_on_local() { fn match_on_local() {
let mut foo = Some(box 5); let mut foo: Option<Box<_>> = Some(box 5);
match foo { match foo {
None => {}, None => {},
Some(x) => { Some(x) => {
@ -33,7 +33,7 @@ fn match_on_arg(mut foo: Option<Box<i32>>) {
} }
fn match_on_binding() { fn match_on_binding() {
match Some(box 7) { match Some(Box::new(7)) {
mut foo => { mut foo => {
match foo { match foo {
None => {}, None => {},
@ -47,7 +47,7 @@ fn match_on_binding() {
} }
fn match_on_upvar() { fn match_on_upvar() {
let mut foo = Some(box 8i32); let mut foo: Option<Box<_>> = Some(box 8i32);
let f = move|| { let f = move|| {
match foo { match foo {
None => {}, None => {},

View file

@ -11,7 +11,6 @@
// ignore-pretty // ignore-pretty
#![allow(unknown_features)] #![allow(unknown_features)]
#![feature(box_syntax)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
struct Parser<'a, I, O> { struct Parser<'a, I, O> {
@ -20,13 +19,14 @@ struct Parser<'a, I, O> {
impl<'a, I: 'a, O: 'a> Parser<'a, I, O> { impl<'a, I: 'a, O: 'a> Parser<'a, I, O> {
fn compose<K: 'a>(mut self, mut rhs: Parser<'a, O, K>) -> Parser<'a, I, K> { fn compose<K: 'a>(mut self, mut rhs: Parser<'a, O, K>) -> Parser<'a, I, K> {
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
Parser { Parser {
parse: box move |x: I| { parse: Box::new(move |x: I| {
match (self.parse)(x) { match (self.parse)(x) {
Ok(r) => (rhs.parse)(r), Ok(r) => (rhs.parse)(r),
Err(e) => Err(e) Err(e) => Err(e)
} }
} })
} }
} }
} }

View file

@ -10,16 +10,15 @@
// Test that generating drop glue for Box<str> doesn't ICE // Test that generating drop glue for Box<str> doesn't ICE
#![allow(unknown_features)]
#![feature(box_syntax)]
fn f(s: Box<str>) -> Box<str> { fn f(s: Box<str>) -> Box<str> {
s s
} }
fn main() { fn main() {
// There is currently no safe way to construct a `Box<str>`, so improvise // There is currently no safe way to construct a `Box<str>`, so improvise
let box_arr: Box<[u8]> = box ['h' as u8, 'e' as u8, 'l' as u8, 'l' as u8, 'o' as u8]; //
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let box_arr: Box<[u8]> = Box::new(['h' as u8, 'e' as u8, 'l' as u8, 'l' as u8, 'o' as u8]);
let box_str: Box<str> = unsafe { std::mem::transmute(box_arr) }; let box_str: Box<str> = unsafe { std::mem::transmute(box_arr) };
assert_eq!(&*box_str, "hello"); assert_eq!(&*box_str, "hello");
f(box_str); f(box_str);

View file

@ -11,9 +11,6 @@
// Check that trans doesn't ICE when translating an array repeat // Check that trans doesn't ICE when translating an array repeat
// expression with a count of 1 and a non-Copy element type. // expression with a count of 1 and a non-Copy element type.
#![allow(unknown_features)]
#![feature(box_syntax)]
fn main() { fn main() {
let _ = [box 1_usize; 1]; let _ = [Box::new(1_usize); 1];
} }

View file

@ -10,10 +10,9 @@
// Test that overloaded calls work with zero arity closures // Test that overloaded calls work with zero arity closures
#![feature(box_syntax)]
fn main() { fn main() {
let functions: [Box<Fn() -> Option<()>>; 1] = [box || None]; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let functions: [Box<Fn() -> Option<()>>; 1] = [Box::new(|| None)];
let _: Option<Vec<()>> = functions.iter().map(|f| (*f)()).collect(); let _: Option<Vec<()>> = functions.iter().map(|f| (*f)()).collect();
} }

View file

@ -11,8 +11,6 @@
// //
// ignore-lexer-test FIXME #15883 // ignore-lexer-test FIXME #15883
#![allow(unknown_features)]
#![feature(box_syntax)]
#![feature(unsafe_destructor)] #![feature(unsafe_destructor)]
pub type Task = int; pub type Task = int;
@ -52,11 +50,11 @@ pub mod pipes {
pub fn packet<T:Send>() -> *const packet<T> { pub fn packet<T:Send>() -> *const packet<T> {
unsafe { unsafe {
let p: *const packet<T> = mem::transmute(box Stuff{ let p: *const packet<T> = mem::transmute(Box::new(Stuff{
state: empty, state: empty,
blocked_task: None::<Task>, blocked_task: None::<Task>,
payload: None::<T> payload: None::<T>
}); }));
p p
} }
} }

View file

@ -8,13 +8,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
type Connection = Box<FnMut(Vec<u8>) + 'static>; type Connection = Box<FnMut(Vec<u8>) + 'static>;
fn f() -> Option<Connection> { fn f() -> Option<Connection> {
let mock_connection: Connection = box |_| {}; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let mock_connection: Connection = Box::new(|_| {});
Some(mock_connection) Some(mock_connection)
} }

View file

@ -11,7 +11,6 @@
// rustc --test ignores2.rs && ./ignores2 // rustc --test ignores2.rs && ./ignores2
#![allow(unknown_features)] #![allow(unknown_features)]
#![feature(box_syntax)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
use std::old_path::{Path}; use std::old_path::{Path};
@ -23,9 +22,10 @@ type rsrc_loader = Box<FnMut(&Path) -> (result::Result<String, String>) + 'stati
fn tester() fn tester()
{ {
let mut loader: rsrc_loader = box move|_path| { // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let mut loader: rsrc_loader = Box::new(move|_path| {
result::Result::Ok("more blah".to_string()) result::Result::Ok("more blah".to_string())
}; });
let path = old_path::Path::new("blah"); let path = old_path::Path::new("blah");
assert!(loader(&path).is_ok()); assert!(loader(&path).is_ok());

View file

@ -9,7 +9,6 @@
// except according to those terms. // except according to those terms.
#![allow(unknown_features)] #![allow(unknown_features)]
#![feature(box_syntax)]
use std::thread::Thread; use std::thread::Thread;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
@ -27,8 +26,8 @@ fn foo(name: String, samples_chan: Sender<Msg>) {
let _t = Thread::spawn(move|| { let _t = Thread::spawn(move|| {
let mut samples_chan = samples_chan; let mut samples_chan = samples_chan;
// `box() (...)` syntax is needed to make pretty printer converge in one try: // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let callback: SamplesFn = box() (move |buffer| { let callback: SamplesFn = Box::new(move |buffer| {
for i in 0_usize..buffer.len() { for i in 0_usize..buffer.len() {
println!("{}: {}", i, buffer[i]) println!("{}: {}", i, buffer[i])
} }

View file

@ -8,13 +8,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
enum Either<T, U> { Left(T), Right(U) } enum Either<T, U> { Left(T), Right(U) }
pub fn main() { pub fn main() {
match Either::Left(box 17) { match Either::Left(Box::new(17)) {
Either::Right(()) => {} Either::Right(()) => {}
_ => {} _ => {}
} }

View file

@ -8,18 +8,15 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
pub fn main() { pub fn main() {
match &[(box 5,box 7)] { match &[(Box::new(5),Box::new(7))] {
ps => { ps => {
let (ref y, _) = ps[0]; let (ref y, _) = ps[0];
assert!(**y == 5); assert!(**y == 5);
} }
} }
match Some(&[(box 5,)]) { match Some(&[(Box::new(5),)]) {
Some(ps) => { Some(ps) => {
let (ref y,) = ps[0]; let (ref y,) = ps[0];
assert!(**y == 5); assert!(**y == 5);
@ -27,7 +24,7 @@ pub fn main() {
None => () None => ()
} }
match Some(&[(box 5,box 7)]) { match Some(&[(Box::new(5),Box::new(7))]) {
Some(ps) => { Some(ps) => {
let (ref y, ref z) = ps[0]; let (ref y, ref z) = ps[0];
assert!(**y == 5); assert!(**y == 5);

View file

@ -17,11 +17,12 @@
struct A { a: Box<isize> } struct A { a: Box<isize> }
fn foo() -> Box<FnMut() -> isize + 'static> { fn foo() -> Box<FnMut() -> isize + 'static> {
let k = box 22; let k: Box<_> = box 22;
let _u = A {a: k.clone()}; let _u = A {a: k.clone()};
// FIXME(#16640) suffix in `22_isize` suffix shouldn't be necessary // FIXME(#16640) suffix in `22_isize` suffix shouldn't be necessary
let result = || 22_isize; let result = || 22_isize;
box result // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
Box::new(result)
} }
pub fn main() { pub fn main() {

View file

@ -11,10 +11,8 @@
// Test that the lambda kind is inferred correctly as a return // Test that the lambda kind is inferred correctly as a return
// expression // expression
#![allow(unknown_features)] // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
#![feature(box_syntax)] fn unique() -> Box<FnMut()+'static> { return Box::new(|| ()); }
fn unique() -> Box<FnMut()+'static> { return box || (); }
pub fn main() { pub fn main() {
} }

Some files were not shown because too many files have changed in this diff Show more