Auto merge of #23002 - pnkfelix:fsk-box-place-runway, r=nikomatsakis

Runway for RFC 809 (overloaded box/placement-in) by adding type annotations or explicit calls to `Box::new` where I found it necessary on PR #22086.

I have broken this up into more than one PR because the entire commit chain (see PR #22086) is long, widespread and unwieldy to rebase frequently.

To my knowledge this is not a breaking change.  Also, there is in principle nothing stopping someone from reverting some/all of these annotations, since without the rest of the commit chain in #22086, the associated code would continue to compile.

All I can do is ask: Try to discourage others from removing seemingly "unnecessary" uses of the `Box` type or the `Box::new()` function, until the rest of RFC 809 lands.
This commit is contained in:
bors 2015-03-03 20:17:08 +00:00
commit fed12499e7
283 changed files with 632 additions and 638 deletions

View File

@ -709,7 +709,7 @@ fn main() {
one_hundred: 100,
});
let y = box foo(x);
let y: Box<BigStruct> = box foo(x);
}
```

View File

@ -69,6 +69,8 @@
//! }
//! ```
use boxed::Box;
use core::prelude::*;
use core::atomic;
@ -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,

View File

@ -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
}
@ -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")]

View File

@ -387,6 +387,7 @@ mod test {
extern crate test;
use self::test::Bencher;
use core::ptr::PtrExt;
use boxed::Box;
use heap;
#[test]
@ -404,7 +405,7 @@ mod test {
#[bench]
fn alloc_owned_small(b: &mut Bencher) {
b.iter(|| {
box 10
let _: Box<_> = box 10;
})
}
}

View File

@ -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;

View File

@ -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};
@ -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);
}

View File

@ -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,
}
};
})
}
@ -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 ),
}
};
})
}

View File

@ -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);

View File

@ -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);

View File

@ -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};
@ -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);
@ -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);
@ -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.
@ -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
@ -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
@ -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 {
@ -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]);
}

View File

@ -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);

View File

@ -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 {

View File

@ -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;

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

@ -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();

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

@ -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);
}

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

