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")]
impl<T> Default for Box<[T]> {
#[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")]

View File

@ -64,7 +64,8 @@ fn test_writer_hasher() {
//assert_eq!(hasher.hash(& s), 97 + 0xFF);
let cs: &[u8] = &[1u8, 2u8, 3u8];
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);
// FIXME (#18248) Add tests for hashing Rc<str> and Rc<[T]>

View File

@ -404,7 +404,8 @@ fn test_collect() {
#[test]
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 % 2 == 0));
assert!(!v.iter().all(|&x| x > 100));
@ -413,7 +414,8 @@ fn test_all() {
#[test]
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 % 2 == 0));
assert!(!v.iter().any(|&x| x > 100));
@ -581,8 +583,9 @@ fn test_rposition() {
#[test]
#[should_fail]
fn test_rposition_panic() {
let v = [(box 0, box 0), (box 0, box 0),
(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)];
let mut i = 0;
v.iter().rposition(|_elt| {
if i == 2 {

View File

@ -79,7 +79,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
None => {}
}
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 {
ast::ItemEnum(ast::EnumDef { ref variants }, _) => {
// 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 => {}
}
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 {
ast::ItemConst(_, ref const_expr) => Some(const_expr.id),
_ => None

View File

@ -99,7 +99,7 @@ impl<'a> Registry<'a> {
/// It builds for you a `NormalTT` that calls `expander`,
/// and also takes care of interning the macro's name.
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.

View File

@ -2969,7 +2969,7 @@ pub fn write_metadata(cx: &SharedCrateContext, krate: &ast::Crate) -> Vec<u8> {
}
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 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 =
csearch::maybe_get_item_ast(
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 {
csearch::FoundAst::NotFound => {

View File

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

View File

@ -547,8 +547,9 @@ mod tests {
let (tx, rx) = channel();
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|| {
set_stdout(box w);
set_stdout(Box::new(w));
println!("hello!");
});
assert_eq!(r.read_to_string().unwrap(), "hello!\n");
@ -560,8 +561,9 @@ mod tests {
let (tx, rx) = channel();
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 || -> () {
set_stderr(box w);
set_stderr(Box::new(w));
panic!("my special message");
});
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.
use boxed::Box;
use sync::mpsc::{Receiver, Sender, channel};
use time::Duration;
use old_io::IoResult;
@ -143,7 +144,7 @@ impl Timer {
let (tx, rx) = channel();
// Short-circuit the timer backend for 0 duration
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 {
tx.send(()).unwrap();
}
@ -204,7 +205,7 @@ impl Timer {
// not clear what use a 0ms period is anyway...
let ms = if ms == 0 { 1 } else { ms };
let (tx, rx) = channel();
self.inner.period(ms, box TimerCallback { tx: tx });
self.inner.period(ms, Box::new(TimerCallback { tx: tx }));
return rx
}
}

View File

@ -166,7 +166,7 @@ fn rust_panic(cause: Box<Any + Send + 'static>) -> ! {
rtdebug!("begin_unwind()");
unsafe {
let exception = box Exception {
let exception: Box<_> = box Exception {
uwe: uw::_Unwind_Exception {
exception_class: rust_exception_class(),
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 _ = 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!().
@ -521,7 +521,7 @@ pub fn begin_unwind<M: Any + Send>(msg: M, file_line: &(&'static str, uint)) ->
// panicking.
// 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.

View File

@ -33,7 +33,7 @@ impl<'a,A,R> Thunk<'a,A,R> {
where F : FnOnce(A) -> R, F : Send + 'a
{
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,
registry: Option<diagnostics::registry::Registry>,
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 {
@ -352,11 +352,11 @@ impl EmitterWriter {
if use_color {
let dst = match term::stderr() {
Some(t) => Terminal(t),
None => Raw(box stderr),
None => Raw(Box::new(stderr)),
};
EmitterWriter { dst: dst, registry: registry }
} 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 {
// utility function to simplify creating NormalTT syntax extensions
fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
NormalTT(box f, None)
NormalTT(Box::new(f), None)
}
let mut syntax_expanders = SyntaxEnv::new();
@ -489,9 +489,9 @@ fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>)
builtin_normal_expander(
ext::log_syntax::expand_syntax_ext));
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"),
Decorator(box ext::deriving::expand_deprecated_deriving));
Decorator(Box::new(ext::deriving::expand_deprecated_deriving)));
if ecfg.enable_quotes() {
// Quasi-quoting expanders

View File

@ -40,9 +40,9 @@ pub fn expand_deriving_clone<F>(cx: &mut ExtCtxt,
args: Vec::new(),
ret_ty: Self_,
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)
}),
})),
}
),
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_bool(span, true),
box |cx, span, _, _| cx.expr_bool(span, false),
Box::new(|cx, span, _, _| cx.expr_bool(span, false)),
cx, span, substr)
}
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_bool(span, false),
box |cx, span, _, _| cx.expr_bool(span, true),
Box::new(|cx, span, _, _| cx.expr_bool(span, true)),
cx, span, substr)
}
@ -72,9 +72,9 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
args: vec!(borrowed_self()),
ret_ty: Literal(path_local!(bool)),
attributes: attrs,
combine_substructure: combine_substructure(box |a, b, c| {
combine_substructure: combine_substructure(Box::new(|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()),
ret_ty: Literal(path_local!(bool)),
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)
})
}))
}
} }
}
@ -61,9 +61,9 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
args: vec![borrowed_self()],
ret_ty: ret_ty,
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)
})
}))
};
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_)))
},
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 {
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
} else {
some_ordering_collapsed(cx, span, PartialCmpOp, tag_tuple)
}
},
}),
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_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 {
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
} else {
@ -233,6 +233,6 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
};
some_ordering_collapsed(cx, span, op, tag_tuple)
}
},
}),
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);
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,
span,
substr)
@ -57,9 +58,9 @@ pub fn expand_deriving_totaleq<F>(cx: &mut ExtCtxt,
args: vec!(),
ret_ty: nil_ty(),
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)
})
}))
}
),
associated_types: Vec::new(),

View File

@ -41,9 +41,9 @@ pub fn expand_deriving_totalord<F>(cx: &mut ExtCtxt,
args: vec!(borrowed_self()),
ret_ty: Literal(path_std!(cx, core::cmp::Ordering)),
attributes: attrs,
combine_substructure: combine_substructure(box |a, b, c| {
combine_substructure: combine_substructure(Box::new(|a, b, c| {
cs_cmp(a, b, c)
}),
})),
}
),
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_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 {
cx.span_bug(span, "not exactly 2 arguments in `derives(Ord)`")
} else {
ordering_collapsed(cx, span, tag_tuple)
}
},
}),
cx, span, substr)
}

View File

@ -82,9 +82,9 @@ fn expand_deriving_decodable_imp<F>(cx: &mut ExtCtxt,
true
)),
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)
}),
})),
}
),
associated_types: Vec::new(),

View File

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

View File

@ -158,9 +158,9 @@ fn expand_deriving_encodable_imp<F>(cx: &mut ExtCtxt,
true
)),
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)
}),
})),
}
),
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))),
ret_ty: nil_ty(),
attributes: vec![],
combine_substructure: combine_substructure(box |a, b, c| {
combine_substructure: combine_substructure(Box::new(|a, b, c| {
hash_substructure(a, b, c)
})
}))
}
),
associated_types: Vec::new(),

View File

@ -45,9 +45,9 @@ pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
true)),
// #[inline] liable to cause code-bloat
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)
}),
})),
},
MethodDef {
name: "from_u64",
@ -60,9 +60,9 @@ pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
true)),
// #[inline] liable to cause code-bloat
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)
}),
})),
}
),
associated_types: Vec::new(),

View File

@ -55,9 +55,9 @@ pub fn expand_deriving_rand<F>(cx: &mut ExtCtxt,
),
ret_ty: Self_,
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)
})
}))
}
),
associated_types: Vec::new(),

View File

@ -46,9 +46,9 @@ pub fn expand_deriving_show<F>(cx: &mut ExtCtxt,
args: vec!(fmtr),
ret_ty: Literal(path_std!(cx, core::fmt::Result)),
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)
})
}))
}
],
associated_types: Vec::new(),

View File

