|
| 1 | +#![feature(plugin)] |
| 2 | +#![plugin(clippy)] |
| 3 | + |
| 4 | +#![deny(drop_ref, forget_ref)] |
| 5 | +#![allow(toplevel_ref_arg, similar_names)] |
| 6 | + |
| 7 | +use std::mem::{drop, forget}; |
| 8 | + |
| 9 | +struct SomeStruct; |
| 10 | + |
| 11 | +fn main() { |
| 12 | + drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument |
| 13 | + forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument |
| 14 | + |
| 15 | + let mut owned1 = SomeStruct; |
| 16 | + drop(&owned1); //~ERROR call to `std::mem::drop` with a reference argument |
| 17 | + drop(&&owned1); //~ERROR call to `std::mem::drop` with a reference argument |
| 18 | + drop(&mut owned1); //~ERROR call to `std::mem::drop` with a reference argument |
| 19 | + drop(owned1); //OK |
| 20 | + let mut owned2 = SomeStruct; |
| 21 | + forget(&owned2); //~ERROR call to `std::mem::forget` with a reference argument |
| 22 | + forget(&&owned2); //~ERROR call to `std::mem::forget` with a reference argument |
| 23 | + forget(&mut owned2); //~ERROR call to `std::mem::forget` with a reference argument |
| 24 | + forget(owned2); //OK |
| 25 | + |
| 26 | + let reference1 = &SomeStruct; |
| 27 | + drop(reference1); //~ERROR call to `std::mem::drop` with a reference argument |
| 28 | + forget(&*reference1); //~ERROR call to `std::mem::forget` with a reference argument |
| 29 | + |
| 30 | + let reference2 = &mut SomeStruct; |
| 31 | + drop(reference2); //~ERROR call to `std::mem::drop` with a reference argument |
| 32 | + let reference3 = &mut SomeStruct; |
| 33 | + forget(reference3); //~ERROR call to `std::mem::forget` with a reference argument |
| 34 | + |
| 35 | + let ref reference4 = SomeStruct; |
| 36 | + drop(reference4); //~ERROR call to `std::mem::drop` with a reference argument |
| 37 | + forget(reference4); //~ERROR call to `std::mem::forget` with a reference argument |
| 38 | +} |
| 39 | + |
| 40 | +#[allow(dead_code)] |
| 41 | +fn test_generic_fn_drop<T>(val: T) { |
| 42 | + drop(&val); //~ERROR call to `std::mem::drop` with a reference argument |
| 43 | + drop(val); //OK |
| 44 | +} |
| 45 | + |
| 46 | +#[allow(dead_code)] |
| 47 | +fn test_generic_fn_forget<T>(val: T) { |
| 48 | + forget(&val); //~ERROR call to `std::mem::forget` with a reference argument |
| 49 | + forget(val); //OK |
| 50 | +} |
| 51 | + |
| 52 | +#[allow(dead_code)] |
| 53 | +fn test_similarly_named_function() { |
| 54 | + fn drop<T>(_val: T) {} |
| 55 | + drop(&SomeStruct); //OK; call to unrelated function which happens to have the same name |
| 56 | + std::mem::drop(&SomeStruct); //~ERROR call to `std::mem::drop` with a reference argument |
| 57 | + fn forget<T>(_val: T) {} |
| 58 | + forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name |
| 59 | + std::mem::forget(&SomeStruct); //~ERROR call to `std::mem::forget` with a reference argument |
| 60 | +} |
0 commit comments