mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-08 21:13:55 +00:00
Add : Box<_>
or ::Box<_>
type annotations to various places.
This is the kind of change that one is expected to need to make to accommodate overloaded-`box`. ---- Note that this is not *all* of the changes necessary to accommodate Issue 22181. It is merely the subset of those cases where there was already a let-binding in place that made it easy to add the necesasry type ascription. (For unnamed intermediate `Box` values, one must go down a different route; `Box::new` is the option that maximizes portability, but has potential inefficiency depending on whether the call is inlined.) ---- There is one place worth note, `run-pass/coerce-match.rs`, where I used an ugly form of `Box<_>` type ascription where I would have preferred to use `Box::new` to accommodate overloaded-`box`. I deliberately did not use `Box::new` here, because that is already done in coerce-match-calls.rs. ---- Precursor for overloaded-`box` and placement-`in`; see Issue 22181.
This commit is contained in:
parent
14f0942a49
commit
270f0eef73
@ -69,6 +69,8 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
use boxed::Box;
|
||||||
|
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
|
|
||||||
use core::atomic;
|
use core::atomic;
|
||||||
@ -170,7 +172,7 @@ impl<T> Arc<T> {
|
|||||||
pub fn new(data: T) -> Arc<T> {
|
pub fn new(data: T) -> Arc<T> {
|
||||||
// Start the weak pointer count as 1 which is the weak pointer that's
|
// 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
|
// 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),
|
strong: atomic::AtomicUsize::new(1),
|
||||||
weak: atomic::AtomicUsize::new(1),
|
weak: atomic::AtomicUsize::new(1),
|
||||||
data: data,
|
data: data,
|
||||||
|
@ -387,6 +387,7 @@ mod test {
|
|||||||
extern crate test;
|
extern crate test;
|
||||||
use self::test::Bencher;
|
use self::test::Bencher;
|
||||||
use core::ptr::PtrExt;
|
use core::ptr::PtrExt;
|
||||||
|
use boxed::Box;
|
||||||
use heap;
|
use heap;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -404,7 +405,7 @@ mod test {
|
|||||||
#[bench]
|
#[bench]
|
||||||
fn alloc_owned_small(b: &mut Bencher) {
|
fn alloc_owned_small(b: &mut Bencher) {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
box 10
|
let _: Box<_> = box 10;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,9 +96,15 @@ pub mod heap;
|
|||||||
|
|
||||||
// Primitive types using the heaps above
|
// 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))]
|
#[cfg(not(test))]
|
||||||
pub mod boxed;
|
pub mod boxed;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
mod boxed { pub use std::boxed::{Box, HEAP}; }
|
||||||
|
#[cfg(test)]
|
||||||
mod boxed_test;
|
mod boxed_test;
|
||||||
pub mod arc;
|
pub mod arc;
|
||||||
pub mod rc;
|
pub mod rc;
|
||||||
|
@ -795,6 +795,7 @@ impl<T> RcBoxPtr<T> for Weak<T> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{Rc, Weak, weak_count, strong_count};
|
use super::{Rc, Weak, weak_count, strong_count};
|
||||||
|
use std::boxed::Box;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::option::Option;
|
use std::option::Option;
|
||||||
use std::option::Option::{Some, None};
|
use std::option::Option::{Some, None};
|
||||||
@ -826,7 +827,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_destructor() {
|
fn test_destructor() {
|
||||||
let x = Rc::new(box 5);
|
let x: Rc<Box<_>> = Rc::new(box 5);
|
||||||
assert_eq!(**x, 5);
|
assert_eq!(**x, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,11 +581,11 @@ mod tests {
|
|||||||
#[bench]
|
#[bench]
|
||||||
pub fn bench_copy_nonarena(b: &mut Bencher) {
|
pub fn bench_copy_nonarena(b: &mut Bencher) {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
box Point {
|
let _: Box<_> = box Point {
|
||||||
x: 1,
|
x: 1,
|
||||||
y: 2,
|
y: 2,
|
||||||
z: 3,
|
z: 3,
|
||||||
}
|
};
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,10 +634,10 @@ mod tests {
|
|||||||
#[bench]
|
#[bench]
|
||||||
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
|
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
box Noncopy {
|
let _: Box<_> = box Noncopy {
|
||||||
string: "hello world".to_string(),
|
string: "hello world".to_string(),
|
||||||
array: vec!( 1, 2, 3, 4, 5 ),
|
array: vec!( 1, 2, 3, 4, 5 ),
|
||||||
}
|
};
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -790,7 +790,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_push_unique() {
|
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_eq!(heap.len(), 3);
|
||||||
assert!(*heap.peek().unwrap() == box 9);
|
assert!(*heap.peek().unwrap() == box 9);
|
||||||
heap.push(box 11);
|
heap.push(box 11);
|
||||||
|
@ -984,7 +984,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_basic() {
|
fn test_basic() {
|
||||||
let mut m = LinkedList::new();
|
let mut m = LinkedList::<Box<_>>::new();
|
||||||
assert_eq!(m.pop_front(), None);
|
assert_eq!(m.pop_front(), None);
|
||||||
assert_eq!(m.pop_back(), None);
|
assert_eq!(m.pop_back(), None);
|
||||||
assert_eq!(m.pop_front(), None);
|
assert_eq!(m.pop_front(), None);
|
||||||
|
@ -1509,6 +1509,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use alloc::boxed::Box;
|
||||||
use core::cmp::Ordering::{Greater, Less, Equal};
|
use core::cmp::Ordering::{Greater, Less, Equal};
|
||||||
use core::prelude::{Some, None, Clone};
|
use core::prelude::{Some, None, Clone};
|
||||||
use core::prelude::{Iterator, IteratorExt};
|
use core::prelude::{Iterator, IteratorExt};
|
||||||
@ -1799,7 +1800,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_swap_remove_noncopyable() {
|
fn test_swap_remove_noncopyable() {
|
||||||
// Tests that we don't accidentally run destructors twice.
|
// 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);
|
v.push(box 0u8);
|
||||||
v.push(box 0u8);
|
v.push(box 0u8);
|
||||||
@ -1828,7 +1829,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_truncate() {
|
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);
|
v.truncate(1);
|
||||||
let v = v;
|
let v = v;
|
||||||
assert_eq!(v.len(), 1);
|
assert_eq!(v.len(), 1);
|
||||||
@ -1838,7 +1839,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clear() {
|
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();
|
v.clear();
|
||||||
assert_eq!(v.len(), 0);
|
assert_eq!(v.len(), 0);
|
||||||
// If the unsafe block didn't drop things properly, we blow up here.
|
// If the unsafe block didn't drop things properly, we blow up here.
|
||||||
@ -1863,11 +1864,11 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dedup_unique() {
|
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();
|
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();
|
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();
|
v2.dedup();
|
||||||
/*
|
/*
|
||||||
* If the boxed pointers were leaked or otherwise misused, valgrind
|
* If the boxed pointers were leaked or otherwise misused, valgrind
|
||||||
@ -1877,11 +1878,11 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dedup_shared() {
|
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();
|
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();
|
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();
|
v2.dedup();
|
||||||
/*
|
/*
|
||||||
* If the pointers were leaked or otherwise misused, valgrind and/or
|
* If the pointers were leaked or otherwise misused, valgrind and/or
|
||||||
@ -2254,8 +2255,9 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_permute_fail() {
|
fn test_permute_fail() {
|
||||||
let v = [(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)),
|
||||||
|
(box 0, Rc::new(0)), (box 0, Rc::new(0))];
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for _ in v.permutations() {
|
for _ in v.permutations() {
|
||||||
if i == 2 {
|
if i == 2 {
|
||||||
@ -2849,7 +2851,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_to_vec() {
|
fn test_to_vec() {
|
||||||
let xs = box [1, 2, 3];
|
let xs: Box<_> = box [1, 2, 3];
|
||||||
let ys = xs.to_vec();
|
let ys = xs.to_vec();
|
||||||
assert_eq!(ys, [1, 2, 3]);
|
assert_eq!(ys, [1, 2, 3]);
|
||||||
}
|
}
|
||||||
|
@ -2130,8 +2130,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_clone_from() {
|
fn test_clone_from() {
|
||||||
let mut v = vec!();
|
let mut v = vec!();
|
||||||
let three = vec!(box 1, box 2, box 3);
|
let three: Vec<Box<_>> = vec!(box 1, box 2, box 3);
|
||||||
let two = vec!(box 4, box 5);
|
let two: Vec<Box<_>> = vec!(box 4, box 5);
|
||||||
// zero, long
|
// zero, long
|
||||||
v.clone_from(&three);
|
v.clone_from(&three);
|
||||||
assert_eq!(v, three);
|
assert_eq!(v, three);
|
||||||
|
@ -1205,7 +1205,7 @@ mod test_map {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_move_iter() {
|
fn test_move_iter() {
|
||||||
let mut m = VecMap::new();
|
let mut m: VecMap<Box<_>> = VecMap::new();
|
||||||
m.insert(1, box 2);
|
m.insert(1, box 2);
|
||||||
let mut called = false;
|
let mut called = false;
|
||||||
for (k, v) in m {
|
for (k, v) in m {
|
||||||
|
@ -68,7 +68,7 @@ fn any_downcast_ref() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn any_downcast_mut() {
|
fn any_downcast_mut() {
|
||||||
let mut a = 5_usize;
|
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 a_r = &mut a as &mut Any;
|
||||||
let tmp: &mut uint = &mut *b;
|
let tmp: &mut uint = &mut *b;
|
||||||
|
@ -16,7 +16,7 @@ use core::clone::Clone;
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_get_ptr() {
|
fn test_get_ptr() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let x = box 0;
|
let x: Box<_> = box 0;
|
||||||
let addr_x: *const int = mem::transmute(&*x);
|
let addr_x: *const int = mem::transmute(&*x);
|
||||||
let opt = Some(x);
|
let opt = Some(x);
|
||||||
let y = opt.unwrap();
|
let y = opt.unwrap();
|
||||||
|
@ -606,7 +606,7 @@ mod tests {
|
|||||||
|
|
||||||
let tests = wikipedia_tests;
|
let tests = wikipedia_tests;
|
||||||
|
|
||||||
let mut sh = box Sha256::new();
|
let mut sh: Box<_> = box Sha256::new();
|
||||||
|
|
||||||
test_hash(&mut *sh, &tests);
|
test_hash(&mut *sh, &tests);
|
||||||
}
|
}
|
||||||
|
@ -323,22 +323,22 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_ip_addr(&mut self) -> Option<IpAddr> {
|
fn read_ip_addr(&mut self) -> Option<IpAddr> {
|
||||||
let ipv4_addr = |p: &mut Parser| p.read_ipv4_addr();
|
let ipv4_addr: Box<_> = box |p: &mut Parser| p.read_ipv4_addr();
|
||||||
let ipv6_addr = |p: &mut Parser| p.read_ipv6_addr();
|
let ipv6_addr: Box<_> = box |p: &mut Parser| p.read_ipv6_addr();
|
||||||
self.read_or(&mut [box ipv4_addr, box ipv6_addr])
|
self.read_or(&mut [ipv4_addr, ipv6_addr])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_socket_addr(&mut self) -> Option<SocketAddr> {
|
fn read_socket_addr(&mut self) -> Option<SocketAddr> {
|
||||||
let ip_addr = |p: &mut Parser| {
|
let ip_addr = |p: &mut Parser| {
|
||||||
let ipv4_p = |p: &mut Parser| p.read_ip_addr();
|
let ipv4_p: Box<_> = box |p: &mut Parser| p.read_ip_addr();
|
||||||
let ipv6_p = |p: &mut Parser| {
|
let ipv6_p: Box<_> = box |p: &mut Parser| {
|
||||||
let open_br = |p: &mut Parser| p.read_given_char('[');
|
let open_br = |p: &mut Parser| p.read_given_char('[');
|
||||||
let ip_addr = |p: &mut Parser| p.read_ipv6_addr();
|
let ip_addr = |p: &mut Parser| p.read_ipv6_addr();
|
||||||
let clos_br = |p: &mut Parser| p.read_given_char(']');
|
let clos_br = |p: &mut Parser| p.read_given_char(']');
|
||||||
p.read_seq_3::<char, IpAddr, char, _, _, _>(open_br, ip_addr, clos_br)
|
p.read_seq_3::<char, IpAddr, char, _, _, _>(open_br, ip_addr, clos_br)
|
||||||
.map(|t| match t { (_, ip, _) => ip })
|
.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 colon = |p: &mut Parser| p.read_given_char(':');
|
||||||
let port = |p: &mut Parser| p.read_number(10, 5, 0x10000).map(|n| n as u16);
|
let port = |p: &mut Parser| p.read_number(10, 5, 0x10000).map(|n| n as u16);
|
||||||
|
@ -1044,13 +1044,13 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn drop_full() {
|
fn drop_full() {
|
||||||
let (tx, _rx) = channel();
|
let (tx, _rx) = channel::<Box<int>>();
|
||||||
tx.send(box 1).unwrap();
|
tx.send(box 1).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn drop_full_shared() {
|
fn drop_full_shared() {
|
||||||
let (tx, _rx) = channel();
|
let (tx, _rx) = channel::<Box<int>>();
|
||||||
drop(tx.clone());
|
drop(tx.clone());
|
||||||
drop(tx.clone());
|
drop(tx.clone());
|
||||||
tx.send(box 1).unwrap();
|
tx.send(box 1).unwrap();
|
||||||
@ -1389,7 +1389,7 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn oneshot_multi_thread_send_recv_stress() {
|
fn oneshot_multi_thread_send_recv_stress() {
|
||||||
for _ in 0..stress_factor() {
|
for _ in 0..stress_factor() {
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel::<Box<int>>();
|
||||||
let _t = thread::spawn(move|| {
|
let _t = thread::spawn(move|| {
|
||||||
tx.send(box 10).unwrap();
|
tx.send(box 10).unwrap();
|
||||||
});
|
});
|
||||||
@ -1566,7 +1566,7 @@ mod sync_tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn drop_full() {
|
fn drop_full() {
|
||||||
let (tx, _rx) = sync_channel(1);
|
let (tx, _rx) = sync_channel::<Box<int>>(1);
|
||||||
tx.send(box 1).unwrap();
|
tx.send(box 1).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_full() {
|
fn test_full() {
|
||||||
let q = Queue::new();
|
let q: Queue<Box<_>> = Queue::new();
|
||||||
q.push(box 1);
|
q.push(box 1);
|
||||||
q.push(box 2);
|
q.push(box 2);
|
||||||
}
|
}
|
||||||
|
@ -289,7 +289,7 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn drop_full() {
|
fn drop_full() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let q = Queue::new(0);
|
let q: Queue<Box<_>> = Queue::new(0);
|
||||||
q.push(box 1);
|
q.push(box 1);
|
||||||
q.push(box 2);
|
q.push(box 2);
|
||||||
}
|
}
|
||||||
|
@ -804,7 +804,7 @@ mod test {
|
|||||||
fn avoid_copying_the_body<F>(spawnfn: F) where F: FnOnce(Thunk<'static>) {
|
fn avoid_copying_the_body<F>(spawnfn: F) where F: FnOnce(Thunk<'static>) {
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
|
||||||
let x = box 1;
|
let x: Box<_> = box 1;
|
||||||
let x_in_parent = (&*x) as *const i32 as usize;
|
let x_in_parent = (&*x) as *const i32 as usize;
|
||||||
|
|
||||||
spawnfn(Thunk::new(move|| {
|
spawnfn(Thunk::new(move|| {
|
||||||
|
@ -146,7 +146,7 @@ impl Table {
|
|||||||
fn search_remainder<C:TableCallback>(item: &mut Entry, key: Code, c: C) {
|
fn search_remainder<C:TableCallback>(item: &mut Entry, key: Code, c: C) {
|
||||||
match item.next {
|
match item.next {
|
||||||
None => {
|
None => {
|
||||||
let mut entry = box Entry {
|
let mut entry: Box<_> = box Entry {
|
||||||
code: key,
|
code: key,
|
||||||
count: 0,
|
count: 0,
|
||||||
next: None,
|
next: None,
|
||||||
@ -170,7 +170,7 @@ impl Table {
|
|||||||
|
|
||||||
{
|
{
|
||||||
if self.items[index as usize].is_none() {
|
if self.items[index as usize].is_none() {
|
||||||
let mut entry = box Entry {
|
let mut entry: Box<_> = box Entry {
|
||||||
code: key,
|
code: key,
|
||||||
count: 0,
|
count: 0,
|
||||||
next: None,
|
next: None,
|
||||||
|
@ -124,7 +124,7 @@ impl Sudoku {
|
|||||||
fn next_color(&mut self, row: u8, col: u8, start_color: u8) -> bool {
|
fn next_color(&mut self, row: u8, col: u8, start_color: u8) -> bool {
|
||||||
if start_color < 10u8 {
|
if start_color < 10u8 {
|
||||||
// colors not yet used
|
// 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
|
// drop colors already in use in neighbourhood
|
||||||
self.drop_colors(&mut *avail, row, col);
|
self.drop_colors(&mut *avail, row, col);
|
||||||
|
@ -16,7 +16,7 @@ struct Foo(Box<isize>, isize);
|
|||||||
struct Bar(isize, isize);
|
struct Bar(isize, isize);
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = (box 1, 2);
|
let x: (Box<_>, _) = (box 1, 2);
|
||||||
let r = &x.0;
|
let r = &x.0;
|
||||||
let y = x; //~ ERROR cannot move out of `x` because it is borrowed
|
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() {
|
fn implicit() {
|
||||||
let mut a = box 1;
|
let mut a: Box<_> = box 1;
|
||||||
|
|
||||||
// Note the danger here:
|
// Note the danger here:
|
||||||
//
|
//
|
||||||
@ -36,7 +36,7 @@ fn implicit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn explicit() {
|
fn explicit() {
|
||||||
let mut a = box 1;
|
let mut a: Box<_> = box 1;
|
||||||
add(
|
add(
|
||||||
&*a,
|
&*a,
|
||||||
rewrite(&mut a)); //~ ERROR cannot borrow
|
rewrite(&mut a)); //~ ERROR cannot borrow
|
||||||
|
@ -23,7 +23,7 @@ fn add(v: &usize, w: Box<usize>) -> usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn implicit() {
|
fn implicit() {
|
||||||
let mut a = box 1;
|
let mut a: Box<_> = box 1;
|
||||||
|
|
||||||
// Note the danger here:
|
// Note the danger here:
|
||||||
//
|
//
|
||||||
@ -36,7 +36,7 @@ fn implicit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn explicit() {
|
fn explicit() {
|
||||||
let mut a = box 1;
|
let mut a: Box<_> = box 1;
|
||||||
add(
|
add(
|
||||||
&*a,
|
&*a,
|
||||||
a); //~ ERROR cannot move
|
a); //~ ERROR cannot move
|
||||||
|
@ -18,7 +18,7 @@ impl A {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let a = box A;
|
let a: Box<_> = box A;
|
||||||
a.foo();
|
a.foo();
|
||||||
//~^ ERROR cannot borrow immutable `Box` content `*a` as mutable
|
//~^ ERROR cannot borrow immutable `Box` content `*a` as mutable
|
||||||
}
|
}
|
||||||
|
@ -31,100 +31,100 @@ struct D {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn copy_after_move() {
|
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 _x = a.x;
|
||||||
let _y = a.y; //~ ERROR use of moved
|
let _y = a.y; //~ ERROR use of moved
|
||||||
//~^^ NOTE `a` moved here (through moving `a.x`)
|
//~^^ NOTE `a` moved here (through moving `a.x`)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_after_move() {
|
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 _x = a.x;
|
||||||
let _y = a.y; //~ ERROR use of moved
|
let _y = a.y; //~ ERROR use of moved
|
||||||
//~^^ NOTE `a` moved here (through moving `a.x`)
|
//~^^ NOTE `a` moved here (through moving `a.x`)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn borrow_after_move() {
|
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 _x = a.x;
|
||||||
let _y = &a.y; //~ ERROR use of moved
|
let _y = &a.y; //~ ERROR use of moved
|
||||||
//~^^ NOTE `a` moved here (through moving `a.x`)
|
//~^^ NOTE `a` moved here (through moving `a.x`)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_after_borrow() {
|
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 _x = &a.x;
|
||||||
let _y = a.y; //~ ERROR cannot move
|
let _y = a.y; //~ ERROR cannot move
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_after_mut_borrow() {
|
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 _x = &mut a.x;
|
||||||
let _y = a.y; //~ ERROR cannot use
|
let _y = a.y; //~ ERROR cannot use
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_after_mut_borrow() {
|
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 _x = &mut a.x;
|
||||||
let _y = a.y; //~ ERROR cannot move
|
let _y = a.y; //~ ERROR cannot move
|
||||||
}
|
}
|
||||||
|
|
||||||
fn borrow_after_mut_borrow() {
|
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 _x = &mut a.x;
|
||||||
let _y = &a.y; //~ ERROR cannot borrow
|
let _y = &a.y; //~ ERROR cannot borrow
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mut_borrow_after_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 _x = &a.x;
|
||||||
let _y = &mut a.y; //~ ERROR cannot borrow
|
let _y = &mut a.y; //~ ERROR cannot borrow
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_after_move_nested() {
|
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 _x = a.x.x;
|
||||||
let _y = a.y; //~ ERROR use of collaterally moved
|
let _y = a.y; //~ ERROR use of collaterally moved
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_after_move_nested() {
|
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 _x = a.x.x;
|
||||||
let _y = a.y; //~ ERROR use of collaterally moved
|
let _y = a.y; //~ ERROR use of collaterally moved
|
||||||
}
|
}
|
||||||
|
|
||||||
fn borrow_after_move_nested() {
|
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 _x = a.x.x;
|
||||||
let _y = &a.y; //~ ERROR use of collaterally moved
|
let _y = &a.y; //~ ERROR use of collaterally moved
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_after_borrow_nested() {
|
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 _x = &a.x.x;
|
||||||
let _y = a.y; //~ ERROR cannot move
|
let _y = a.y; //~ ERROR cannot move
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_after_mut_borrow_nested() {
|
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 _x = &mut a.x.x;
|
||||||
let _y = a.y; //~ ERROR cannot use
|
let _y = a.y; //~ ERROR cannot use
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_after_mut_borrow_nested() {
|
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 _x = &mut a.x.x;
|
||||||
let _y = a.y; //~ ERROR cannot move
|
let _y = a.y; //~ ERROR cannot move
|
||||||
}
|
}
|
||||||
|
|
||||||
fn borrow_after_mut_borrow_nested() {
|
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 _x = &mut a.x.x;
|
||||||
let _y = &a.y; //~ ERROR cannot borrow
|
let _y = &a.y; //~ ERROR cannot borrow
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mut_borrow_after_borrow_nested() {
|
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 _x = &a.x.x;
|
||||||
let _y = &mut a.y; //~ ERROR cannot borrow
|
let _y = &mut a.y; //~ ERROR cannot borrow
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ fn e() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn f() {
|
fn f() {
|
||||||
let mut x = box 3;
|
let mut x: Box<_> = box 3;
|
||||||
let c1 = || get(&*x);
|
let c1 = || get(&*x);
|
||||||
*x = 5; //~ ERROR cannot assign
|
*x = 5; //~ ERROR cannot assign
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ fn g() {
|
|||||||
f: Box<isize>
|
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 c1 = || get(&*x.f);
|
||||||
*x.f = 5; //~ ERROR cannot assign to `*x.f`
|
*x.f = 5; //~ ERROR cannot assign to `*x.f`
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ fn h() {
|
|||||||
f: Box<isize>
|
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 c1 = || get(&*x.f);
|
||||||
let c2 = || *x.f = 5; //~ ERROR cannot borrow `x` as mutable
|
let c2 = || *x.f = 5; //~ ERROR cannot borrow `x` as mutable
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ fn g() {
|
|||||||
f: Box<isize>
|
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 c1 = to_fn_mut(|| set(&mut *x.f));
|
||||||
let c2 = 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
|
//~^ ERROR cannot borrow `x` as mutable more than once
|
||||||
|
@ -25,7 +25,7 @@ impl Drop for Foo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut ptr = box Foo { x: 0 };
|
let mut ptr: Box<_> = box Foo { x: 0 };
|
||||||
let mut test = |foo: &Foo| {
|
let mut test = |foo: &Foo| {
|
||||||
ptr = box Foo { x: ptr.x + 1 };
|
ptr = box Foo { x: ptr.x + 1 };
|
||||||
};
|
};
|
||||||
|
@ -28,7 +28,7 @@ fn main() {
|
|||||||
for &a in &f.a { //~ ERROR cannot move out
|
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
|
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() {
|
fn borrow_in_var_from_var() {
|
||||||
let mut x: isize = 1;
|
let mut x: isize = 1;
|
||||||
let y = box &mut x;
|
let y: Box<_> = box &mut x;
|
||||||
let p = &y;
|
let p = &y;
|
||||||
let q = &***p;
|
let q = &***p;
|
||||||
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
|
**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() {
|
fn borrow_in_var_from_field() {
|
||||||
let mut x = A { a: 1 };
|
let mut x = A { a: 1 };
|
||||||
let y = box &mut x.a;
|
let y: Box<_> = box &mut x.a;
|
||||||
let p = &y;
|
let p = &y;
|
||||||
let q = &***p;
|
let q = &***p;
|
||||||
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
|
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = Some(box 1);
|
let x: Option<Box<_>> = Some(box 1);
|
||||||
match x {
|
match x {
|
||||||
Some(ref _y) => {
|
Some(ref _y) => {
|
||||||
let _a = x; //~ ERROR cannot move
|
let _a = x; //~ ERROR cannot move
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = Some(box 1);
|
let x: Option<Box<_>> = Some(box 1);
|
||||||
match x {
|
match x {
|
||||||
Some(ref y) => {
|
Some(ref y) => {
|
||||||
let _b = *y; //~ ERROR cannot move out
|
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
|
// In this instance, the freeze is conditional and starts before
|
||||||
// the mut borrow.
|
// the mut borrow.
|
||||||
|
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let _w;
|
let _w;
|
||||||
if cond() {
|
if cond() {
|
||||||
_w = &v;
|
_w = &v;
|
||||||
@ -42,7 +42,7 @@ fn pre_freeze_else() {
|
|||||||
// In this instance, the freeze and mut borrow are on separate sides
|
// In this instance, the freeze and mut borrow are on separate sides
|
||||||
// of the if.
|
// of the if.
|
||||||
|
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let _w;
|
let _w;
|
||||||
if cond() {
|
if cond() {
|
||||||
_w = &v;
|
_w = &v;
|
||||||
|
@ -28,7 +28,7 @@ fn inc(v: &mut Box<isize>) {
|
|||||||
fn loop_overarching_alias_mut() {
|
fn loop_overarching_alias_mut() {
|
||||||
// In this instance, the borrow encompasses the entire loop.
|
// 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;
|
let mut x = &mut v;
|
||||||
**x += 1;
|
**x += 1;
|
||||||
loop {
|
loop {
|
||||||
@ -39,7 +39,7 @@ fn loop_overarching_alias_mut() {
|
|||||||
fn block_overarching_alias_mut() {
|
fn block_overarching_alias_mut() {
|
||||||
// In this instance, the borrow encompasses the entire closure call.
|
// 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;
|
let mut x = &mut v;
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
borrow(&*v); //~ ERROR cannot borrow
|
borrow(&*v); //~ ERROR cannot borrow
|
||||||
@ -50,8 +50,8 @@ fn block_overarching_alias_mut() {
|
|||||||
fn loop_aliased_mut() {
|
fn loop_aliased_mut() {
|
||||||
// In this instance, the borrow is carried through the loop.
|
// In this instance, the borrow is carried through the loop.
|
||||||
|
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let mut w = box 4;
|
let mut w: Box<_> = box 4;
|
||||||
let mut _x = &w;
|
let mut _x = &w;
|
||||||
loop {
|
loop {
|
||||||
borrow_mut(&mut *v); //~ ERROR cannot borrow
|
borrow_mut(&mut *v); //~ ERROR cannot borrow
|
||||||
@ -62,8 +62,8 @@ fn loop_aliased_mut() {
|
|||||||
fn while_aliased_mut() {
|
fn while_aliased_mut() {
|
||||||
// In this instance, the borrow is carried through the loop.
|
// In this instance, the borrow is carried through the loop.
|
||||||
|
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let mut w = box 4;
|
let mut w: Box<_> = box 4;
|
||||||
let mut _x = &w;
|
let mut _x = &w;
|
||||||
while cond() {
|
while cond() {
|
||||||
borrow_mut(&mut *v); //~ ERROR cannot borrow
|
borrow_mut(&mut *v); //~ ERROR cannot borrow
|
||||||
@ -75,8 +75,8 @@ fn while_aliased_mut() {
|
|||||||
fn loop_aliased_mut_break() {
|
fn loop_aliased_mut_break() {
|
||||||
// In this instance, the borrow is carried through the loop.
|
// In this instance, the borrow is carried through the loop.
|
||||||
|
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let mut w = box 4;
|
let mut w: Box<_> = box 4;
|
||||||
let mut _x = &w;
|
let mut _x = &w;
|
||||||
loop {
|
loop {
|
||||||
borrow_mut(&mut *v);
|
borrow_mut(&mut *v);
|
||||||
@ -89,8 +89,8 @@ fn loop_aliased_mut_break() {
|
|||||||
fn while_aliased_mut_break() {
|
fn while_aliased_mut_break() {
|
||||||
// In this instance, the borrow is carried through the loop.
|
// In this instance, the borrow is carried through the loop.
|
||||||
|
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let mut w = box 4;
|
let mut w: Box<_> = box 4;
|
||||||
let mut _x = &w;
|
let mut _x = &w;
|
||||||
while cond() {
|
while cond() {
|
||||||
borrow_mut(&mut *v);
|
borrow_mut(&mut *v);
|
||||||
@ -101,8 +101,8 @@ fn while_aliased_mut_break() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn while_aliased_mut_cond(cond: bool, cond2: bool) {
|
fn while_aliased_mut_cond(cond: bool, cond2: bool) {
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let mut w = box 4;
|
let mut w: Box<_> = box 4;
|
||||||
let mut x = &mut w;
|
let mut x = &mut w;
|
||||||
while cond {
|
while cond {
|
||||||
**x += 1;
|
**x += 1;
|
||||||
|
@ -29,7 +29,7 @@ fn inc(v: &mut Box<isize>) {
|
|||||||
fn pre_freeze() {
|
fn pre_freeze() {
|
||||||
// In this instance, the freeze starts before the mut borrow.
|
// In this instance, the freeze starts before the mut borrow.
|
||||||
|
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let _w = &v;
|
let _w = &v;
|
||||||
borrow_mut(&mut *v); //~ ERROR cannot borrow
|
borrow_mut(&mut *v); //~ ERROR cannot borrow
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ fn pre_freeze() {
|
|||||||
fn post_freeze() {
|
fn post_freeze() {
|
||||||
// In this instance, the const alias starts after the borrow.
|
// 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);
|
borrow_mut(&mut *v);
|
||||||
let _w = &v;
|
let _w = &v;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ fn borrow<F>(v: &isize, f: F) where F: FnOnce(&isize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn box_imm() {
|
fn box_imm() {
|
||||||
let v = box 3;
|
let v: Box<_> = box 3;
|
||||||
let _w = &v;
|
let _w = &v;
|
||||||
thread::spawn(move|| {
|
thread::spawn(move|| {
|
||||||
println!("v={}", *v);
|
println!("v={}", *v);
|
||||||
@ -26,7 +26,7 @@ fn box_imm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn box_imm_explicit() {
|
fn box_imm_explicit() {
|
||||||
let v = box 3;
|
let v: Box<_> = box 3;
|
||||||
let _w = &v;
|
let _w = &v;
|
||||||
thread::spawn(move|| {
|
thread::spawn(move|| {
|
||||||
println!("v={}", *v);
|
println!("v={}", *v);
|
||||||
|
@ -15,7 +15,7 @@ fn borrow<F>(v: &isize, f: F) where F: FnOnce(&isize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn box_imm() {
|
fn box_imm() {
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
borrow(&*v,
|
borrow(&*v,
|
||||||
|w| { //~ ERROR cannot borrow `v` as mutable
|
|w| { //~ ERROR cannot borrow `v` as mutable
|
||||||
v = box 4;
|
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 }
|
fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let bar = box 3;
|
let bar: Box<_> = box 3;
|
||||||
let _g = to_fn_mut(|| {
|
let _g = to_fn_mut(|| {
|
||||||
let _h = to_fn_once(move || -> isize { *bar }); //~ ERROR cannot move out of
|
let _h = to_fn_once(move || -> isize { *bar }); //~ ERROR cannot move out of
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = box box 2;
|
let a: Box<Box<_>> = box box 2;
|
||||||
let b = &a;
|
let b = &a;
|
||||||
|
|
||||||
let z = *a; //~ ERROR: cannot move out of `*a` because it is borrowed
|
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() {
|
fn main() {
|
||||||
let t = box 3;
|
let t: Box<_> = box 3;
|
||||||
|
|
||||||
call_f(move|| { *t + 1 });
|
call_f(move|| { *t + 1 });
|
||||||
call_f(move|| { *t + 1 }); //~ ERROR capture of moved value
|
call_f(move|| { *t + 1 }); //~ ERROR capture of moved value
|
||||||
|
@ -15,9 +15,9 @@ use std::thread;
|
|||||||
fn borrow<T>(_: &T) { }
|
fn borrow<T>(_: &T) { }
|
||||||
|
|
||||||
fn different_vars_after_borrows() {
|
fn different_vars_after_borrows() {
|
||||||
let x1 = box 1;
|
let x1: Box<_> = box 1;
|
||||||
let p1 = &x1;
|
let p1 = &x1;
|
||||||
let x2 = box 2;
|
let x2: Box<_> = box 2;
|
||||||
let p2 = &x2;
|
let p2 = &x2;
|
||||||
thread::spawn(move|| {
|
thread::spawn(move|| {
|
||||||
drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed
|
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() {
|
fn different_vars_after_moves() {
|
||||||
let x1 = box 1;
|
let x1: Box<_> = box 1;
|
||||||
drop(x1);
|
drop(x1);
|
||||||
let x2 = box 2;
|
let x2: Box<_> = box 2;
|
||||||
drop(x2);
|
drop(x2);
|
||||||
thread::spawn(move|| {
|
thread::spawn(move|| {
|
||||||
drop(x1); //~ ERROR capture of moved value: `x1`
|
drop(x1); //~ ERROR capture of moved value: `x1`
|
||||||
@ -39,7 +39,7 @@ fn different_vars_after_moves() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn same_var_after_borrow() {
|
fn same_var_after_borrow() {
|
||||||
let x = box 1;
|
let x: Box<_> = box 1;
|
||||||
let p = &x;
|
let p = &x;
|
||||||
thread::spawn(move|| {
|
thread::spawn(move|| {
|
||||||
drop(x); //~ ERROR cannot move `x` into closure because it is borrowed
|
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() {
|
fn same_var_after_move() {
|
||||||
let x = box 1;
|
let x: Box<_> = box 1;
|
||||||
drop(x);
|
drop(x);
|
||||||
thread::spawn(move|| {
|
thread::spawn(move|| {
|
||||||
drop(x); //~ ERROR capture of moved value: `x`
|
drop(x); //~ ERROR capture of moved value: `x`
|
||||||
|
@ -19,7 +19,7 @@ enum cycle {
|
|||||||
empty
|
empty
|
||||||
}
|
}
|
||||||
fn main() {
|
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!
|
// Create a cycle!
|
||||||
match *x {
|
match *x {
|
||||||
cycle::node(ref mut y) => {
|
cycle::node(ref mut y) => {
|
||||||
|
@ -25,7 +25,7 @@ impl<T> Index<usize> for MyVec<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
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 good = &v[0]; // Shouldn't fail here
|
||||||
let bad = v[0];
|
let bad = v[0];
|
||||||
//~^ ERROR cannot move out of indexed content
|
//~^ ERROR cannot move out of indexed content
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
fn borrow(_v: &isize) {}
|
fn borrow(_v: &isize) {}
|
||||||
|
|
||||||
fn local() {
|
fn local() {
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
borrow(&*v);
|
borrow(&*v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,27 +32,27 @@ fn local_recs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn aliased_imm() {
|
fn aliased_imm() {
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let _w = &v;
|
let _w = &v;
|
||||||
borrow(&*v);
|
borrow(&*v);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aliased_mut() {
|
fn aliased_mut() {
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let _w = &mut v;
|
let _w = &mut v;
|
||||||
borrow(&*v); //~ ERROR cannot borrow `*v`
|
borrow(&*v); //~ ERROR cannot borrow `*v`
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aliased_other() {
|
fn aliased_other() {
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let mut w = box 4;
|
let mut w: Box<_> = box 4;
|
||||||
let _x = &mut w;
|
let _x = &mut w;
|
||||||
borrow(&*v);
|
borrow(&*v);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aliased_other_reassign() {
|
fn aliased_other_reassign() {
|
||||||
let mut v = box 3;
|
let mut v: Box<_> = box 3;
|
||||||
let mut w = box 4;
|
let mut w: Box<_> = box 4;
|
||||||
let mut _x = &mut w;
|
let mut _x = &mut w;
|
||||||
_x = &mut v;
|
_x = &mut v;
|
||||||
borrow(&*v); //~ ERROR cannot borrow `*v`
|
borrow(&*v); //~ ERROR cannot borrow `*v`
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 1;
|
let x: Box<_> = box 1;
|
||||||
let f = move|| {
|
let f = move|| {
|
||||||
let _a = x;
|
let _a = x;
|
||||||
drop(x);
|
drop(x);
|
||||||
|
@ -21,7 +21,7 @@ impl Drop for Foo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut ptr = box Foo { x: 0 };
|
let mut ptr: Box<_> = box Foo { x: 0 };
|
||||||
let mut test = |foo: &Foo| {
|
let mut test = |foo: &Foo| {
|
||||||
println!("access {}", foo.x);
|
println!("access {}", foo.x);
|
||||||
ptr = box Foo { x: ptr.x + 1 };
|
ptr = box Foo { x: ptr.x + 1 };
|
||||||
|
@ -14,7 +14,7 @@ fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let r = {
|
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
|
let f = to_fn_once(move|| &x); //~ ERROR: `x` does not live long enough
|
||||||
f()
|
f()
|
||||||
};
|
};
|
||||||
|
@ -14,7 +14,7 @@ fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
|
|||||||
fn do_it(x: &isize) { }
|
fn do_it(x: &isize) { }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 22;
|
let x: Box<_> = box 22;
|
||||||
let f = to_fn_once(move|| do_it(&*x));
|
let f = to_fn_once(move|| do_it(&*x));
|
||||||
to_fn_once(move|| {
|
to_fn_once(move|| {
|
||||||
f();
|
f();
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
struct Foo { a: isize, b: isize }
|
struct Foo { a: isize, b: isize }
|
||||||
|
|
||||||
fn main() {
|
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);
|
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
|
//~^ 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`)
|
//~^^ 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);
|
let (c, d) = (&mut foo.a, &foo.b);
|
||||||
//~^ ERROR cannot borrow `foo` (here through borrowing `foo.b`) as immutable
|
//~^ ERROR cannot borrow `foo` (here through borrowing `foo.b`) as immutable
|
||||||
//~^^ NOTE previous borrow of `foo` occurs here (through borrowing `foo.a`)
|
//~^^ NOTE previous borrow of `foo` occurs here (through borrowing `foo.a`)
|
||||||
|
@ -16,13 +16,13 @@
|
|||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
fn main() {
|
fn main() {
|
||||||
let n = 0_usize;
|
let n = 0_usize;
|
||||||
let a = box [&n; 0xF000000000000000_usize];
|
let a: Box<_> = box [&n; 0xF000000000000000_usize];
|
||||||
println!("{}", a[0xFFFFFF_usize]);
|
println!("{}", a[0xFFFFFF_usize]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "32")]
|
#[cfg(target_pointer_width = "32")]
|
||||||
fn main() {
|
fn main() {
|
||||||
let n = 0_usize;
|
let n = 0_usize;
|
||||||
let a = box [&n; 0xFFFFFFFF_usize];
|
let a: Box<_> = box [&n; 0xFFFFFFFF_usize];
|
||||||
println!("{}", a[0xFFFFFF_usize]);
|
println!("{}", a[0xFFFFFF_usize]);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ impl<T:Copy> Foo for T {
|
|||||||
fn take_param<T:Foo>(foo: &T) { }
|
fn take_param<T:Foo>(foo: &T) { }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 3;
|
let x: Box<_> = box 3;
|
||||||
take_param(&x);
|
take_param(&x);
|
||||||
//~^ ERROR the trait `core::marker::Copy` is not implemented
|
//~^ 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 take_param<T:Foo>(foo: &T) { }
|
||||||
|
|
||||||
fn a() {
|
fn a() {
|
||||||
let x = box 3;
|
let x: Box<_> = box 3;
|
||||||
take_param(&x); //~ ERROR `core::marker::Copy` is not implemented
|
take_param(&x); //~ ERROR `core::marker::Copy` is not implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
fn b() {
|
fn b() {
|
||||||
let x = box 3;
|
let x: Box<_> = box 3;
|
||||||
let y = &x;
|
let y = &x;
|
||||||
let z = &x as &Foo; //~ ERROR `core::marker::Copy` is not implemented
|
let z = &x as &Foo; //~ ERROR `core::marker::Copy` is not implemented
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 5;
|
let x: Box<_> = box 5;
|
||||||
let y = x;
|
let y = x;
|
||||||
println!("{}", *x); //~ ERROR use of moved value: `*x`
|
println!("{}", *x); //~ ERROR use of moved value: `*x`
|
||||||
y.clone();
|
y.clone();
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = box 1;
|
let x: Box<_> = box 1;
|
||||||
|
|
||||||
let v = (1, 2);
|
let v = (1, 2);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = box 1;
|
let x: Box<_> = box 1;
|
||||||
|
|
||||||
let v = (1, 2);
|
let v = (1, 2);
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
struct Foo(Box<isize>);
|
struct Foo(Box<isize>);
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = (box 1,);
|
let x: (Box<_>,) = (box 1,);
|
||||||
let y = x.0;
|
let y = x.0;
|
||||||
let z = x.0; //~ ERROR use of moved value: `x.0`
|
let z = x.0; //~ ERROR use of moved value: `x.0`
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
fn f(_: &mut isize) {}
|
fn f(_: &mut isize) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut x = box 3;
|
let mut x: Box<_> = box 3;
|
||||||
f(x) //~ ERROR mismatched types
|
f(x) //~ ERROR mismatched types
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
fn f<T:'static>(_: T) {}
|
fn f<T:'static>(_: T) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = box 3;
|
let x: Box<_> = box 3;
|
||||||
f(x);
|
f(x);
|
||||||
let x = &3; //~ ERROR borrowed value does not live long enough
|
let x = &3; //~ ERROR borrowed value does not live long enough
|
||||||
f(x);
|
f(x);
|
||||||
|
@ -34,8 +34,8 @@ impl List {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let n = box Number { n: 42 };
|
let n: Box<_> = box Number { n: 42 };
|
||||||
let mut l = box List { list: Vec::new() };
|
let mut l: Box<_> = box List { list: Vec::new() };
|
||||||
l.push(n);
|
l.push(n);
|
||||||
let x = n.to_string();
|
let x = n.to_string();
|
||||||
//~^ ERROR: use of moved value: `n`
|
//~^ ERROR: use of moved value: `n`
|
||||||
|
@ -78,7 +78,7 @@ fn main() {
|
|||||||
let stack_val_interior_ref_2: &f64 = &stack_val.y;
|
let stack_val_interior_ref_2: &f64 = &stack_val.y;
|
||||||
let ref_to_unnamed: &SomeStruct = &SomeStruct { x: 11, y: 24.5 };
|
let ref_to_unnamed: &SomeStruct = &SomeStruct { x: 11, y: 24.5 };
|
||||||
|
|
||||||
let unique_val = box SomeStruct { x: 13, y: 26.5 };
|
let unique_val: Box<_> = box SomeStruct { x: 13, y: 26.5 };
|
||||||
let unique_val_ref: &SomeStruct = &*unique_val;
|
let unique_val_ref: &SomeStruct = &*unique_val;
|
||||||
let unique_val_interior_ref_1: &int = &unique_val.x;
|
let unique_val_interior_ref_1: &int = &unique_val.x;
|
||||||
let unique_val_interior_ref_2: &f64 = &unique_val.y;
|
let unique_val_interior_ref_2: &f64 = &unique_val.y;
|
||||||
|
@ -57,9 +57,9 @@ impl Drop for StructWithDestructor {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
let unique = box StructWithSomePadding { x: 99, y: 999, z: 9999, w: 99999 };
|
let unique: Box<_> = box StructWithSomePadding { x: 99, y: 999, z: 9999, w: 99999 };
|
||||||
|
|
||||||
let unique_dtor = box StructWithDestructor { x: 77, y: 777, z: 7777, w: 77777 };
|
let unique_dtor: Box<_> = box StructWithDestructor { x: 77, y: 777, z: 7777, w: 77777 };
|
||||||
zzz(); // #break
|
zzz(); // #break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ fn main() {
|
|||||||
let _ = stack.self_by_ref(-1, 2_u16);
|
let _ = stack.self_by_ref(-1, 2_u16);
|
||||||
let _ = stack.self_by_val(-3, -4_i16);
|
let _ = stack.self_by_val(-3, -4_i16);
|
||||||
|
|
||||||
let owned = box Struct { x: 1234.5f64 };
|
let owned: Box<_> = box Struct { x: 1234.5f64 };
|
||||||
let _ = owned.self_by_ref(-5, -6_i32);
|
let _ = owned.self_by_ref(-5, -6_i32);
|
||||||
let _ = owned.self_by_val(-7, -8_i64);
|
let _ = owned.self_by_val(-7, -8_i64);
|
||||||
let _ = owned.self_owned(-9, -10.5_f32);
|
let _ = owned.self_owned(-9, -10.5_f32);
|
||||||
|
@ -144,7 +144,7 @@ fn main() {
|
|||||||
let _ = stack.self_by_ref(-1, -2);
|
let _ = stack.self_by_ref(-1, -2);
|
||||||
let _ = stack.self_by_val(-3, -4);
|
let _ = stack.self_by_val(-3, -4);
|
||||||
|
|
||||||
let owned = box Enum::Variant1{ x: 1799, y: 1799 };
|
let owned: Box<_> = box Enum::Variant1{ x: 1799, y: 1799 };
|
||||||
let _ = owned.self_by_ref(-5, -6);
|
let _ = owned.self_by_ref(-5, -6);
|
||||||
let _ = owned.self_by_val(-7, -8);
|
let _ = owned.self_by_val(-7, -8);
|
||||||
let _ = owned.self_owned(-9, -10);
|
let _ = owned.self_owned(-9, -10);
|
||||||
|
@ -143,7 +143,7 @@ fn main() {
|
|||||||
let _ = stack.self_by_ref(-1, -2);
|
let _ = stack.self_by_ref(-1, -2);
|
||||||
let _ = stack.self_by_val(-3, -4);
|
let _ = stack.self_by_val(-3, -4);
|
||||||
|
|
||||||
let owned = box Struct { x: 1234.5f64 };
|
let owned: Box<_> = box Struct { x: 1234.5f64 };
|
||||||
let _ = owned.self_by_ref(-5, -6);
|
let _ = owned.self_by_ref(-5, -6);
|
||||||
let _ = owned.self_by_val(-7, -8);
|
let _ = owned.self_by_val(-7, -8);
|
||||||
let _ = owned.self_owned(-9, -10);
|
let _ = owned.self_owned(-9, -10);
|
||||||
|
@ -143,7 +143,7 @@ fn main() {
|
|||||||
let _ = stack.self_by_ref(-1, -2);
|
let _ = stack.self_by_ref(-1, -2);
|
||||||
let _ = stack.self_by_val(-3, -4);
|
let _ = stack.self_by_val(-3, -4);
|
||||||
|
|
||||||
let owned = box Struct { x: 200 };
|
let owned: Box<_> = box Struct { x: 200 };
|
||||||
let _ = owned.self_by_ref(-5, -6);
|
let _ = owned.self_by_ref(-5, -6);
|
||||||
let _ = owned.self_by_val(-7, -8);
|
let _ = owned.self_by_val(-7, -8);
|
||||||
let _ = owned.self_owned(-9, -10);
|
let _ = owned.self_owned(-9, -10);
|
||||||
|
@ -149,7 +149,7 @@ fn main() {
|
|||||||
let _ = stack.self_by_ref(-1, -2);
|
let _ = stack.self_by_ref(-1, -2);
|
||||||
let _ = stack.self_by_val(-3, -4);
|
let _ = stack.self_by_val(-3, -4);
|
||||||
|
|
||||||
let owned = box Struct { x: 200 };
|
let owned: Box<_> = box Struct { x: 200 };
|
||||||
let _ = owned.self_by_ref(-5, -6);
|
let _ = owned.self_by_ref(-5, -6);
|
||||||
let _ = owned.self_by_val(-7, -8);
|
let _ = owned.self_by_val(-7, -8);
|
||||||
let _ = owned.self_owned(-9, -10);
|
let _ = owned.self_owned(-9, -10);
|
||||||
|
@ -141,7 +141,7 @@ fn main() {
|
|||||||
let _ = stack.self_by_ref(-1, -2);
|
let _ = stack.self_by_ref(-1, -2);
|
||||||
let _ = stack.self_by_val(-3, -4);
|
let _ = stack.self_by_val(-3, -4);
|
||||||
|
|
||||||
let owned = box TupleStruct(200, -200.5);
|
let owned: Box<_> = box TupleStruct(200, -200.5);
|
||||||
let _ = owned.self_by_ref(-5, -6);
|
let _ = owned.self_by_ref(-5, -6);
|
||||||
let _ = owned.self_by_val(-7, -8);
|
let _ = owned.self_by_val(-7, -8);
|
||||||
let _ = owned.self_owned(-9, -10);
|
let _ = owned.self_owned(-9, -10);
|
||||||
|
@ -143,7 +143,7 @@ fn main() {
|
|||||||
let _ = stack.self_by_ref(-1, -2);
|
let _ = stack.self_by_ref(-1, -2);
|
||||||
let _ = stack.self_by_val(-3, -4);
|
let _ = stack.self_by_val(-3, -4);
|
||||||
|
|
||||||
let owned = box Struct { x: 200 };
|
let owned: Box<_> = box Struct { x: 200 };
|
||||||
let _ = owned.self_by_ref(-5, -6);
|
let _ = owned.self_by_ref(-5, -6);
|
||||||
let _ = owned.self_by_val(-7, -8);
|
let _ = owned.self_by_val(-7, -8);
|
||||||
let _ = owned.self_owned(-9, -10);
|
let _ = owned.self_owned(-9, -10);
|
||||||
|
@ -144,7 +144,7 @@ fn main() {
|
|||||||
let _ = stack.self_by_ref(-1, 2_u16);
|
let _ = stack.self_by_ref(-1, 2_u16);
|
||||||
let _ = stack.self_by_val(-3, -4_i16);
|
let _ = stack.self_by_val(-3, -4_i16);
|
||||||
|
|
||||||
let owned = box Struct { x: 879 };
|
let owned: Box<_> = box Struct { x: 879 };
|
||||||
let _ = owned.self_by_ref(-5, -6_i32);
|
let _ = owned.self_by_ref(-5, -6_i32);
|
||||||
let _ = owned.self_by_val(-7, -8_i64);
|
let _ = owned.self_by_val(-7, -8_i64);
|
||||||
let _ = owned.self_owned(-9, -10.5_f32);
|
let _ = owned.self_owned(-9, -10.5_f32);
|
||||||
|
@ -67,15 +67,15 @@ fn main() {
|
|||||||
// 0b01111100011111000111110001111100 = 2088533116
|
// 0b01111100011111000111110001111100 = 2088533116
|
||||||
// 0b0111110001111100 = 31868
|
// 0b0111110001111100 = 31868
|
||||||
// 0b01111100 = 124
|
// 0b01111100 = 124
|
||||||
let the_a = box ABC::TheA { x: 0, y: 8970181431921507452 };
|
let the_a: Box<_> = box ABC::TheA { x: 0, y: 8970181431921507452 };
|
||||||
|
|
||||||
// 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441
|
// 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441
|
||||||
// 0b00010001000100010001000100010001 = 286331153
|
// 0b00010001000100010001000100010001 = 286331153
|
||||||
// 0b0001000100010001 = 4369
|
// 0b0001000100010001 = 4369
|
||||||
// 0b00010001 = 17
|
// 0b00010001 = 17
|
||||||
let the_b = box ABC::TheB (0, 286331153, 286331153);
|
let the_b: Box<_> = box ABC::TheB (0, 286331153, 286331153);
|
||||||
|
|
||||||
let univariant = box Univariant::TheOnlyCase(123234);
|
let univariant: Box<_> = box Univariant::TheOnlyCase(123234);
|
||||||
|
|
||||||
zzz(); // #break
|
zzz(); // #break
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let struct_ref = &a_struct;
|
let struct_ref = &a_struct;
|
||||||
let owned = box 6;
|
let owned: Box<_> = box 6;
|
||||||
|
|
||||||
let mut closure = || {
|
let mut closure = || {
|
||||||
let closure_local = 8;
|
let closure_local = 8;
|
||||||
|
@ -58,7 +58,7 @@ fn main() {
|
|||||||
c: 4
|
c: 4
|
||||||
};
|
};
|
||||||
|
|
||||||
let owned = box 5;
|
let owned: Box<_> = box 5;
|
||||||
|
|
||||||
let closure = move || {
|
let closure = move || {
|
||||||
zzz(); // #break
|
zzz(); // #break
|
||||||
|
@ -90,7 +90,7 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let struct_ref = &a_struct;
|
let struct_ref = &a_struct;
|
||||||
let owned = box 6;
|
let owned: Box<_> = box 6;
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut first_closure = || {
|
let mut first_closure = || {
|
||||||
|
@ -20,6 +20,6 @@ impl double for uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = box() (box 3_usize as Box<double>);
|
let x: Box<_> = box() (box 3_usize as Box<double>);
|
||||||
assert_eq!(x.double(), 6_usize);
|
assert_eq!(x.double(), 6_usize);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,6 @@ impl double for Box<uint> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = box 3_usize;
|
let x: Box<_> = box 3_usize;
|
||||||
assert_eq!(x.double(), 6_usize);
|
assert_eq!(x.double(), 6_usize);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,6 @@ impl double for Box<uint> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = box box box box box 3_usize;
|
let x: Box<Box<Box<Box<Box<_>>>>> = box box box box box 3_usize;
|
||||||
assert_eq!(x.double(), 6_usize);
|
assert_eq!(x.double(), 6_usize);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,6 @@ impl double for uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = box box 3_usize;
|
let x: Box<Box<_>> = box box 3_usize;
|
||||||
assert_eq!(x.double(), 6_usize);
|
assert_eq!(x.double(), 6_usize);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,6 @@ impl double for uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = box 3_usize;
|
let x: Box<_> = box 3_usize;
|
||||||
assert_eq!(x.double(), 6_usize);
|
assert_eq!(x.double(), 6_usize);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,6 @@ impl Foo for uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = box 3_usize;
|
let x: Box<_> = box 3_usize;
|
||||||
assert_eq!(x.foo(), "box 3".to_string());
|
assert_eq!(x.foo(), "box 3".to_string());
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ extern crate collections;
|
|||||||
use std::collections::BitVec;
|
use std::collections::BitVec;
|
||||||
|
|
||||||
fn bitv_test() {
|
fn bitv_test() {
|
||||||
let mut v1 = box BitVec::from_elem(31, false);
|
let mut v1: Box<_> = box BitVec::from_elem(31, false);
|
||||||
let v2 = box BitVec::from_elem(31, true);
|
let v2: Box<_> = box BitVec::from_elem(31, true);
|
||||||
v1.union(&*v2);
|
v1.union(&*v2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let bar = box 3;
|
let bar: Box<_> = box 3;
|
||||||
let h = || -> int *bar;
|
let h = || -> int *bar;
|
||||||
assert_eq!(h(), 3);
|
assert_eq!(h(), 3);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ fn iter_ints<F>(x: &Ints, mut f: F) -> bool where F: FnMut(&int) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let mut ints = box Ints {sum: box 0, values: Vec::new()};
|
let mut ints: Box<_> = box Ints {sum: box 0, values: Vec::new()};
|
||||||
add_int(&mut *ints, 22);
|
add_int(&mut *ints, 22);
|
||||||
add_int(&mut *ints, 44);
|
add_int(&mut *ints, 44);
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ extern crate cci_borrow_lib;
|
|||||||
use cci_borrow_lib::foo;
|
use cci_borrow_lib::foo;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let p = box 22_usize;
|
let p: Box<_> = box 22_usize;
|
||||||
let r = foo(&*p);
|
let r = foo(&*p);
|
||||||
println!("r={}", r);
|
println!("r={}", r);
|
||||||
assert_eq!(r, 22_usize);
|
assert_eq!(r, 22_usize);
|
||||||
|
@ -43,7 +43,7 @@ fn get_bar(x: uint) -> Vec<uint> { vec!(x * 2) }
|
|||||||
|
|
||||||
pub fn fails() {
|
pub fn fails() {
|
||||||
let x = 2;
|
let x = 2;
|
||||||
let mut y = Vec::new();
|
let mut y: Vec<Box<_>> = Vec::new();
|
||||||
y.push(box Conzabble::Bickwick(do_it(&get_bar(x))));
|
y.push(box Conzabble::Bickwick(do_it(&get_bar(x))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ struct Pair {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let z = box Pair { a : 10, b : 12};
|
let z: Box<_> = box Pair { a : 10, b : 12};
|
||||||
|
|
||||||
let _t = Thread::spawn(move|| {
|
let _t = Thread::spawn(move|| {
|
||||||
assert_eq!(z.a, 10);
|
assert_eq!(z.a, 10);
|
||||||
|
@ -14,9 +14,13 @@
|
|||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let _: Box<[int]> = if true { box [1, 2, 3] } else { box [1] };
|
let _: Box<[int]> =
|
||||||
|
if true { let b: Box<_> = box [1, 2, 3]; b } else { let b: Box<_> = box [1]; b };
|
||||||
|
|
||||||
let _: Box<[int]> = match true { true => box [1, 2, 3], false => box [1] };
|
let _: Box<[int]> = match true {
|
||||||
|
true => { let b: Box<_> = box [1, 2, 3]; b }
|
||||||
|
false => { let b: Box<_> = box [1]; b }
|
||||||
|
};
|
||||||
|
|
||||||
// Check we don't get over-keen at propagating coercions in the case of casts.
|
// Check we don't get over-keen at propagating coercions in the case of casts.
|
||||||
let x = if true { 42 } else { 42u8 } as u16;
|
let x = if true { 42 } else { 42u8 } as u16;
|
||||||
|
@ -22,7 +22,7 @@ extern crate crate_method_reexport_grrrrrrr2;
|
|||||||
pub fn main() {
|
pub fn main() {
|
||||||
use crate_method_reexport_grrrrrrr2::rust::add;
|
use crate_method_reexport_grrrrrrr2::rust::add;
|
||||||
use crate_method_reexport_grrrrrrr2::rust::cx;
|
use crate_method_reexport_grrrrrrr2::rust::cx;
|
||||||
let x = box() ();
|
let x: Box<_> = box () ();
|
||||||
x.cx();
|
x.cx();
|
||||||
let y = ();
|
let y = ();
|
||||||
y.add("hi".to_string());
|
y.add("hi".to_string());
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = box Cell::new(5);
|
let x: Box<_> = box Cell::new(5);
|
||||||
x.set(1000);
|
x.set(1000);
|
||||||
println!("{}", x.get());
|
println!("{}", x.get());
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,6 @@ impl<K,V> HashMap<K,V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let mut m = box linear_map::<(),()>();
|
let mut m: Box<_> = box linear_map::<(),()>();
|
||||||
assert_eq!(m.len(), 0);
|
assert_eq!(m.len(), 0);
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ trait Nus { fn f(&self); }
|
|||||||
impl Nus for thing { fn f(&self) {} }
|
impl Nus for thing { fn f(&self) {} }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let y = box thing(A {a: 10});
|
let y: Box<_> = box thing(A {a: 10});
|
||||||
assert_eq!(y.clone().bar(), 10);
|
assert_eq!(y.clone().bar(), 10);
|
||||||
assert_eq!(y.quux(), 10);
|
assert_eq!(y.quux(), 10);
|
||||||
|
|
||||||
|
@ -12,4 +12,4 @@
|
|||||||
#![allow(unknown_features)]
|
#![allow(unknown_features)]
|
||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
pub fn main() { let x = { box 100 }; assert!((*x == 100)); }
|
pub fn main() { let x: Box<_> = { box 100 }; assert!((*x == 100)); }
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
// Tests for if as expressions returning boxed types
|
// Tests for if as expressions returning boxed types
|
||||||
fn test_box() {
|
fn test_box() {
|
||||||
let rs = if true { box 100 } else { box 101 };
|
let rs: Box<_> = if true { box 100 } else { box 101 };
|
||||||
assert_eq!(*rs, 100);
|
assert_eq!(*rs, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
// Tests for match as expressions resulting in boxed types
|
// Tests for match as expressions resulting in boxed types
|
||||||
fn test_box() {
|
fn test_box() {
|
||||||
let res = match true { true => { box 100 }, _ => panic!() };
|
let res: Box<_> = match true { true => { box 100 }, _ => panic!() };
|
||||||
assert_eq!(*res, 100);
|
assert_eq!(*res, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ fn foo(Foo {x, ..}: Foo) -> *const uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let obj = box 1;
|
let obj: Box<_> = box 1;
|
||||||
let objptr: *const uint = &*obj;
|
let objptr: *const uint = &*obj;
|
||||||
let f = Foo {x: obj, y: box 2};
|
let f = Foo {x: obj, y: box 2};
|
||||||
let xptr = foo(f);
|
let xptr = foo(f);
|
||||||
|
@ -28,7 +28,7 @@ fn checkval(box ref x: Box<uint>) -> uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let obj = box 1;
|
let obj: Box<_> = box 1;
|
||||||
let objptr: *const uint = &*obj;
|
let objptr: *const uint = &*obj;
|
||||||
let xptr = getaddr(obj);
|
let xptr = getaddr(obj);
|
||||||
assert_eq!(objptr, xptr);
|
assert_eq!(objptr, xptr);
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
fn id<T:Send>(t: T) -> T { return t; }
|
fn id<T:Send>(t: T) -> T { return t; }
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let expected = box 100;
|
let expected: Box<_> = box 100;
|
||||||
let actual = id::<Box<int>>(expected.clone());
|
let actual = id::<Box<int>>(expected.clone());
|
||||||
println!("{}", *actual);
|
println!("{}", *actual);
|
||||||
assert_eq!(*expected, *actual);
|
assert_eq!(*expected, *actual);
|
||||||
|
@ -154,7 +154,7 @@ pub fn main() {
|
|||||||
test_order();
|
test_order();
|
||||||
|
|
||||||
// make sure that format! doesn't move out of local variables
|
// make sure that format! doesn't move out of local variables
|
||||||
let a = box 3;
|
let a: Box<_> = box 3;
|
||||||
format!("{}", a);
|
format!("{}", a);
|
||||||
format!("{}", a);
|
format!("{}", a);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ fn test_tup() {
|
|||||||
fn test_unique() {
|
fn test_unique() {
|
||||||
let i = &Cell::new(0);
|
let i = &Cell::new(0);
|
||||||
{
|
{
|
||||||
let _a = box r(i);
|
let _a: Box<_> = box r(i);
|
||||||
}
|
}
|
||||||
assert_eq!(i.get(), 1);
|
assert_eq!(i.get(), 1);
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ fn test_unique() {
|
|||||||
fn test_unique_rec() {
|
fn test_unique_rec() {
|
||||||
let i = &Cell::new(0);
|
let i = &Cell::new(0);
|
||||||
{
|
{
|
||||||
let _a = box BoxR {
|
let _a: Box<_> = box BoxR {
|
||||||
x: r(i)
|
x: r(i)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ mod rusti {
|
|||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut x = box 1;
|
let mut x: Box<_> = box 1;
|
||||||
|
|
||||||
assert_eq!(rusti::atomic_load(&*x), 1);
|
assert_eq!(rusti::atomic_load(&*x), 1);
|
||||||
*x = 5;
|
*x = 5;
|
||||||
|
@ -23,7 +23,7 @@ mod rusti {
|
|||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let x = box 1;
|
let x: Box<_> = box 1;
|
||||||
let mut y = rusti::init();
|
let mut y = rusti::init();
|
||||||
let mut z: *const uint = transmute(&x);
|
let mut z: *const uint = transmute(&x);
|
||||||
rusti::move_val_init(&mut y, x);
|
rusti::move_val_init(&mut y, x);
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user