@ -479,7 +479,7 @@ pub fn parse(sess: &ParseSess,
}
rdr.next_token();
} 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();
match ei.top_elts.get_tt(ei.idx) {

View File

@ -180,7 +180,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
Some(named_matches),
imported_from,
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();
// Let the context choose how to interpret the result.
// 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")
};
let exp = box MacroRulesMacroExpander {
let exp: Box<_> = box MacroRulesMacroExpander {
name: def.ident,
imported_from: def.imported_from,
lhses: lhses,

View File

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

View File

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

View File

@ -36,10 +36,12 @@ pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("identity", expand_identity);
reg.register_syntax_extension(
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(
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])

View File

@ -46,5 +46,6 @@ impl TTMacroExpander for Expander {
pub fn plugin_registrar(reg: &mut Registry) {
let args = reg.args().clone();
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;
fn main() {
let tmp;
let tmp: Box<_>;
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
tmp = box 2;

View File

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

View File

@ -11,14 +11,13 @@
// Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is
// forbidden when `T` is a trait.
#![feature(box_syntax)]
struct Foo;
trait Trait { fn foo(&self) {} }
impl Trait for Foo {}
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
//~| expected `&Trait`
//~| found `Box<Trait>`

View File

@ -10,8 +10,6 @@
// Forbid assignment into a dynamically sized type.
#![feature(box_syntax)]
struct Fat<T: ?Sized> {
f1: isize,
f2: &'static str,
@ -43,7 +41,8 @@ impl ToBar for Bar1 {
pub fn main() {
// Assignment.
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;
//~^ ERROR the trait `core::marker::Sized` is not implemented
}

View File

@ -10,8 +10,6 @@
// Forbid assignment into a dynamically sized type.
#![feature(box_syntax)]
struct Fat<T: ?Sized> {
f1: isize,
f2: &'static str,
@ -43,7 +41,8 @@ impl ToBar for Bar1 {
pub fn main() {
// Assignment.
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};
//~^ ERROR mismatched types
//~| expected `ToBar`

View File

@ -8,13 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
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
//~^ ERROR cannot infer an appropriate lifetime
});
}));
}
fn main() {}

View File

@ -15,6 +15,7 @@ struct Test {
}
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
}

View File

@ -8,18 +8,20 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
fn main() {
let _foo = &[1_usize, 2] as [usize];
//~^ ERROR cast to unsized type: `&[usize; 2]` as `[usize]`
//~^^ 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`
//~^^ HELP did you mean `Box<core::fmt::Debug>`?
let _baz = 1_usize as std::fmt::Debug;
//~^ ERROR cast to unsized type: `usize` as `core::fmt::Debug`
//~^^ HELP consider using a box or reference as appropriate
let _quux = [1_usize, 2] as [usize];
//~^ ERROR cast to unsized type: `[usize; 2]` as `[usize]`
//~^^ 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
// and rejected.
#![feature(box_syntax)]
fn main() {
(|| box *[0_usize].as_slice())();
//~^ ERROR cannot move out of borrowed content
//~^^ ERROR cannot move a value of type [usize]
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
(|| Box::new(*[0_usize].as_slice()))();
//~^ 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
// except according to those terms.
#![feature(box_syntax)]
use std::cell::RefCell;
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
fn main() {
let mut y = 1_usize;
let c = RefCell::new(vec![]);
c.push(box || y = 0);
c.push(box || y = 0);
c.push(Box::new(|| y = 0));
c.push(Box::new(|| y = 0));
//~^ ERROR cannot borrow `y` as mutable more than once at a time
}
@ -24,8 +24,8 @@ fn ufcs() {
let mut y = 1_usize;
let c = RefCell::new(vec![]);
Push::push(&c, box || y = 0);
Push::push(&c, box || y = 0);
Push::push(&c, Box::new(|| y = 0));
Push::push(&c, Box::new(|| y = 0));
//~^ 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
// except according to those terms.
#![feature(box_syntax)]
mod my_mod {
pub struct MyStruct {
priv_field: isize
@ -26,10 +24,15 @@ fn main() {
let my_struct = my_mod::MyStruct();
let _woohoo = (&my_struct).priv_field;
//~^ 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
(&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;
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private
}

View File

@ -9,12 +9,12 @@
// except according to those terms.
#![feature(unboxed_closures)]
#![feature(box_syntax)]
fn id<T>(t: T) -> T { t }
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 cannot move out of borrowed content
}

View File

@ -8,13 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
trait Foo { fn foo(&self) {} }
impl Foo for u8 {}
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>;
//~^ 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() {
let x: Box<HashMap<isize, isize>> = box HashMap::new();
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
}

View File

@ -12,7 +12,6 @@
// bound must be noncopyable. For details see
// http://smallcultfollowing.com/babysteps/blog/2013/04/30/the-case-of-the-recurring-closure/
#![feature(box_syntax)]
#![feature(unboxed_closures)]
struct R<'a> {
@ -41,7 +40,8 @@ fn innocent_looking_victim() {
}
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
}

View File

@ -11,32 +11,36 @@
// Test that attempts to implicitly coerce a value into an
// object respect the lifetime bound on the object type.
#![feature(box_syntax)]
trait Foo : ::std::marker::MarkerTrait {}
impl<'a> Foo for &'a [u8] {}
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
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
}
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> {
// 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> {
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> {
box v // OK, thanks to 'a:'b
Box::new(v) // OK, thanks to 'a:'b
}
fn main() { }

View File

@ -10,6 +10,8 @@
#![feature(box_syntax)]
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
use std::marker::MarkerTrait;
trait X : MarkerTrait {}
@ -24,48 +26,48 @@ trait Iter {
fn bad1<T: Iter>(v: T) -> Box<X+'static>
{
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>
where Box<T::Item> : X
{
let item = box v.into_item();
box item //~ ERROR associated type `<T as Iter>::Item` may not live long enough
let item: Box<_> = box v.into_item();
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>
{
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>
where Box<T::Item> : X
{
let item = box v.into_item();
box item //~ ERROR associated type `<T as Iter>::Item` may not live long enough
let item: Box<_> = box v.into_item();
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>
where T::Item : 'a
{
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>
where T::Item : Clone
{
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>
where T::Item : Clone + 'a
{
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>
@ -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.
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() {}

View File

@ -8,32 +8,32 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
trait X { fn foo(&self) {} }
fn p1<T>(v: T) -> Box<X+'static>
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>
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>
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>
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() {}

View File

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

View File

@ -8,17 +8,17 @@
// option. This file may not be copied, modified, or distributed
// 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> {
// This is legal, because the region bound on `proc`
// states that it captures `x`.
box move|| { *x }
Box::new(move|| { *x })
}
fn static_proc(x: &isize) -> Box<FnMut()->(isize) + '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() { }

View File

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
#![feature(unboxed_closures)]
struct closure_box<'a> {
@ -22,7 +21,8 @@ fn box_it<'r>(x: Box<FnMut() + 'r>) -> closure_box<'r> {
fn main() {
let mut cl_box = {
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(());
}

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
struct Struct {
person: &'static str
}
@ -25,7 +23,8 @@ impl Trait<&'static str> for Struct {
}
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`
s.f(1);
}

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
struct Struct {
person: &'static str
}
@ -27,6 +25,7 @@ impl Trait<&'static str> for Struct {
fn main() {
let person = "Fred".to_string();
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
// except according to those terms.
#![feature(box_syntax)]
#![feature(unboxed_closures)]
// 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_once<A,F:FnOnce<A>>(f: F) -> F { f }
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
fn main() {
// By-ref cases
{
let x = box 0_usize;
let x = Box::new(0_usize);
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 x = box 0_usize;
let x = Box::new(0_usize);
let f = to_fn_once(|| drop(x)); // OK -- FnOnce
}
// 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 x = box 0_usize;
let x = Box::new(0_usize);
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
}
}

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
#[derive(Debug)]
struct r {
b: bool,
@ -20,7 +18,8 @@ impl Drop for r {
}
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
println!("{:?}", i);
}

View File

@ -8,15 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
use std::rc::Rc;
fn f<T:Send>(__isize: T) {
}
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);
//~^ ERROR `core::marker::Send` is not implemented
}

View File

@ -10,8 +10,6 @@
#![feature(unsafe_destructor)]
#![feature(box_syntax)]
use std::cell::Cell;
#[derive(Debug)]
@ -36,8 +34,9 @@ fn clone<T: Clone>(t: &T) -> T { t.clone() }
fn main() {
let i1 = &Cell::new(0);
let i2 = &Cell::new(1);
let r1 = vec!(box r { i: i1 });
let r2 = vec!(box r { i: i2 });
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let r1 = vec!(Box::new(r { i: i1 }));
let r2 = vec!(Box::new(r { i: i2 }));
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

View File

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

View File

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

View File

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

View File

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

View File

@ -245,9 +245,10 @@ fn hello<X: SomeTrait>((z, a) : (u32, String), ex: X) {
let x = 32.0f32;
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 s3 = box nofields;
let s3: Box<_> = box nofields;
s.Method(43);
s3.Method(43);
@ -282,7 +283,7 @@ pub struct blah {
}
fn main() { // foo
let s = box some_fields {field1: 43};
let s: Box<_> = box some_fields {field1: 43};
hello((43, "a".to_string()), *s);
sub::sub2::hello();
sub2::sub3::hello();

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
static mut DROP_RAN: bool = false;
struct Foo;
@ -28,7 +26,8 @@ struct Fat<T: ?Sized> {
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 {
assert!(DROP_RAN);

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(box_syntax)]
static mut DROP_RAN: int = 0;
struct Foo;
@ -25,7 +23,8 @@ struct Fat<T: ?Sized> {
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 {
assert!(DROP_RAN == 3);

View File

@ -8,15 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
#[derive(PartialEq, Debug)]
struct Point { x : int }
pub fn main() {
assert_eq!(14,14);
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});
}

View File

@ -25,6 +25,7 @@ fn pairwise_sub(mut t: Box<DoubleEndedIterator<Item=int>>) -> int {
fn main() {
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);
}

View File

@ -17,12 +17,21 @@ use std::fmt::Debug;
// rvalue expressions to be unsized. See #20169 for more information.
pub fn main() {
let _: Box<[int]> = box { [1, 2, 3] };
let _: Box<[int]> = box if true { [1, 2, 3] } else { [1, 3, 4] };
let _: Box<[int]> = box match true { true => [1, 2, 3], false => [1, 3, 4] };
let _: Box<Fn(int) -> _> = box { |x| (x as u8) };
let _: Box<Debug> = box if true { false } else { true };
let _: Box<Debug> = box match true { true => 'a', false => 'b' };
// FIXME #22405: We cannot infer the type `Box<[int; k]>` for
// the r-value expression from the context `Box<[int]>`, and
// therefore the `box EXPR` desugaring breaks down.
//
// One could reasonably claim that the `box EXPR` desugaring is
// 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] = &if true { [1, 2, 3] } else { [1, 3, 4] };
@ -36,6 +45,6 @@ pub fn main() {
let _: Vec<Box<Fn(int) -> _>> = vec![
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
// are const.
#![allow(unknown_features)]
#![feature(box_syntax)]
fn foo<T: Sync>(x: T) -> T { x }
struct F { field: int }
@ -25,5 +22,5 @@ pub fn main() {
foo(F{field: 42});
foo((1, 2_usize));
foo(@1);*/
foo(box 1);
foo(Box::new(1));
}

View File

@ -20,6 +20,7 @@ struct A {
pub fn main() {
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);
}

View File

@ -23,7 +23,8 @@ struct A {
}
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 obj2: A = json::decode(&s).unwrap();
assert!(obj.foo == obj2.foo);

View File

@ -8,15 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
#[derive(PartialEq, PartialOrd, Eq, Ord)]
struct Foo(Box<[u8]>);
pub fn main() {
let a = Foo(box [0, 1, 2]);
let b = Foo(box [0, 1, 2]);
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let a = Foo(Box::new([0, 1, 2]));
let b = Foo(Box::new([0, 1, 2]));
assert!(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
#![allow(unknown_features)]
#![feature(box_syntax)]
use std::ops::{Deref, DerefMut};
pub struct Arr {
@ -41,6 +38,7 @@ pub fn foo(arr: &mut Arr) {
}
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);
}

View File

@ -10,9 +10,6 @@
// Test that a custom deref with a fat pointer return type does not ICE
#![allow(unknown_features)]
#![feature(box_syntax)]
use std::ops::Deref;
pub struct Arr {
@ -36,6 +33,7 @@ pub fn foo(arr: &Arr) {
}
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);
}

View File

@ -115,7 +115,7 @@ pub fn main() {
foo3(f5);
// Box.
let f1 = box [1, 2, 3];
let f1 = Box::new([1, 2, 3]);
assert!((*f1)[1] == 2);
let f2: Box<[int]> = f1;
assert!((*f2)[1] == 2);
@ -125,6 +125,9 @@ pub fn main() {
foo(&*f1);
let f2 : Box<Fat<[int]>> = f1;
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);
}

View File

@ -95,7 +95,9 @@ pub fn main() {
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);
// Deep nesting

View File

@ -8,18 +8,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
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());
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());
}

View File

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

View File

@ -9,7 +9,6 @@
// except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
#![feature(unboxed_closures)]
/**
@ -61,7 +60,8 @@ mod map_reduce {
}
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();
}

View File

@ -9,7 +9,6 @@
// except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
#![feature(unboxed_closures)]
// Test that `Fn(int) -> int + 'static` parses as `(Fn(int) -> int) +
@ -17,7 +16,8 @@
// cause a compilation error. Issue #18772.
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() {}

View File

@ -9,8 +9,8 @@
// except according to those terms.
#![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) { } }
impl Foo for int {}
@ -39,16 +39,16 @@ fn main() {
let r = &1;
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([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(&[box 1, box 2]);
bars(&[Box::new(1), Box::new(2)]);
let x: &[Box<Foo>] = &[box 1, box 2];
foog(x, &[box 1]);
let x: &[Box<Foo>] = &[Box::new(1), Box::new(2)];
foog(x, &[Box::new(1)]);
struct T<'a> {
t: [&'a (Foo+'a); 2]
@ -85,9 +85,9 @@ fn main() {
t: &'a [Box<Foo+'static>]
}
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 {
t: &x
};

View File

@ -9,8 +9,6 @@
// except according to those terms.
#![allow(dead_code)]
#![allow(unknown_features)]
#![feature(box_syntax)]
// this code used to cause an ICE
@ -28,5 +26,6 @@ impl X<int> for F {
}
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
// except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
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())
}

View File

@ -8,16 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
struct Foo<'a> {
listener: Box<FnMut() + 'a>,
}
impl<'a> Foo<'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
// coerced to a trait object
#![allow(unknown_features)]
#![feature(box_syntax)]
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
fn main() {
send::<Box<Foo>>(box Output(0));
Test::<Box<Foo>>::foo(box Output(0));
Test::<Box<Foo>>::new().send(box Output(0));
send::<Box<Foo>>(Box::new(Output(0)));
Test::<Box<Foo>>::foo(Box::new(Output(0)));
Test::<Box<Foo>>::new().send(Box::new(Output(0)));
}
fn send<T>(_: T) {}

View File

@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
trait Matcher {
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 {
fn into_matcher(self, s: &'a str) -> CharPredMatcher<'a, 'b> {
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
CharPredMatcher {
str: s,
pred: box self,
pred: Box::new(self),
}
}
}

View File

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

View File

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

View File

@ -10,16 +10,15 @@
// Test that generating drop glue for Box<str> doesn't ICE
#![allow(unknown_features)]
#![feature(box_syntax)]
fn f(s: Box<str>) -> Box<str> {
s
}
fn main() {
// 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) };
assert_eq!(&*box_str, "hello");
f(box_str);

View File

@ -11,9 +11,6 @@
// Check that trans doesn't ICE when translating an array repeat
// expression with a count of 1 and a non-Copy element type.
#![allow(unknown_features)]
#![feature(box_syntax)]
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
#![feature(box_syntax)]
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();
}

View File

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

View File

@ -8,13 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(unknown_features)]
#![feature(box_syntax)]
type Connection = Box<FnMut(Vec<u8>) + 'static>;
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)
}

View File

@ -11,7 +11,6 @@
// rustc --test ignores2.rs && ./ignores2
#![allow(unknown_features)]
#![feature(box_syntax)]
#![feature(unboxed_closures)]
use std::old_path::{Path};
@ -23,9 +22,10 @@ type rsrc_loader = Box<FnMut(&Path) -> (result::Result<String, String>) + 'stati
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())
};
});
let path = old_path::Path::new("blah");
assert!(loader(&path).is_ok());

View File

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

View File

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

View File

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

View File

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

View File

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

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