Skip to content

Commit 3050d90

Browse files
committed
Add forget_ref tests.
Also rename drop_ref.rs to drop_forget_ref.rs in tests/compile-fail.
1 parent 920a2b7 commit 3050d90

File tree

2 files changed

+60
-42
lines changed

2 files changed

+60
-42
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
}

tests/compile-fail/drop_ref.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)