Skip to content

Commit 7985b4d

Browse files
committed
Auto merge of #5120 - JohnTitor:split-up-drop-forget-ref, r=flip1995
Split up `drop_forget_ref` ui test Part of #2038 changelog: none
2 parents ea85b4c + fa32b41 commit 7985b4d

File tree

5 files changed

+275
-244
lines changed

5 files changed

+275
-244
lines changed

tests/ui/drop_forget_ref.stderr

-220
This file was deleted.

tests/ui/drop_forget_ref.rs tests/ui/drop_ref.rs

+5-24
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
1-
#![warn(clippy::drop_ref, clippy::forget_ref)]
2-
#![allow(clippy::toplevel_ref_arg, clippy::similar_names, clippy::needless_pass_by_value)]
1+
#![warn(clippy::drop_ref)]
2+
#![allow(clippy::toplevel_ref_arg)]
33

4-
use std::mem::{drop, forget};
4+
use std::mem::drop;
55

66
struct SomeStruct;
77

88
fn main() {
99
drop(&SomeStruct);
10-
forget(&SomeStruct);
1110

1211
let mut owned1 = SomeStruct;
1312
drop(&owned1);
1413
drop(&&owned1);
1514
drop(&mut owned1);
1615
drop(owned1); //OK
17-
let mut owned2 = SomeStruct;
18-
forget(&owned2);
19-
forget(&&owned2);
20-
forget(&mut owned2);
21-
forget(owned2); //OK
2216

2317
let reference1 = &SomeStruct;
2418
drop(reference1);
25-
forget(&*reference1);
2619

2720
let reference2 = &mut SomeStruct;
2821
drop(reference2);
29-
let reference3 = &mut SomeStruct;
30-
forget(reference3);
3122

32-
let ref reference4 = SomeStruct;
33-
drop(reference4);
34-
forget(reference4);
23+
let ref reference3 = SomeStruct;
24+
drop(reference3);
3525
}
3626

3727
#[allow(dead_code)]
@@ -40,20 +30,11 @@ fn test_generic_fn_drop<T>(val: T) {
4030
drop(val); //OK
4131
}
4232

43-
#[allow(dead_code)]
44-
fn test_generic_fn_forget<T>(val: T) {
45-
forget(&val);
46-
forget(val); //OK
47-
}
48-
4933
#[allow(dead_code)]
5034
fn test_similarly_named_function() {
5135
fn drop<T>(_val: T) {}
5236
drop(&SomeStruct); //OK; call to unrelated function which happens to have the same name
5337
std::mem::drop(&SomeStruct);
54-
fn forget<T>(_val: T) {}
55-
forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name
56-
std::mem::forget(&SomeStruct);
5738
}
5839

5940
#[derive(Copy, Clone)]

tests/ui/drop_ref.stderr

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
2+
--> $DIR/drop_ref.rs:9:5
3+
|
4+
LL | drop(&SomeStruct);
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::drop-ref` implied by `-D warnings`
8+
note: argument has type `&SomeStruct`
9+
--> $DIR/drop_ref.rs:9:10
10+
|
11+
LL | drop(&SomeStruct);
12+
| ^^^^^^^^^^^
13+
14+
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
15+
--> $DIR/drop_ref.rs:12:5
16+
|
17+
LL | drop(&owned1);
18+
| ^^^^^^^^^^^^^
19+
|
20+
note: argument has type `&SomeStruct`
21+
--> $DIR/drop_ref.rs:12:10
22+
|
23+
LL | drop(&owned1);
24+
| ^^^^^^^
25+
26+
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
27+
--> $DIR/drop_ref.rs:13:5
28+
|
29+
LL | drop(&&owned1);
30+
| ^^^^^^^^^^^^^^
31+
|
32+
note: argument has type `&&SomeStruct`
33+
--> $DIR/drop_ref.rs:13:10
34+
|
35+
LL | drop(&&owned1);
36+
| ^^^^^^^^
37+
38+
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
39+
--> $DIR/drop_ref.rs:14:5
40+
|
41+
LL | drop(&mut owned1);
42+
| ^^^^^^^^^^^^^^^^^
43+
|
44+
note: argument has type `&mut SomeStruct`
45+
--> $DIR/drop_ref.rs:14:10
46+
|
47+
LL | drop(&mut owned1);
48+
| ^^^^^^^^^^^
49+
50+
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
51+
--> $DIR/drop_ref.rs:18:5
52+
|
53+
LL | drop(reference1);
54+
| ^^^^^^^^^^^^^^^^
55+
|
56+
note: argument has type `&SomeStruct`
57+
--> $DIR/drop_ref.rs:18:10
58+
|
59+
LL | drop(reference1);
60+
| ^^^^^^^^^^
61+
62+
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
63+
--> $DIR/drop_ref.rs:21:5
64+
|
65+
LL | drop(reference2);
66+
| ^^^^^^^^^^^^^^^^
67+
|
68+
note: argument has type `&mut SomeStruct`
69+
--> $DIR/drop_ref.rs:21:10
70+
|
71+
LL | drop(reference2);
72+
| ^^^^^^^^^^
73+
74+
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
75+
--> $DIR/drop_ref.rs:24:5
76+
|
77+
LL | drop(reference3);
78+
| ^^^^^^^^^^^^^^^^
79+
|
80+
note: argument has type `&SomeStruct`
81+
--> $DIR/drop_ref.rs:24:10
82+
|
83+
LL | drop(reference3);
84+
| ^^^^^^^^^^
85+
86+
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
87+
--> $DIR/drop_ref.rs:29:5
88+
|
89+
LL | drop(&val);
90+
| ^^^^^^^^^^
91+
|
92+
note: argument has type `&T`
93+
--> $DIR/drop_ref.rs:29:10
94+
|
95+
LL | drop(&val);
96+
| ^^^^
97+
98+
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
99+
--> $DIR/drop_ref.rs:37:5
100+
|
101+
LL | std::mem::drop(&SomeStruct);
102+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
103+
|
104+
note: argument has type `&SomeStruct`
105+
--> $DIR/drop_ref.rs:37:20
106+
|
107+
LL | std::mem::drop(&SomeStruct);
108+
| ^^^^^^^^^^^
109+
110+
error: aborting due to 9 previous errors
111+

0 commit comments

Comments
 (0)