Skip to content

Prepare runway for RFC 809 (overloaded box/placement-in) #23002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/trpl/pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ fn main() {
one_hundred: 100,
});

let y = box foo(x);
let y: Box<BigStruct> = box foo(x);
}
```

Expand Down
4 changes: 3 additions & 1 deletion src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
//! }
//! ```

use boxed::Box;

use core::prelude::*;

use core::atomic;
Expand Down Expand Up @@ -170,7 +172,7 @@ impl<T> Arc<T> {
pub fn new(data: T) -> Arc<T> {
// Start the weak pointer count as 1 which is the weak pointer that's
// held by all the strong pointers (kinda), see std/rc.rs for more info
let x = box ArcInner {
let x: Box<_> = box ArcInner {
strong: atomic::AtomicUsize::new(1),
weak: atomic::AtomicUsize::new(1),
data: data,
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl<T> Box<T> {
/// let x = Box::new(5);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline(always)]
pub fn new(x: T) -> Box<T> {
box x
}
Expand Down Expand Up @@ -156,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")]
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ mod test {
extern crate test;
use self::test::Bencher;
use core::ptr::PtrExt;
use boxed::Box;
use heap;

#[test]
Expand All @@ -404,7 +405,7 @@ mod test {
#[bench]
fn alloc_owned_small(b: &mut Bencher) {
b.iter(|| {
box 10
let _: Box<_> = box 10;
})
}
}
6 changes: 6 additions & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,15 @@ pub mod heap;

// Primitive types using the heaps above

// Need to conditionally define the mod from `boxed.rs` to avoid
// duplicating the lang-items when building in test cfg; but also need
// to allow code to have `use boxed::HEAP;`
// and `use boxed::Box;` declarations.
#[cfg(not(test))]
pub mod boxed;
#[cfg(test)]
mod boxed { pub use std::boxed::{Box, HEAP}; }
#[cfg(test)]
mod boxed_test;
pub mod arc;
pub mod rc;
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ impl<T> RcBoxPtr<T> for Weak<T> {
#[cfg(test)]
mod tests {
use super::{Rc, Weak, weak_count, strong_count};
use std::boxed::Box;
use std::cell::RefCell;
use std::option::Option;
use std::option::Option::{Some, None};
Expand Down Expand Up @@ -826,7 +827,7 @@ mod tests {

#[test]
fn test_destructor() {
let x = Rc::new(box 5);
let x: Rc<Box<_>> = Rc::new(box 5);
assert_eq!(**x, 5);
}

Expand Down
8 changes: 4 additions & 4 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,11 @@ mod tests {
#[bench]
pub fn bench_copy_nonarena(b: &mut Bencher) {
b.iter(|| {
box Point {
let _: Box<_> = box Point {
x: 1,
y: 2,
z: 3,
}
};
})
}

Expand Down Expand Up @@ -634,10 +634,10 @@ mod tests {
#[bench]
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
b.iter(|| {
box Noncopy {
let _: Box<_> = box Noncopy {
string: "hello world".to_string(),
array: vec!( 1, 2, 3, 4, 5 ),
}
};
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ mod tests {

#[test]
fn test_push_unique() {
let mut heap = BinaryHeap::from_vec(vec![box 2, box 4, box 9]);
let mut heap = BinaryHeap::<Box<_>>::from_vec(vec![box 2, box 4, box 9]);
assert_eq!(heap.len(), 3);
assert!(*heap.peek().unwrap() == box 9);
heap.push(box 11);
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ mod tests {

#[test]
fn test_basic() {
let mut m = LinkedList::new();
let mut m = LinkedList::<Box<_>>::new();
assert_eq!(m.pop_front(), None);
assert_eq!(m.pop_back(), None);
assert_eq!(m.pop_front(), None);
Expand Down
26 changes: 14 additions & 12 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order

#[cfg(test)]
mod tests {
use alloc::boxed::Box;
use core::cmp::Ordering::{Greater, Less, Equal};
use core::prelude::{Some, None, Clone};
use core::prelude::{Iterator, IteratorExt};
Expand Down Expand Up @@ -1799,7 +1800,7 @@ mod tests {
#[test]
fn test_swap_remove_noncopyable() {
// Tests that we don't accidentally run destructors twice.
let mut v = Vec::new();
let mut v: Vec<Box<_>> = Vec::new();
v.push(box 0u8);
v.push(box 0u8);
v.push(box 0u8);
Expand Down Expand Up @@ -1828,7 +1829,7 @@ mod tests {

#[test]
fn test_truncate() {
let mut v = vec![box 6,box 5,box 4];
let mut v: Vec<Box<_>> = vec![box 6,box 5,box 4];
v.truncate(1);
let v = v;
assert_eq!(v.len(), 1);
Expand All @@ -1838,7 +1839,7 @@ mod tests {

#[test]
fn test_clear() {
let mut v = vec![box 6,box 5,box 4];
let mut v: Vec<Box<_>> = vec![box 6,box 5,box 4];
v.clear();
assert_eq!(v.len(), 0);
// If the unsafe block didn't drop things properly, we blow up here.
Expand All @@ -1863,11 +1864,11 @@ mod tests {

#[test]
fn test_dedup_unique() {
let mut v0 = vec![box 1, box 1, box 2, box 3];
let mut v0: Vec<Box<_>> = vec![box 1, box 1, box 2, box 3];
v0.dedup();
let mut v1 = vec![box 1, box 2, box 2, box 3];
let mut v1: Vec<Box<_>> = vec![box 1, box 2, box 2, box 3];
v1.dedup();
let mut v2 = vec![box 1, box 2, box 3, box 3];
let mut v2: Vec<Box<_>> = vec![box 1, box 2, box 3, box 3];
v2.dedup();
/*
* If the boxed pointers were leaked or otherwise misused, valgrind
Expand All @@ -1877,11 +1878,11 @@ mod tests {

#[test]
fn test_dedup_shared() {
let mut v0 = vec![box 1, box 1, box 2, box 3];
let mut v0: Vec<Box<_>> = vec![box 1, box 1, box 2, box 3];
v0.dedup();
let mut v1 = vec![box 1, box 2, box 2, box 3];
let mut v1: Vec<Box<_>> = vec![box 1, box 2, box 2, box 3];
v1.dedup();
let mut v2 = vec![box 1, box 2, box 3, box 3];
let mut v2: Vec<Box<_>> = vec![box 1, box 2, box 3, box 3];
v2.dedup();
/*
* If the pointers were leaked or otherwise misused, valgrind and/or
Expand Down Expand Up @@ -2254,8 +2255,9 @@ mod tests {
#[test]
#[should_fail]
fn test_permute_fail() {
let v = [(box 0, Rc::new(0)), (box 0, Rc::new(0)),
(box 0, Rc::new(0)), (box 0, Rc::new(0))];
let v: [(Box<_>, Rc<_>); 4] =
[(box 0, Rc::new(0)), (box 0, Rc::new(0)),
(box 0, Rc::new(0)), (box 0, Rc::new(0))];
let mut i = 0;
for _ in v.permutations() {
if i == 2 {
Expand Down Expand Up @@ -2849,7 +2851,7 @@ mod tests {

#[test]
fn test_to_vec() {
let xs = box [1, 2, 3];
let xs: Box<_> = box [1, 2, 3];
let ys = xs.to_vec();
assert_eq!(ys, [1, 2, 3]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2130,8 +2130,8 @@ mod tests {
#[test]
fn test_clone_from() {
let mut v = vec!();
let three = vec!(box 1, box 2, box 3);
let two = vec!(box 4, box 5);
let three: Vec<Box<_>> = vec!(box 1, box 2, box 3);
let two: Vec<Box<_>> = vec!(box 4, box 5);
// zero, long
v.clone_from(&three);
assert_eq!(v, three);
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ mod test_map {

#[test]
fn test_move_iter() {
let mut m = VecMap::new();
let mut m: VecMap<Box<_>> = VecMap::new();
m.insert(1, box 2);
let mut called = false;
for (k, v) in m {
Expand Down
2 changes: 1 addition & 1 deletion src/libcoretest/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn any_downcast_ref() {
#[test]
fn any_downcast_mut() {
let mut a = 5_usize;
let mut b = box 7_usize;
let mut b: Box<_> = box 7_usize;

let a_r = &mut a as &mut Any;
let tmp: &mut uint = &mut *b;
Expand Down
3 changes: 2 additions & 1 deletion src/libcoretest/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]>
Expand Down
11 changes: 7 additions & 4 deletions src/libcoretest/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/libcoretest/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use core::clone::Clone;
#[test]
fn test_get_ptr() {
unsafe {
let x = box 0;
let x: Box<_> = box 0;
let addr_x: *const int = mem::transmute(&*x);
let opt = Some(x);
let y = opt.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/plugin/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ mod tests {

let tests = wikipedia_tests;

let mut sh = box Sha256::new();
let mut sh: Box<_> = box Sha256::new();

test_hash(&mut *sh, &tests);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_typeck/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
Loading