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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 7 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 3 additions & 2 deletions
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
}

0 commit comments

Comments
 (0)