@ -323,22 +323,22 @@ impl<'a> Parser<'a> {
}
fn read_ip_addr(&mut self) -> Option<IpAddr> {
let ipv4_addr = |p: &mut Parser| p.read_ipv4_addr();
let ipv6_addr = |p: &mut Parser| p.read_ipv6_addr();
self.read_or(&mut [box ipv4_addr, box ipv6_addr])
let ipv4_addr: Box<_> = box |p: &mut Parser| p.read_ipv4_addr();
let ipv6_addr: Box<_> = box |p: &mut Parser| p.read_ipv6_addr();
self.read_or(&mut [ipv4_addr, ipv6_addr])
}
fn read_socket_addr(&mut self) -> Option<SocketAddr> {
let ip_addr = |p: &mut Parser| {
let ipv4_p = |p: &mut Parser| p.read_ip_addr();
let ipv6_p = |p: &mut Parser| {
let ipv4_p: Box<_> = box |p: &mut Parser| p.read_ip_addr();
let ipv6_p: Box<_> = box |p: &mut Parser| {
let open_br = |p: &mut Parser| p.read_given_char('[');
let ip_addr = |p: &mut Parser| p.read_ipv6_addr();
let clos_br = |p: &mut Parser| p.read_given_char(']');
p.read_seq_3::<char, IpAddr, char, _, _, _>(open_br, ip_addr, clos_br)
.map(|t| match t { (_, ip, _) => ip })
};
p.read_or(&mut [box ipv4_p, box ipv6_p])
p.read_or(&mut [ipv4_p, ipv6_p])
};
let colon = |p: &mut Parser| p.read_given_char(':');
let port = |p: &mut Parser| p.read_number(10, 5, 0x10000).map(|n| n as u16);

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

@ -1044,13 +1044,13 @@ mod test {
#[test]
fn drop_full() {
let (tx, _rx) = channel();
let (tx, _rx) = channel::<Box<int>>();
tx.send(box 1).unwrap();
}
#[test]
fn drop_full_shared() {
let (tx, _rx) = channel();
let (tx, _rx) = channel::<Box<int>>();
drop(tx.clone());
drop(tx.clone());
tx.send(box 1).unwrap();
@ -1389,7 +1389,7 @@ mod test {
#[test]
fn oneshot_multi_thread_send_recv_stress() {
for _ in 0..stress_factor() {
let (tx, rx) = channel();
let (tx, rx) = channel::<Box<int>>();
let _t = thread::spawn(move|| {
tx.send(box 10).unwrap();
});
@ -1566,7 +1566,7 @@ mod sync_tests {
#[test]
fn drop_full() {
let (tx, _rx) = sync_channel(1);
let (tx, _rx) = sync_channel::<Box<int>>(1);
tx.send(box 1).unwrap();
}

View File

@ -164,7 +164,7 @@ mod tests {
#[test]
fn test_full() {
let q = Queue::new();
let q: Queue<Box<_>> = Queue::new();
q.push(box 1);
q.push(box 2);
}

View File

@ -289,7 +289,7 @@ mod test {
#[test]
fn drop_full() {
unsafe {
let q = Queue::new(0);
let q: Queue<Box<_>> = Queue::new(0);
q.push(box 1);
q.push(box 2);
}

View File

@ -804,7 +804,7 @@ mod test {
fn avoid_copying_the_body<F>(spawnfn: F) where F: FnOnce(Thunk<'static>) {
let (tx, rx) = channel();
let x = box 1;
let x: Box<_> = box 1;
let x_in_parent = (&*x) as *const i32 as usize;
spawnfn(Thunk::new(move|| {

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

@ -146,7 +146,7 @@ impl Table {
fn search_remainder<C:TableCallback>(item: &mut Entry, key: Code, c: C) {
match item.next {
None => {
let mut entry = box Entry {
let mut entry: Box<_> = box Entry {
code: key,
count: 0,
next: None,
@ -170,7 +170,7 @@ impl Table {
{
if self.items[index as usize].is_none() {
let mut entry = box Entry {
let mut entry: Box<_> = box Entry {
code: key,
count: 0,
next: None,

View File

@ -124,7 +124,7 @@ impl Sudoku {
fn next_color(&mut self, row: u8, col: u8, start_color: u8) -> bool {
if start_color < 10u8 {
// colors not yet used
let mut avail = box Colors::new(start_color);
let mut avail: Box<_> = box Colors::new(start_color);
// drop colors already in use in neighbourhood
self.drop_colors(&mut *avail, row, col);

View File

@ -16,7 +16,7 @@ struct Foo(Box<isize>, isize);
struct Bar(isize, isize);
fn main() {
let x = (box 1, 2);
let x: (Box<_>, _) = (box 1, 2);
let r = &x.0;
let y = x; //~ ERROR cannot move out of `x` because it is borrowed

View File

@ -23,7 +23,7 @@ fn add(v: &usize, w: usize) -> usize {
}
fn implicit() {
let mut a = box 1;
let mut a: Box<_> = box 1;
// Note the danger here:
//
@ -36,7 +36,7 @@ fn implicit() {
}
fn explicit() {
let mut a = box 1;
let mut a: Box<_> = box 1;
add(
&*a,
rewrite(&mut a)); //~ ERROR cannot borrow

View File

@ -23,7 +23,7 @@ fn add(v: &usize, w: Box<usize>) -> usize {
}
fn implicit() {
let mut a = box 1;
let mut a: Box<_> = box 1;
// Note the danger here:
//
@ -36,7 +36,7 @@ fn implicit() {
}
fn explicit() {
let mut a = box 1;
let mut a: Box<_> = box 1;
add(
&*a,
a); //~ ERROR cannot move

View File

@ -18,7 +18,7 @@ impl A {
}
pub fn main() {
let a = box A;
let a: Box<_> = box A;
a.foo();
//~^ ERROR cannot borrow immutable `Box` content `*a` as mutable
}

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

@ -31,100 +31,100 @@ struct D {
}
fn copy_after_move() {
let a = box A { x: box 0, y: 1 };
let a: Box<_> = box A { x: box 0, y: 1 };
let _x = a.x;
let _y = a.y; //~ ERROR use of moved
//~^^ NOTE `a` moved here (through moving `a.x`)
}
fn move_after_move() {
let a = box B { x: box 0, y: box 1 };
let a: Box<_> = box B { x: box 0, y: box 1 };
let _x = a.x;
let _y = a.y; //~ ERROR use of moved
//~^^ NOTE `a` moved here (through moving `a.x`)
}
fn borrow_after_move() {
let a = box A { x: box 0, y: 1 };
let a: Box<_> = box A { x: box 0, y: 1 };
let _x = a.x;
let _y = &a.y; //~ ERROR use of moved
//~^^ NOTE `a` moved here (through moving `a.x`)
}
fn move_after_borrow() {
let a = box B { x: box 0, y: box 1 };
let a: Box<_> = box B { x: box 0, y: box 1 };
let _x = &a.x;
let _y = a.y; //~ ERROR cannot move
}
fn copy_after_mut_borrow() {
let mut a = box A { x: box 0, y: 1 };
let mut a: Box<_> = box A { x: box 0, y: 1 };
let _x = &mut a.x;
let _y = a.y; //~ ERROR cannot use
}
fn move_after_mut_borrow() {
let mut a = box B { x: box 0, y: box 1 };
let mut a: Box<_> = box B { x: box 0, y: box 1 };
let _x = &mut a.x;
let _y = a.y; //~ ERROR cannot move
}
fn borrow_after_mut_borrow() {
let mut a = box A { x: box 0, y: 1 };
let mut a: Box<_> = box A { x: box 0, y: 1 };
let _x = &mut a.x;
let _y = &a.y; //~ ERROR cannot borrow
}
fn mut_borrow_after_borrow() {
let mut a = box A { x: box 0, y: 1 };
let mut a: Box<_> = box A { x: box 0, y: 1 };
let _x = &a.x;
let _y = &mut a.y; //~ ERROR cannot borrow
}
fn copy_after_move_nested() {
let a = box C { x: box A { x: box 0, y: 1 }, y: 2 };
let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
let _x = a.x.x;
let _y = a.y; //~ ERROR use of collaterally moved
}
fn move_after_move_nested() {
let a = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
let _x = a.x.x;
let _y = a.y; //~ ERROR use of collaterally moved
}
fn borrow_after_move_nested() {
let a = box C { x: box A { x: box 0, y: 1 }, y: 2 };
let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
let _x = a.x.x;
let _y = &a.y; //~ ERROR use of collaterally moved
}
fn move_after_borrow_nested() {
let a = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
let _x = &a.x.x;
let _y = a.y; //~ ERROR cannot move
}
fn copy_after_mut_borrow_nested() {
let mut a = box C { x: box A { x: box 0, y: 1 }, y: 2 };
let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
let _x = &mut a.x.x;
let _y = a.y; //~ ERROR cannot use
}
fn move_after_mut_borrow_nested() {
let mut a = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
let mut a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
let _x = &mut a.x.x;
let _y = a.y; //~ ERROR cannot move
}
fn borrow_after_mut_borrow_nested() {
let mut a = box C { x: box A { x: box 0, y: 1 }, y: 2 };
let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
let _x = &mut a.x.x;
let _y = &a.y; //~ ERROR cannot borrow
}
fn mut_borrow_after_borrow_nested() {
let mut a = box C { x: box A { x: box 0, y: 1 }, y: 2 };
let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
let _x = &a.x.x;
let _y = &mut a.y; //~ ERROR cannot borrow
}

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

@ -52,7 +52,7 @@ fn e() {
}
fn f() {
let mut x = box 3;
let mut x: Box<_> = box 3;
let c1 = || get(&*x);
*x = 5; //~ ERROR cannot assign
}
@ -62,7 +62,7 @@ fn g() {
f: Box<isize>
}
let mut x = box Foo { f: box 3 };
let mut x: Box<_> = box Foo { f: box 3 };
let c1 = || get(&*x.f);
*x.f = 5; //~ ERROR cannot assign to `*x.f`
}
@ -72,7 +72,7 @@ fn h() {
f: Box<isize>
}
let mut x = box Foo { f: box 3 };
let mut x: Box<_> = box Foo { f: box 3 };
let c1 = || get(&*x.f);
let c2 = || *x.f = 5; //~ ERROR cannot borrow `x` as mutable
}

View File

@ -50,7 +50,7 @@ fn g() {
f: Box<isize>
}
let mut x = box Foo { f: box 3 };
let mut x: Box<_> = box Foo { f: box 3 };
let c1 = to_fn_mut(|| set(&mut *x.f));
let c2 = to_fn_mut(|| set(&mut *x.f));
//~^ ERROR cannot borrow `x` as mutable more than once

View File

@ -25,7 +25,7 @@ impl Drop for Foo {
}
fn main() {
let mut ptr = box Foo { x: 0 };
let mut ptr: Box<_> = box Foo { x: 0 };
let mut test = |foo: &Foo| {
ptr = box Foo { x: ptr.x + 1 };
};

View File

@ -28,7 +28,7 @@ fn main() {
for &a in &f.a { //~ ERROR cannot move out
}
let x = Some(box 1);
let x: Option<Box<_>> = Some(box 1);
for &a in x.iter() { //~ ERROR cannot move out
}
}

View File

@ -18,7 +18,7 @@ struct B<'a> { a: Box<&'a mut isize> }
fn borrow_in_var_from_var() {
let mut x: isize = 1;
let y = box &mut x;
let y: Box<_> = box &mut x;
let p = &y;
let q = &***p;
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
@ -28,7 +28,7 @@ fn borrow_in_var_from_var() {
fn borrow_in_var_from_field() {
let mut x = A { a: 1 };
let y = box &mut x.a;
let y: Box<_> = box &mut x.a;
let p = &y;
let q = &***p;
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed

View File

@ -11,7 +11,7 @@
#![feature(box_syntax)]
fn main() {
let x = Some(box 1);
let x: Option<Box<_>> = Some(box 1);
match x {
Some(ref _y) => {
let _a = x; //~ ERROR cannot move

View File

@ -11,7 +11,7 @@
#![feature(box_syntax)]
fn main() {
let x = Some(box 1);
let x: Option<Box<_>> = Some(box 1);
match x {
Some(ref y) => {
let _b = *y; //~ ERROR cannot move out

View File

@ -30,7 +30,7 @@ fn pre_freeze_cond() {
// In this instance, the freeze is conditional and starts before
// the mut borrow.
let mut v = box 3;
let mut v: Box<_> = box 3;
let _w;
if cond() {
_w = &v;
@ -42,7 +42,7 @@ fn pre_freeze_else() {
// In this instance, the freeze and mut borrow are on separate sides
// of the if.
let mut v = box 3;
let mut v: Box<_> = box 3;
let _w;
if cond() {
_w = &v;

View File

@ -28,7 +28,7 @@ fn inc(v: &mut Box<isize>) {
fn loop_overarching_alias_mut() {
// In this instance, the borrow encompasses the entire loop.
let mut v = box 3;
let mut v: Box<_> = box 3;
let mut x = &mut v;
**x += 1;
loop {
@ -39,7 +39,7 @@ fn loop_overarching_alias_mut() {
fn block_overarching_alias_mut() {
// In this instance, the borrow encompasses the entire closure call.
let mut v = box 3;
let mut v: Box<_> = box 3;
let mut x = &mut v;
for _ in 0..3 {
borrow(&*v); //~ ERROR cannot borrow
@ -50,8 +50,8 @@ fn block_overarching_alias_mut() {
fn loop_aliased_mut() {
// In this instance, the borrow is carried through the loop.
let mut v = box 3;
let mut w = box 4;
let mut v: Box<_> = box 3;
let mut w: Box<_> = box 4;
let mut _x = &w;
loop {
borrow_mut(&mut *v); //~ ERROR cannot borrow
@ -62,8 +62,8 @@ fn loop_aliased_mut() {
fn while_aliased_mut() {
// In this instance, the borrow is carried through the loop.
let mut v = box 3;
let mut w = box 4;
let mut v: Box<_> = box 3;
let mut w: Box<_> = box 4;
let mut _x = &w;
while cond() {
borrow_mut(&mut *v); //~ ERROR cannot borrow
@ -75,8 +75,8 @@ fn while_aliased_mut() {
fn loop_aliased_mut_break() {
// In this instance, the borrow is carried through the loop.
let mut v = box 3;
let mut w = box 4;
let mut v: Box<_> = box 3;
let mut w: Box<_> = box 4;
let mut _x = &w;
loop {
borrow_mut(&mut *v);
@ -89,8 +89,8 @@ fn loop_aliased_mut_break() {
fn while_aliased_mut_break() {
// In this instance, the borrow is carried through the loop.
let mut v = box 3;
let mut w = box 4;
let mut v: Box<_> = box 3;
let mut w: Box<_> = box 4;
let mut _x = &w;
while cond() {
borrow_mut(&mut *v);
@ -101,8 +101,8 @@ fn while_aliased_mut_break() {
}
fn while_aliased_mut_cond(cond: bool, cond2: bool) {
let mut v = box 3;
let mut w = box 4;
let mut v: Box<_> = box 3;
let mut w: Box<_> = box 4;
let mut x = &mut w;
while cond {
**x += 1;

View File

@ -29,7 +29,7 @@ fn inc(v: &mut Box<isize>) {
fn pre_freeze() {
// In this instance, the freeze starts before the mut borrow.
let mut v = box 3;
let mut v: Box<_> = box 3;
let _w = &v;
borrow_mut(&mut *v); //~ ERROR cannot borrow
}
@ -37,7 +37,7 @@ fn pre_freeze() {
fn post_freeze() {
// In this instance, the const alias starts after the borrow.
let mut v = box 3;
let mut v: Box<_> = box 3;
borrow_mut(&mut *v);
let _w = &v;
}

View File

@ -17,7 +17,7 @@ fn borrow<F>(v: &isize, f: F) where F: FnOnce(&isize) {
}
fn box_imm() {
let v = box 3;
let v: Box<_> = box 3;
let _w = &v;
thread::spawn(move|| {
println!("v={}", *v);
@ -26,7 +26,7 @@ fn box_imm() {
}
fn box_imm_explicit() {
let v = box 3;
let v: Box<_> = box 3;
let _w = &v;
thread::spawn(move|| {
println!("v={}", *v);

View File

@ -15,7 +15,7 @@ fn borrow<F>(v: &isize, f: F) where F: FnOnce(&isize) {
}
fn box_imm() {
let mut v = box 3;
let mut v: Box<_> = box 3;
borrow(&*v,
|w| { //~ ERROR cannot borrow `v` as mutable
v = box 4;

View File

@ -14,7 +14,7 @@ fn to_fn_mut<A,F:FnMut<A>>(f: F) -> F { f }
fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
pub fn main() {
let bar = box 3;
let bar: Box<_> = box 3;
let _g = to_fn_mut(|| {
let _h = to_fn_once(move || -> isize { *bar }); //~ ERROR cannot move out of
});

View File

@ -14,7 +14,7 @@
#![feature(box_syntax)]
fn main() {
let a = box box 2;
let a: Box<Box<_>> = box box 2;
let b = &a;
let z = *a; //~ ERROR: cannot move out of `*a` because it is borrowed

View File

@ -15,7 +15,7 @@ fn call_f<F:FnOnce() -> isize>(f: F) -> isize {
}
fn main() {
let t = box 3;
let t: Box<_> = box 3;
call_f(move|| { *t + 1 });
call_f(move|| { *t + 1 }); //~ ERROR capture of moved value

View File

@ -15,9 +15,9 @@ use std::thread;
fn borrow<T>(_: &T) { }
fn different_vars_after_borrows() {
let x1 = box 1;
let x1: Box<_> = box 1;
let p1 = &x1;
let x2 = box 2;
let x2: Box<_> = box 2;
let p2 = &x2;
thread::spawn(move|| {
drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed
@ -28,9 +28,9 @@ fn different_vars_after_borrows() {
}
fn different_vars_after_moves() {
let x1 = box 1;
let x1: Box<_> = box 1;
drop(x1);
let x2 = box 2;
let x2: Box<_> = box 2;
drop(x2);
thread::spawn(move|| {
drop(x1); //~ ERROR capture of moved value: `x1`
@ -39,7 +39,7 @@ fn different_vars_after_moves() {
}
fn same_var_after_borrow() {
let x = box 1;
let x: Box<_> = box 1;
let p = &x;
thread::spawn(move|| {
drop(x); //~ ERROR cannot move `x` into closure because it is borrowed
@ -49,7 +49,7 @@ fn same_var_after_borrow() {
}
fn same_var_after_move() {
let x = box 1;
let x: Box<_> = box 1;
drop(x);
thread::spawn(move|| {
drop(x); //~ ERROR capture of moved value: `x`

View File

@ -19,7 +19,7 @@ enum cycle {
empty
}
fn main() {
let mut x = box cycle::node(node_ {a: box cycle::empty});
let mut x: Box<_> = box cycle::node(node_ {a: box cycle::empty});
// Create a cycle!
match *x {
cycle::node(ref mut y) => {

View File

@ -25,7 +25,7 @@ impl<T> Index<usize> for MyVec<T> {
}
fn main() {
let v = MyVec { data: vec!(box 1, box 2, box 3) };
let v = MyVec::<Box<_>> { data: vec!(box 1, box 2, box 3) };
let good = &v[0]; // Shouldn't fail here
let bad = v[0];
//~^ ERROR cannot move out of indexed content

View File

@ -13,7 +13,7 @@
fn borrow(_v: &isize) {}
fn local() {
let mut v = box 3;
let mut v: Box<_> = box 3;
borrow(&*v);
}
@ -32,27 +32,27 @@ fn local_recs() {
}
fn aliased_imm() {
let mut v = box 3;
let mut v: Box<_> = box 3;
let _w = &v;
borrow(&*v);
}
fn aliased_mut() {
let mut v = box 3;
let mut v: Box<_> = box 3;
let _w = &mut v;
borrow(&*v); //~ ERROR cannot borrow `*v`
}
fn aliased_other() {
let mut v = box 3;
let mut w = box 4;
let mut v: Box<_> = box 3;
let mut w: Box<_> = box 4;
let _x = &mut w;
borrow(&*v);
}
fn aliased_other_reassign() {
let mut v = box 3;
let mut w = box 4;
let mut v: Box<_> = box 3;
let mut w: Box<_> = box 4;
let mut _x = &mut w;
_x = &mut v;
borrow(&*v); //~ ERROR cannot borrow `*v`

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

@ -11,7 +11,7 @@
#![feature(box_syntax)]
fn main() {
let x = box 1;
let x: Box<_> = box 1;
let f = move|| {
let _a = x;
drop(x);

View File

@ -21,7 +21,7 @@ impl Drop for Foo {
}
fn main() {
let mut ptr = box Foo { x: 0 };
let mut ptr: Box<_> = box Foo { x: 0 };
let mut test = |foo: &Foo| {
println!("access {}", foo.x);
ptr = box Foo { x: ptr.x + 1 };

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

@ -14,7 +14,7 @@ fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
fn main() {
let r = {
let x = box 42;
let x: Box<_> = box 42;
let f = to_fn_once(move|| &x); //~ ERROR: `x` does not live long enough
f()
};

View File

@ -14,7 +14,7 @@ fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
fn do_it(x: &isize) { }
fn main() {
let x = box 22;
let x: Box<_> = box 22;
let f = to_fn_once(move|| do_it(&*x));
to_fn_once(move|| {
f();

View File

@ -13,12 +13,12 @@
struct Foo { a: isize, b: isize }
fn main() {
let mut x = box Foo { a: 1, b: 2 };
let mut x: Box<_> = box Foo { a: 1, b: 2 };
let (a, b) = (&mut x.a, &mut x.b);
//~^ ERROR cannot borrow `x` (here through borrowing `x.b`) as mutable more than once at a time
//~^^ NOTE previous borrow of `x` occurs here (through borrowing `x.a`)
let mut foo = box Foo { a: 1, b: 2 };
let mut foo: Box<_> = box Foo { a: 1, b: 2 };
let (c, d) = (&mut foo.a, &foo.b);
//~^ ERROR cannot borrow `foo` (here through borrowing `foo.b`) as immutable
//~^^ NOTE previous borrow of `foo` occurs here (through borrowing `foo.a`)

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

@ -16,13 +16,13 @@
#[cfg(target_pointer_width = "64")]
fn main() {
let n = 0_usize;
let a = box [&n; 0xF000000000000000_usize];
let a: Box<_> = box [&n; 0xF000000000000000_usize];
println!("{}", a[0xFFFFFF_usize]);
}
#[cfg(target_pointer_width = "32")]
fn main() {
let n = 0_usize;
let a = box [&n; 0xFFFFFFFF_usize];
let a: Box<_> = box [&n; 0xFFFFFFFF_usize];
println!("{}", a[0xFFFFFF_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

@ -21,7 +21,7 @@ impl<T:Copy> Foo for T {
fn take_param<T:Foo>(foo: &T) { }
fn main() {
let x = box 3;
let x: Box<_> = box 3;
take_param(&x);
//~^ ERROR the trait `core::marker::Copy` is not implemented
}

View File

@ -24,12 +24,12 @@ impl<T:Copy> Foo for T {
fn take_param<T:Foo>(foo: &T) { }
fn a() {
let x = box 3;
let x: Box<_> = box 3;
take_param(&x); //~ ERROR `core::marker::Copy` is not implemented
}
fn b() {
let x = box 3;
let x: Box<_> = box 3;
let y = &x;
let z = &x as &Foo; //~ ERROR `core::marker::Copy` is not implemented
}

View File

@ -11,7 +11,7 @@
#![feature(box_syntax)]
fn main() {
let x = box 5;
let x: Box<_> = box 5;
let y = x;
println!("{}", *x); //~ ERROR use of moved value: `*x`
y.clone();

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
}

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