Merge branch 'master' into format-padding
This commit is contained in:
commit
604095fff2
42 changed files with 260 additions and 134 deletions
|
|
@ -9,5 +9,5 @@ fn main() {
|
|||
retarget(&mut target_alias, target);
|
||||
// now `target_alias` points to the same thing as `target`
|
||||
*target = 13;
|
||||
let _val = *target_alias; //~ ERROR does not exist on the stack
|
||||
let _val = *target_alias; //~ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::mem;
|
||||
|
||||
pub fn safe(_x: &mut i32, _y: &i32) {} //~ ERROR does not exist on the stack
|
||||
pub fn safe(_x: &mut i32, _y: &i32) {} //~ ERROR does not exist on the borrow stack
|
||||
|
||||
fn main() {
|
||||
let mut x = 0;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ fn demo_mut_advanced_unique(mut our: Box<i32>) -> i32 {
|
|||
unknown_code_2();
|
||||
|
||||
// We know this will return 5
|
||||
*our //~ ERROR does not exist on the stack
|
||||
*our //~ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
||||
// Now comes the evil context
|
||||
|
|
|
|||
|
|
@ -13,5 +13,5 @@ fn main() {
|
|||
let v1 = safe::as_mut_slice(&v);
|
||||
let _v2 = safe::as_mut_slice(&v);
|
||||
v1[1] = 5;
|
||||
//~^ ERROR does not exist on the stack
|
||||
//~^ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ mod safe {
|
|||
assert!(mid <= len);
|
||||
|
||||
(from_raw_parts_mut(ptr, len - mid), // BUG: should be "mid" instead of "len - mid"
|
||||
//~^ ERROR does not exist on the stack
|
||||
//~^ ERROR does not exist on the borrow stack
|
||||
from_raw_parts_mut(ptr.offset(mid as isize), len - mid))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
let xref = unsafe { &mut *xraw }; // derived from raw, so using raw is still okay...
|
||||
callee(xraw);
|
||||
let _val = *xref; // ...but any use of raw will invalidate our ref.
|
||||
//~^ ERROR: does not exist on the stack
|
||||
//~^ ERROR: does not exist on the borrow stack
|
||||
}
|
||||
|
||||
fn callee(xraw: *mut i32) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
let xref = unsafe { &mut *xraw }; // derived from raw, so using raw is still okay...
|
||||
callee(xraw);
|
||||
let _val = *xref; // ...but any use of raw will invalidate our ref.
|
||||
//~^ ERROR: does not exist on the stack
|
||||
//~^ ERROR: does not exist on the borrow stack
|
||||
}
|
||||
|
||||
fn callee(xraw: *mut i32) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ fn main() {
|
|||
let xref2 = &mut *xref1; // derived from xref1, so using raw is still okay...
|
||||
callee(xref1_sneaky);
|
||||
let _val = *xref2; // ...but any use of it will invalidate our ref.
|
||||
//~^ ERROR: does not exist on the stack
|
||||
//~^ ERROR: does not exist on the borrow stack
|
||||
}
|
||||
|
||||
fn callee(xref1: usize) {
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@ fn main() {
|
|||
let xraw = xref1 as *mut _;
|
||||
let xref2 = unsafe { &mut *xraw };
|
||||
let _val = unsafe { *xraw }; // use the raw again, this invalidates xref2 *even* with the special read except for uniq refs
|
||||
let _illegal = *xref2; //~ ERROR does not exist on the stack
|
||||
let _illegal = *xref2; //~ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,5 +12,5 @@ fn main() {
|
|||
let _val = *xref; // we can even still use our mutable reference
|
||||
mem::forget(unsafe { ptr::read(xshr) }); // but after reading through the shared ref
|
||||
let _val = *xref; // the mutable one is dead and gone
|
||||
//~^ ERROR does not exist on the stack
|
||||
//~^ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ fn main() {
|
|||
let target2 = target as *mut _;
|
||||
drop(&mut *target); // reborrow
|
||||
// Now make sure our ref is still the only one.
|
||||
unsafe { *target2 = 13; } //~ ERROR does not exist on the stack
|
||||
unsafe { *target2 = 13; } //~ ERROR does not exist on the borrow stack
|
||||
let _val = *target;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ fn main() {
|
|||
// Make sure raw ptr with raw tag cannot mutate frozen location without breaking the shared ref.
|
||||
let r#ref = ⌖ // freeze
|
||||
let ptr = r#ref as *const _ as *mut _; // raw ptr, with raw tag
|
||||
unsafe { *ptr = 42; } //~ ERROR does not exist on the stack
|
||||
unsafe { *ptr = 42; } //~ ERROR does not exist on the borrow stack
|
||||
let _val = *r#ref;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
let xref = unsafe { &mut *xraw }; // derived from raw, so using raw is still okay...
|
||||
callee(xraw);
|
||||
let _val = *xref; // ...but any use of raw will invalidate our ref.
|
||||
//~^ ERROR: does not exist on the stack
|
||||
//~^ ERROR: does not exist on the borrow stack
|
||||
}
|
||||
|
||||
fn callee(xraw: *mut i32) {
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@ fn main() {
|
|||
let xref = unsafe { &mut *xraw };
|
||||
let xref_in_mem = Box::new(xref);
|
||||
let _val = unsafe { *xraw }; // invalidate xref
|
||||
let _val = *xref_in_mem; //~ ERROR does not exist on the stack
|
||||
let _val = *xref_in_mem; //~ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ fn main() {
|
|||
let y: *const i32 = &x;
|
||||
x = 1; // this invalidates y by reactivating the lowermost uniq borrow for this local
|
||||
|
||||
assert_eq!(unsafe { *y }, 1); //~ ERROR does not exist on the stack
|
||||
assert_eq!(unsafe { *y }, 1); //~ ERROR does not exist on the borrow stack
|
||||
|
||||
assert_eq!(x, 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ fn main() {
|
|||
let xraw = x as *mut _;
|
||||
let xref = unsafe { &mut *xraw };
|
||||
let _val = unsafe { *xraw }; // invalidate xref
|
||||
foo(xref); //~ ERROR does not exist on the stack
|
||||
foo(xref); //~ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ fn fun1(x: &mut u8) {
|
|||
|
||||
fn fun2() {
|
||||
// Now we use a pointer we are not allowed to use
|
||||
let _x = unsafe { *PTR }; //~ ERROR does not exist on the stack
|
||||
let _x = unsafe { *PTR }; //~ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ fn foo(x: &mut (i32, i32)) -> &mut i32 {
|
|||
let xraw = x as *mut (i32, i32);
|
||||
let ret = unsafe { &mut (*xraw).1 };
|
||||
let _val = unsafe { *xraw }; // invalidate xref
|
||||
ret //~ ERROR does not exist on the stack
|
||||
ret //~ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ fn foo(x: &mut (i32, i32)) -> Option<&mut i32> {
|
|||
let xraw = x as *mut (i32, i32);
|
||||
let ret = Some(unsafe { &mut (*xraw).1 });
|
||||
let _val = unsafe { *xraw }; // invalidate xref
|
||||
ret //~ ERROR does not exist on the stack
|
||||
ret //~ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ fn foo(x: &mut (i32, i32)) -> (&mut i32,) {
|
|||
let xraw = x as *mut (i32, i32);
|
||||
let ret = (unsafe { &mut (*xraw).1 },);
|
||||
let _val = unsafe { *xraw }; // invalidate xref
|
||||
ret //~ ERROR does not exist on the stack
|
||||
ret //~ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ fn main() {
|
|||
let _raw: *mut i32 = unsafe { mem::transmute(&mut x[0]) };
|
||||
// `raw` still carries a tag, so we get another pointer to the same location that does not carry a tag
|
||||
let raw = (&mut x[1] as *mut i32).wrapping_offset(-1);
|
||||
unsafe { *raw = 13; } //~ ERROR does not exist on the stack
|
||||
unsafe { *raw = 13; } //~ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@ fn main() {
|
|||
let mut x = 42;
|
||||
let raw = &mut x as *mut i32 as usize as *mut i32;
|
||||
let _ptr = &mut x;
|
||||
unsafe { *raw = 13; } //~ ERROR does not exist on the stack
|
||||
unsafe { *raw = 13; } //~ ERROR does not exist on the borrow stack
|
||||
}
|
||||
|
|
|
|||
5
tests/run-pass/args.rs
Normal file
5
tests/run-pass/args.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
fn main() {
|
||||
for arg in std::env::args() {
|
||||
println!("{}", arg);
|
||||
}
|
||||
}
|
||||
1
tests/run-pass/args.stdout
Normal file
1
tests/run-pass/args.stdout
Normal file
|
|
@ -0,0 +1 @@
|
|||
args
|
||||
40
tests/run-pass/iter.rs
Normal file
40
tests/run-pass/iter.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
fn iter_empty_and_zst() {
|
||||
for _ in Vec::<u32>::new().iter() { // this iterates over a Unique::empty()
|
||||
panic!("We should never be here.");
|
||||
}
|
||||
|
||||
// Iterate over a ZST (uses arith_offset internally)
|
||||
let mut count = 0;
|
||||
for _ in &[(), (), ()] {
|
||||
count += 1;
|
||||
}
|
||||
assert_eq!(count, 3);
|
||||
}
|
||||
|
||||
fn test_iterator_step_by_nth() {
|
||||
let mut it = (0..16).step_by(5);
|
||||
assert_eq!(it.nth(0), Some(0));
|
||||
assert_eq!(it.nth(0), Some(5));
|
||||
assert_eq!(it.nth(0), Some(10));
|
||||
assert_eq!(it.nth(0), Some(15));
|
||||
assert_eq!(it.nth(0), None);
|
||||
}
|
||||
|
||||
fn iter_any() {
|
||||
let f = |x: &u8| { 10u8 == *x };
|
||||
f(&1u8);
|
||||
|
||||
let g = |(), x: &u8| { 10u8 == *x };
|
||||
g((), &1u8);
|
||||
|
||||
let h = |(), (), x: &u8| { 10u8 == *x };
|
||||
h((), (), &1u8);
|
||||
|
||||
[1, 2, 3u8].into_iter().any(|elt| 10 == *elt);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test_iterator_step_by_nth();
|
||||
iter_any();
|
||||
iter_empty_and_zst();
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
pub fn main() {
|
||||
let f = |x: &u8| { 10u8 == *x };
|
||||
f(&1u8);
|
||||
|
||||
let g = |(), x: &u8| { 10u8 == *x };
|
||||
g((), &1u8);
|
||||
|
||||
let h = |(), (), x: &u8| { 10u8 == *x };
|
||||
h((), (), &1u8);
|
||||
|
||||
[1, 2, 3u8].into_iter().any(|elt| 10 == *elt);
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
fn main() {
|
||||
for _ in Vec::<u32>::new().iter() { // this iterates over a Unique::empty()
|
||||
panic!("We should never be here.");
|
||||
}
|
||||
|
||||
// Iterate over a ZST (uses arith_offset internally)
|
||||
let mut count = 0;
|
||||
for _ in &[(), (), ()] {
|
||||
count += 1;
|
||||
}
|
||||
assert_eq!(count, 3);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue