do not use 'let _', it is strange

This commit is contained in:
Ralf Jung 2018-11-26 15:31:53 +01:00
parent 6f9ee8b9e5
commit 7d623f73cc
24 changed files with 28 additions and 28 deletions

View File

@ -2,5 +2,5 @@
fn main() {
let v = [1i8, 2];
let x = &v[1] as *const i8;
let _ = unsafe { x.offset(isize::min_value()) };
let _val = unsafe { x.offset(isize::min_value()) };
}

View File

@ -12,5 +12,5 @@ pub enum Foo {
fn main() {
let f = unsafe { std::mem::transmute::<i32, Foo>(42) };
let _ = mem::discriminant(&f);
let _val = mem::discriminant(&f);
}

View File

@ -3,5 +3,5 @@ fn main() {
let y = &x;
let z = &y as *const &i32 as *const usize;
let ptr_bytes = unsafe { *z }; // the actual deref is fine, because we read the entire pointer at once
let _ = ptr_bytes / 432; //~ ERROR invalid arithmetic on pointers that would leak base addresses
let _val = ptr_bytes / 432; //~ ERROR invalid arithmetic on pointers that would leak base addresses
}

View File

@ -3,5 +3,5 @@ fn main() {
let y = &x;
let z = &y as *const &i32 as *const u8;
// the deref fails, because we are reading only a part of the pointer
let _ = unsafe { *z }; //~ ERROR tried to access part of a pointer value as raw bytes
let _val = unsafe { *z }; //~ ERROR tried to access part of a pointer value as raw bytes
}

View File

@ -1,5 +1,5 @@
fn main() {
let val = 13usize;
let addr = &val as *const _ as usize;
let _ = addr & 13; //~ ERROR access part of a pointer value as raw bytes
let _val = addr & 13; //~ ERROR access part of a pointer value as raw bytes
}

View File

@ -4,5 +4,5 @@ fn main() {
let x = x as *const i32;
let x = x as u8; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes
let x = x as *const i32;
let _ = unsafe { *x };
let _val = unsafe { *x };
}

View File

@ -3,6 +3,6 @@
fn main() {
// Can't offset an integer pointer by non-zero offset.
unsafe {
let _ = (1 as *mut u8).offset(1);
let _val = (1 as *mut u8).offset(1);
}
}

View File

@ -4,6 +4,6 @@ fn main() {
let ptr = Box::into_raw(Box::new(0u32));
// Can't start with an integer pointer and get to something usable
unsafe {
let _ = (1 as *mut u8).offset(ptr as isize);
let _val = (1 as *mut u8).offset(ptr as isize);
}
}

View File

@ -1,5 +1,5 @@
fn main() {
let val = 13usize;
let addr = &val as *const _ as usize;
let _ = addr % 16; //~ ERROR access part of a pointer value as raw bytes
let _val = addr % 16; //~ ERROR access part of a pointer value as raw bytes
}

View File

@ -4,5 +4,5 @@ fn main() {
let ptr = Box::into_raw(Box::new(0u32));
// Can't start with an integer pointer and get to something usable
let ptr = (1 as *mut u8).wrapping_offset(ptr as isize);
let _ = unsafe { *ptr };
let _val = unsafe { *ptr };
}

View File

@ -10,5 +10,5 @@ fn main() {
let bad = unsafe {
std::mem::transmute::<&[u8], [u8; 8]>(&[1u8])
};
let _ = bad[0] + bad[bad.len()-1]; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes
let _val = bad[0] + bad[bad.len()-1]; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes
}

View File

@ -1,6 +1,6 @@
fn main() {
assert!(std::char::from_u32(-1_i32 as u32).is_none());
let _ = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR encountered 4294967295, but expected something less or equal to 1114111
let _val = match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR encountered 4294967295, but expected something less or equal to 1114111
'a' => {true},
'b' => {false},
_ => {true},

View File

@ -1,4 +1,4 @@
fn main() {
let x = &() as *const () as *const i32;
let _ = unsafe { *x }; //~ ERROR access memory with alignment 1, but alignment 4 is required
let _val = unsafe { *x }; //~ ERROR access memory with alignment 1, but alignment 4 is required
}

View File

@ -3,6 +3,6 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
fn main() {
let mut i = 3;
let _ = catch_unwind(AssertUnwindSafe(|| {i -= 2;} ));
let _val = catch_unwind(AssertUnwindSafe(|| {i -= 2;} ));
println!("{}", i);
}

View File

@ -1,3 +1,3 @@
fn main() {
let _ = ::std::str::from_utf8(b"a");
let _val = ::std::str::from_utf8(b"a");
}

View File

@ -5,15 +5,15 @@ use std::sync;
fn main() {
let m = sync::Mutex::new(0);
let _ = m.lock();
drop(m.lock());
drop(m);
// We don't provide RwLock on Windows
#[cfg(not(target_os = "windows"))]
{
let rw = sync::RwLock::new(0);
let _ = rw.read();
let _ = rw.write();
drop(rw.read());
drop(rw.write());
drop(rw);
}
}

View File

@ -17,7 +17,7 @@ fn main() {
// this closure never by val uses its captures
// so it's basically a fn(&self)
// the shim used to not drop the `x`
let x = move || { let _ = x; };
let x = move || { let _val = x; };
f(x);
}
assert!(ran_drop);

View File

@ -3,5 +3,5 @@
fn main() {
// With the nested Vec, this is calling Offset(Unique::empty(), 0) on drop.
let args : Vec<Vec<i32>> = Vec::new();
let _ = box args;
let _val = box args;
}

View File

@ -13,5 +13,5 @@
fn main() {
let functions: [Box<Fn() -> Option<()>>; 1] = [Box::new(|| None)];
let _: Option<Vec<()>> = functions.iter().map(|f| (*f)()).collect();
let _val: Option<Vec<()>> = functions.iter().map(|f| (*f)()).collect();
}

View File

@ -20,7 +20,7 @@ fn main() {
let mut x = 0;
{
let wrapper = Box::new(Wrapper(&mut x, 123));
let _: Box<Wrapper<Send>> = wrapper;
let _val: Box<Wrapper<Send>> = wrapper;
}
assert_eq!(432, x)
}

View File

@ -15,5 +15,5 @@ trait Foo {}
impl Foo for [u8; 2] {}
fn main() {
let _: Arc<Foo + Send> = Arc::new([3, 4]);
let _val: Arc<Foo + Send> = Arc::new([3, 4]);
}

View File

@ -1,4 +1,4 @@
pub fn main() {
let bytes: [u8; 8] = unsafe { ::std::mem::transmute(0u64) };
let _: &[u8] = &bytes;
let _val: &[u8] = &bytes;
}

View File

@ -27,6 +27,6 @@ fn foo(i:isize, j: char) -> Foo {
pub fn main() {
let (tx, rx) = channel();
let _ = tx.send(foo(42, 'c'));
let _ = rx;
tx.send(foo(42, 'c')).unwrap();
let _val = rx;
}

View File

@ -4,7 +4,7 @@ fn slice_of_zst() {
fn foo<T>(v: &[T]) -> Option<&[T]> {
let mut it = v.iter();
for _ in 0..5 {
let _ = it.next();
it.next();
}
Some(it.as_slice())
}
@ -12,7 +12,7 @@ fn slice_of_zst() {
fn foo_mut<T>(v: &mut [T]) -> Option<&mut [T]> {
let mut it = v.iter_mut();
for _ in 0..5 {
let _ = it.next();
it.next();
}
Some(it.into_slice())
}