Skip to content

Commit 0d5bcb1

Browse files
committed
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.
1 parent b03279a commit 0d5bcb1

File tree

118 files changed

+349
-373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+349
-373
lines changed

src/liballoc/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<T: Default> Default for Box<T> {
157157
#[stable(feature = "rust1", since = "1.0.0")]
158158
impl<T> Default for Box<[T]> {
159159
#[stable(feature = "rust1", since = "1.0.0")]
160-
fn default() -> Box<[T]> { box [] }
160+
fn default() -> Box<[T]> { Box::<[T; 0]>::new([]) }
161161
}
162162

163163
#[stable(feature = "rust1", since = "1.0.0")]

src/libcoretest/hash/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ fn test_writer_hasher() {
6464
//assert_eq!(hasher.hash(& s), 97 + 0xFF);
6565
let cs: &[u8] = &[1u8, 2u8, 3u8];
6666
assert_eq!(hash(& cs), 9);
67-
let cs: Box<[u8]> = box [1u8, 2u8, 3u8];
67+
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
68+
let cs: Box<[u8]> = Box::new([1u8, 2u8, 3u8]);
6869
assert_eq!(hash(& cs), 9);
6970

7071
// FIXME (#18248) Add tests for hashing Rc<str> and Rc<[T]>

src/libcoretest/iter.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ fn test_collect() {
404404

405405
#[test]
406406
fn test_all() {
407-
let v: Box<[int]> = box [1, 2, 3, 4, 5];
407+
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
408+
let v: Box<[int]> = Box::new([1, 2, 3, 4, 5]);
408409
assert!(v.iter().all(|&x| x < 10));
409410
assert!(!v.iter().all(|&x| x % 2 == 0));
410411
assert!(!v.iter().all(|&x| x > 100));
@@ -413,7 +414,8 @@ fn test_all() {
413414

414415
#[test]
415416
fn test_any() {
416-
let v: Box<[int]> = box [1, 2, 3, 4, 5];
417+
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
418+
let v: Box<[int]> = Box::new([1, 2, 3, 4, 5]);
417419
assert!(v.iter().any(|&x| x < 10));
418420
assert!(v.iter().any(|&x| x % 2 == 0));
419421
assert!(!v.iter().any(|&x| x > 100));
@@ -581,8 +583,9 @@ fn test_rposition() {
581583
#[test]
582584
#[should_fail]
583585
fn test_rposition_panic() {
584-
let v = [(box 0, box 0), (box 0, box 0),
585-
(box 0, box 0), (box 0, box 0)];
586+
let v: [(Box<_>, Box<_>); 4] =
587+
[(box 0, box 0), (box 0, box 0),
588+
(box 0, box 0), (box 0, box 0)];
586589
let mut i = 0;
587590
v.iter().rposition(|_elt| {
588591
if i == 2 {

src/librustc/middle/const_eval.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
7979
None => {}
8080
}
8181
let expr_id = match csearch::maybe_get_item_ast(tcx, enum_def,
82-
box |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) {
82+
Box::new(|a, b, c, d| astencode::decode_inlined_item(a, b, c, d))) {
8383
csearch::FoundAst::Found(&ast::IIItem(ref item)) => match item.node {
8484
ast::ItemEnum(ast::EnumDef { ref variants }, _) => {
8585
// 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)
119119
None => {}
120120
}
121121
let expr_id = match csearch::maybe_get_item_ast(tcx, def_id,
122-
box |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) {
122+
Box::new(|a, b, c, d| astencode::decode_inlined_item(a, b, c, d))) {
123123
csearch::FoundAst::Found(&ast::IIItem(ref item)) => match item.node {
124124
ast::ItemConst(_, ref const_expr) => Some(const_expr.id),
125125
_ => None

src/librustc/plugin/registry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a> Registry<'a> {
9999
/// It builds for you a `NormalTT` that calls `expander`,
100100
/// and also takes care of interning the macro's name.
101101
pub fn register_macro(&mut self, name: &str, expander: MacroExpanderFn) {
102-
self.register_syntax_extension(token::intern(name), NormalTT(box expander, None));
102+
self.register_syntax_extension(token::intern(name), NormalTT(Box::new(expander), None));
103103
}
104104

105105
/// Register a compiler lint pass.

src/librustc_trans/trans/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2969,7 +2969,7 @@ pub fn write_metadata(cx: &SharedCrateContext, krate: &ast::Crate) -> Vec<u8> {
29692969
}
29702970

29712971
let encode_inlined_item: encoder::EncodeInlinedItem =
2972-
box |ecx, rbml_w, ii| astencode::encode_inlined_item(ecx, rbml_w, ii);
2972+
Box::new(|ecx, rbml_w, ii| astencode::encode_inlined_item(ecx, rbml_w, ii));
29732973

29742974
let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
29752975
let metadata = encoder::encode_metadata(encode_parms, krate);

src/librustc_trans/trans/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
4040
let csearch_result =
4141
csearch::maybe_get_item_ast(
4242
ccx.tcx(), fn_id,
43-
box |a,b,c,d| astencode::decode_inlined_item(a, b, c, d));
43+
Box::new(|a,b,c,d| astencode::decode_inlined_item(a, b, c, d)));
4444

4545
let inline_def = match csearch_result {
4646
csearch::FoundAst::NotFound => {

src/librustc_typeck/check/callee.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ fn try_overloaded_call_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
152152
&closure_ty.sig).0;
153153
fcx.record_deferred_call_resolution(
154154
def_id,
155-
box CallResolution {call_expr: call_expr,
156-
callee_expr: callee_expr,
157-
adjusted_ty: adjusted_ty,
158-
autoderefref: autoderefref,
159-
fn_sig: fn_sig.clone(),
160-
closure_def_id: def_id});
155+
Box::new(CallResolution {call_expr: call_expr,
156+
callee_expr: callee_expr,
157+
adjusted_ty: adjusted_ty,
158+
autoderefref: autoderefref,
159+
fn_sig: fn_sig.clone(),
160+
closure_def_id: def_id}));
161161
return Some(CallStep::DeferredClosure(fn_sig));
162162
}
163163
}

src/libstd/old_io/stdio.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,9 @@ mod tests {
547547

548548
let (tx, rx) = channel();
549549
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
550+
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
550551
let _t = thread::spawn(move|| {
551-
set_stdout(box w);
552+
set_stdout(Box::new(w));
552553
println!("hello!");
553554
});
554555
assert_eq!(r.read_to_string().unwrap(), "hello!\n");
@@ -560,8 +561,9 @@ mod tests {
560561

561562
let (tx, rx) = channel();
562563
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
564+
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
563565
let _t = thread::spawn(move || -> () {
564-
set_stderr(box w);
566+
set_stderr(Box::new(w));
565567
panic!("my special message");
566568
});
567569
let s = r.read_to_string().unwrap();

src/libstd/old_io/timer.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
1616
// FIXME: These functions take Durations but only pass ms to the backend impls.
1717

18+
use boxed::Box;
1819
use sync::mpsc::{Receiver, Sender, channel};
1920
use time::Duration;
2021
use old_io::IoResult;
@@ -143,7 +144,7 @@ impl Timer {
143144
let (tx, rx) = channel();
144145
// Short-circuit the timer backend for 0 duration
145146
if in_ms_u64(duration) != 0 {
146-
self.inner.oneshot(in_ms_u64(duration), box TimerCallback { tx: tx });
147+
self.inner.oneshot(in_ms_u64(duration), Box::new(TimerCallback { tx: tx }));
147148
} else {
148149
tx.send(()).unwrap();
149150
}
@@ -204,7 +205,7 @@ impl Timer {
204205
// not clear what use a 0ms period is anyway...
205206
let ms = if ms == 0 { 1 } else { ms };
206207
let (tx, rx) = channel();
207-
self.inner.period(ms, box TimerCallback { tx: tx });
208+
self.inner.period(ms, Box::new(TimerCallback { tx: tx }));
208209
return rx
209210
}
210211
}

src/libstd/rt/unwind.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn rust_panic(cause: Box<Any + Send + 'static>) -> ! {
166166
rtdebug!("begin_unwind()");
167167

168168
unsafe {
169-
let exception = box Exception {
169+
let exception: Box<_> = box Exception {
170170
uwe: uw::_Unwind_Exception {
171171
exception_class: rust_exception_class(),
172172
exception_cleanup: exception_cleanup,
@@ -506,7 +506,7 @@ pub fn begin_unwind_fmt(msg: fmt::Arguments, file_line: &(&'static str, uint)) -
506506

507507
let mut s = String::new();
508508
let _ = write!(&mut s, "{}", msg);
509-
begin_unwind_inner(box s, file_line)
509+
begin_unwind_inner(Box::new(s), file_line)
510510
}
511511

512512
/// 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)) ->
521521
// panicking.
522522

523523
// see below for why we do the `Any` coercion here.
524-
begin_unwind_inner(box msg, file_line)
524+
begin_unwind_inner(Box::new(msg), file_line)
525525
}
526526

527527
/// The core of the unwinding.

src/libstd/thunk.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'a,A,R> Thunk<'a,A,R> {
3333
where F : FnOnce(A) -> R, F : Send + 'a
3434
{
3535
Thunk {
36-
invoke: box func
36+
invoke: Box::<F>::new(func)
3737
}
3838
}
3939

src/libsyntax/diagnostic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub fn mk_span_handler(handler: Handler, cm: codemap::CodeMap) -> SpanHandler {
223223
pub fn default_handler(color_config: ColorConfig,
224224
registry: Option<diagnostics::registry::Registry>,
225225
can_emit_warnings: bool) -> Handler {
226-
mk_handler(can_emit_warnings, box EmitterWriter::stderr(color_config, registry))
226+
mk_handler(can_emit_warnings, Box::new(EmitterWriter::stderr(color_config, registry)))
227227
}
228228

229229
pub fn mk_handler(can_emit_warnings: bool, e: Box<Emitter + Send>) -> Handler {
@@ -352,11 +352,11 @@ impl EmitterWriter {
352352
if use_color {
353353
let dst = match term::stderr() {
354354
Some(t) => Terminal(t),
355-
None => Raw(box stderr),
355+
None => Raw(Box::new(stderr)),
356356
};
357357
EmitterWriter { dst: dst, registry: registry }
358358
} else {
359-
EmitterWriter { dst: Raw(box stderr), registry: registry }
359+
EmitterWriter { dst: Raw(Box::new(stderr)), registry: registry }
360360
}
361361
}
362362

src/libsyntax/ext/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>)
465465
-> SyntaxEnv {
466466
// utility function to simplify creating NormalTT syntax extensions
467467
fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
468-
NormalTT(box f, None)
468+
NormalTT(Box::new(f), None)
469469
}
470470

471471
let mut syntax_expanders = SyntaxEnv::new();
@@ -489,9 +489,9 @@ fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>)
489489
builtin_normal_expander(
490490
ext::log_syntax::expand_syntax_ext));
491491
syntax_expanders.insert(intern("derive"),
492-
Decorator(box ext::deriving::expand_meta_derive));
492+
Decorator(Box::new(ext::deriving::expand_meta_derive)));
493493
syntax_expanders.insert(intern("deriving"),
494-
Decorator(box ext::deriving::expand_deprecated_deriving));
494+
Decorator(Box::new(ext::deriving::expand_deprecated_deriving)));
495495

496496
if ecfg.enable_quotes() {
497497
// Quasi-quoting expanders

src/libsyntax/ext/deriving/clone.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ pub fn expand_deriving_clone<F>(cx: &mut ExtCtxt,
4040
args: Vec::new(),
4141
ret_ty: Self_,
4242
attributes: attrs,
43-
combine_substructure: combine_substructure(box |c, s, sub| {
43+
combine_substructure: combine_substructure(Box::new(|c, s, sub| {
4444
cs_clone("Clone", c, s, sub)
45-
}),
45+
})),
4646
}
4747
),
4848
associated_types: Vec::new(),

src/libsyntax/ext/deriving/cmp/eq.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
4040
cx.expr_binary(span, ast::BiAnd, subexpr, eq)
4141
},
4242
cx.expr_bool(span, true),
43-
box |cx, span, _, _| cx.expr_bool(span, false),
43+
Box::new(|cx, span, _, _| cx.expr_bool(span, false)),
4444
cx, span, substr)
4545
}
4646
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,
5757
cx.expr_binary(span, ast::BiOr, subexpr, eq)
5858
},
5959
cx.expr_bool(span, false),
60-
box |cx, span, _, _| cx.expr_bool(span, true),
60+
Box::new(|cx, span, _, _| cx.expr_bool(span, true)),
6161
cx, span, substr)
6262
}
6363

@@ -72,9 +72,9 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
7272
args: vec!(borrowed_self()),
7373
ret_ty: Literal(path_local!(bool)),
7474
attributes: attrs,
75-
combine_substructure: combine_substructure(box |a, b, c| {
75+
combine_substructure: combine_substructure(Box::new(|a, b, c| {
7676
$f(a, b, c)
77-
})
77+
}))
7878
}
7979
} }
8080
}

src/libsyntax/ext/deriving/cmp/ord.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
3838
args: vec!(borrowed_self()),
3939
ret_ty: Literal(path_local!(bool)),
4040
attributes: attrs,
41-
combine_substructure: combine_substructure(box |cx, span, substr| {
41+
combine_substructure: combine_substructure(Box::new(|cx, span, substr| {
4242
cs_op($op, $equal, cx, span, substr)
43-
})
43+
}))
4444
}
4545
} }
4646
}
@@ -61,9 +61,9 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
6161
args: vec![borrowed_self()],
6262
ret_ty: ret_ty,
6363
attributes: attrs,
64-
combine_substructure: combine_substructure(box |cx, span, substr| {
64+
combine_substructure: combine_substructure(Box::new(|cx, span, substr| {
6565
cs_partial_cmp(cx, span, substr)
66-
})
66+
}))
6767
};
6868

6969
let trait_def = TraitDef {
@@ -175,13 +175,13 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
175175
cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
176176
},
177177
equals_expr.clone(),
178-
box |cx, span, (self_args, tag_tuple), _non_self_args| {
178+
Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
179179
if self_args.len() != 2 {
180180
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
181181
} else {
182182
some_ordering_collapsed(cx, span, PartialCmpOp, tag_tuple)
183183
}
184-
},
184+
}),
185185
cx, span, substr)
186186
}
187187

@@ -223,7 +223,7 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
223223
cx.expr_binary(span, ast::BiOr, cmp, and)
224224
},
225225
cx.expr_bool(span, equal),
226-
box |cx, span, (self_args, tag_tuple), _non_self_args| {
226+
Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
227227
if self_args.len() != 2 {
228228
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
229229
} else {
@@ -233,6 +233,6 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
233233
};
234234
some_ordering_collapsed(cx, span, op, tag_tuple)
235235
}
236-
},
236+
}),
237237
cx, span, substr)
238238
}

src/libsyntax/ext/deriving/cmp/totaleq.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ pub fn expand_deriving_totaleq<F>(cx: &mut ExtCtxt,
3232
let block = cx.block(span, stmts, None);
3333
cx.expr_block(block)
3434
},
35-
box |cx, sp, _, _| cx.span_bug(sp, "non matching enums in derive(Eq)?"),
35+
Box::new(|cx, sp, _, _| {
36+
cx.span_bug(sp, "non matching enums in derive(Eq)?") }),
3637
cx,
3738
span,
3839
substr)
@@ -57,9 +58,9 @@ pub fn expand_deriving_totaleq<F>(cx: &mut ExtCtxt,
5758
args: vec!(),
5859
ret_ty: nil_ty(),
5960
attributes: attrs,
60-
combine_substructure: combine_substructure(box |a, b, c| {
61+
combine_substructure: combine_substructure(Box::new(|a, b, c| {
6162
cs_total_eq_assert(a, b, c)
62-
})
63+
}))
6364
}
6465
),
6566
associated_types: Vec::new(),

src/libsyntax/ext/deriving/cmp/totalord.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ pub fn expand_deriving_totalord<F>(cx: &mut ExtCtxt,
4141
args: vec!(borrowed_self()),
4242
ret_ty: Literal(path_std!(cx, core::cmp::Ordering)),
4343
attributes: attrs,
44-
combine_substructure: combine_substructure(box |a, b, c| {
44+
combine_substructure: combine_substructure(Box::new(|a, b, c| {
4545
cs_cmp(a, b, c)
46-
}),
46+
})),
4747
}
4848
),
4949
associated_types: Vec::new(),
@@ -131,12 +131,12 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
131131
cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
132132
},
133133
cx.expr_path(equals_path.clone()),
134-
box |cx, span, (self_args, tag_tuple), _non_self_args| {
134+
Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
135135
if self_args.len() != 2 {
136136
cx.span_bug(span, "not exactly 2 arguments in `derives(Ord)`")
137137
} else {
138138
ordering_collapsed(cx, span, tag_tuple)
139139
}
140-
},
140+
}),
141141
cx, span, substr)
142142
}

0 commit comments

Comments
 (0)