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:
commit
fed12499e7
@ -709,7 +709,7 @@ fn main() {
|
||||
one_hundred: 100,
|
||||
});
|
||||
|
||||
let y = box foo(x);
|
||||
let y: Box<BigStruct> = box foo(x);
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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 @@ fn default() -> Box<T> { box Default::default() }
|
||||
#[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")]
|
||||
|
@ -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 @@ fn basic_reallocate_inplace_noop() {
|
||||
#[bench]
|
||||
fn alloc_owned_small(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
box 10
|
||||
let _: Box<_> = box 10;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -96,9 +96,15 @@
|
||||
|
||||
// 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;
|
||||
|
@ -795,6 +795,7 @@ fn inner(&self) -> &RcBox<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 @@ fn test_simple_clone() {
|
||||
|
||||
#[test]
|
||||
fn test_destructor() {
|
||||
let x = Rc::new(box 5);
|
||||
let x: Rc<Box<_>> = Rc::new(box 5);
|
||||
assert_eq!(**x, 5);
|
||||
}
|
||||
|
||||
|
@ -581,11 +581,11 @@ pub fn bench_copy(b: &mut Bencher) {
|
||||
#[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 @@ pub fn bench_noncopy(b: &mut Bencher) {
|
||||
#[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 ),
|
||||
}
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -790,7 +790,7 @@ fn test_push() {
|
||||
|
||||
#[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);
|
||||
|
@ -984,7 +984,7 @@ pub fn check_links<T>(list: &LinkedList<T>) {
|
||||
|
||||
#[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);
|
||||
|
@ -1509,6 +1509,7 @@ unsafe fn step<T>(ptr: &mut *mut T) -> *mut T {
|
||||
|
||||
#[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 @@ fn test_swap_remove_fail() {
|
||||
#[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 @@ fn test_push() {
|
||||
|
||||
#[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 @@ fn test_truncate() {
|
||||
|
||||
#[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 @@ fn case(a: Vec<i32>, b: Vec<i32>) {
|
||||
|
||||
#[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 @@ fn test_dedup_unique() {
|
||||
|
||||
#[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 @@ fn test_slice_2() {
|
||||
#[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 @@ fn test_mut_last() {
|
||||
|
||||
#[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]);
|
||||
}
|
||||
|
@ -2130,8 +2130,8 @@ fn test_clone() {
|
||||
#[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);
|
||||
|
@ -1205,7 +1205,7 @@ fn test_mut_rev_iterator() {
|
||||
|
||||
#[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 {
|
||||
|
@ -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;
|
||||
|
@ -64,7 +64,8 @@ fn hash<T: Hash>(t: &T) -> u64 {
|
||||
//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]>
|
||||
|
@ -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 {
|
||||
|
@ -16,7 +16,7 @@
|
||||
#[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();
|
||||
|
@ -79,7 +79,7 @@ fn variant_expr<'a>(variants: &'a [P<ast::Variant>], id: ast::NodeId)
|
||||
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
|
||||
|
@ -99,7 +99,7 @@ pub fn register_syntax_extension(&mut self, name: ast::Name, extension: SyntaxEx
|
||||
/// 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.
|
||||
|
@ -606,7 +606,7 @@ fn test_sha256() {
|
||||
|
||||
let tests = wikipedia_tests;
|
||||
|
||||
let mut sh = box Sha256::new();
|
||||
let mut sh: Box<_> = box Sha256::new();
|
||||
|
||||
test_hash(&mut *sh, &tests);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 => {
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -323,22 +323,22 @@ fn read_ipv6_addr(&mut self) -> Option<IpAddr> {
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -547,8 +547,9 @@ fn capture_stdout() {
|
||||
|
||||
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 @@ fn capture_stderr() {
|
||||
|
||||
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();
|
||||
|
@ -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 @@ pub fn oneshot(&mut self, duration: Duration) -> Receiver<()> {
|
||||
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 @@ pub fn periodic(&mut self, duration: Duration) -> Receiver<()> {
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -1044,13 +1044,13 @@ fn smoke() {
|
||||
|
||||
#[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 @@ fn oneshot_multi_thread_recv_close_stress() {
|
||||
#[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 @@ fn smoke() {
|
||||
|
||||
#[test]
|
||||
fn drop_full() {
|
||||
let (tx, _rx) = sync_channel(1);
|
||||
let (tx, _rx) = sync_channel::<Box<int>>(1);
|
||||
tx.send(box 1).unwrap();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ fn peek() {
|
||||
#[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);
|
||||
}
|
||||
|
@ -804,7 +804,7 @@ fn test_spawn_sched_childs_on_default_sched() {
|
||||
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|| {
|
||||
|
@ -33,7 +33,7 @@ pub fn with_arg<F>(func: F) -> Thunk<'a,A,R>
|
||||
where F : FnOnce(A) -> R, F : Send + 'a
|
||||
{
|
||||
Thunk {
|
||||
invoke: box func
|
||||
invoke: Box::<F>::new(func)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 @@ pub fn stderr(color_config: ColorConfig,
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
|
||||
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
|
||||
|
@ -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(),
|
||||
|
@ -40,7 +40,7 @@ fn cs_eq(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
|
||||
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 @@ fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
|
||||
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 @@ macro_rules! md {
|
||||
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)
|
||||
})
|
||||
}))
|
||||
}
|
||||
} }
|
||||
}
|
||||
|
@ -38,9 +38,9 @@ macro_rules! md {
|
||||
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 @@ macro_rules! md {
|
||||
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)
|
||||
}
|
||||
|
@ -32,7 +32,8 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<
|
||||
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 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<
|
||||
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(),
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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(),
|
||||
|
@ -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(),
|
||||
|
@ -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(),
|
||||
|
@ -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(),
|
||||
|
@ -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(),
|
||||
|
@ -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(),
|
||||
|
@ -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(),
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
@ -30,7 +30,7 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
||||
impl<T> OwnedSlice<T> {
|
||||
pub fn empty() -> OwnedSlice<T> {
|
||||
OwnedSlice { data: box [] }
|
||||
OwnedSlice { data: Box::new([]) }
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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])
|
||||
|
@ -46,5 +46,6 @@ fn expand<'cx>(&self,
|
||||
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));
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ fn new() -> 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 @@ fn lookup<C:TableCallback>(&mut self, key: Code, c: C) {
|
||||
|
||||
{
|
||||
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,
|
||||
|
@ -124,7 +124,7 @@ pub fn solve(&mut self) {
|
||||
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);
|
||||
|
@ -16,7 +16,7 @@
|
||||
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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -18,7 +18,7 @@ fn foo(&mut self) {
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let a = box A;
|
||||
let a: Box<_> = box A;
|
||||
a.foo();
|
||||
//~^ ERROR cannot borrow immutable `Box` content `*a` as mutable
|
||||
}
|
||||
|
@ -16,9 +16,10 @@
|
||||
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;
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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() {}
|
||||
|
@ -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 @@ struct Foo {
|
||||
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 @@ struct Foo {
|
||||
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
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ struct Foo {
|
||||
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
|
||||
|
@ -25,7 +25,7 @@ fn drop(&mut self) {
|
||||
}
|
||||
|
||||
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 };
|
||||
};
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
});
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -15,9 +15,9 @@
|
||||
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`
|
||||
|
@ -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) => {
|
||||
|
@ -25,7 +25,7 @@ fn index(&self, &i: &usize) -> &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
|
||||
|
@ -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 @@ struct H { h: Box<isize> }
|
||||
}
|
||||
|
||||
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`
|
||||
|
@ -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>`
|
||||
|
@ -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 @@ fn to_val(&self) -> isize {
|
||||
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
|
||||
}
|
||||
|
@ -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 @@ fn to_val(&self) -> isize {
|
||||
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`
|
||||
|
@ -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() {}
|
||||
|
@ -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);
|
||||
|
@ -21,7 +21,7 @@ fn drop(&mut self) {
|
||||
}
|
||||
|
||||
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 };
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
};
|
||||
|
@ -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();
|
||||
|
@ -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`)
|
||||
|
@ -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
|
||||
|
@ -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]`
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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`
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
Loading…
Reference in New Issue
Block a user