Skip to content

Commit

Permalink
Split up drop_forget_ref ui test
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Feb 1, 2020
1 parent f3e2ccd commit fa32b41
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 244 deletions.
220 changes: 0 additions & 220 deletions tests/ui/drop_forget_ref.stderr

This file was deleted.

29 changes: 5 additions & 24 deletions tests/ui/drop_forget_ref.rs → tests/ui/drop_ref.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
#![warn(clippy::drop_ref, clippy::forget_ref)]
#![allow(clippy::toplevel_ref_arg, clippy::similar_names, clippy::needless_pass_by_value)]
#![warn(clippy::drop_ref)]
#![allow(clippy::toplevel_ref_arg)]

use std::mem::{drop, forget};
use std::mem::drop;

struct SomeStruct;

fn main() {
drop(&SomeStruct);
forget(&SomeStruct);

let mut owned1 = SomeStruct;
drop(&owned1);
drop(&&owned1);
drop(&mut owned1);
drop(owned1); //OK
let mut owned2 = SomeStruct;
forget(&owned2);
forget(&&owned2);
forget(&mut owned2);
forget(owned2); //OK

let reference1 = &SomeStruct;
drop(reference1);
forget(&*reference1);

let reference2 = &mut SomeStruct;
drop(reference2);
let reference3 = &mut SomeStruct;
forget(reference3);

let ref reference4 = SomeStruct;
drop(reference4);
forget(reference4);
let ref reference3 = SomeStruct;
drop(reference3);
}

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

#[allow(dead_code)]
fn test_generic_fn_forget<T>(val: T) {
forget(&val);
forget(val); //OK
}

#[allow(dead_code)]
fn test_similarly_named_function() {
fn drop<T>(_val: T) {}
drop(&SomeStruct); //OK; call to unrelated function which happens to have the same name
std::mem::drop(&SomeStruct);
fn forget<T>(_val: T) {}
forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name
std::mem::forget(&SomeStruct);
}

#[derive(Copy, Clone)]
Expand Down
111 changes: 111 additions & 0 deletions tests/ui/drop_ref.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:9:5
|
LL | drop(&SomeStruct);
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::drop-ref` implied by `-D warnings`
note: argument has type `&SomeStruct`
--> $DIR/drop_ref.rs:9:10
|
LL | drop(&SomeStruct);
| ^^^^^^^^^^^

error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:12:5
|
LL | drop(&owned1);
| ^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/drop_ref.rs:12:10
|
LL | drop(&owned1);
| ^^^^^^^

error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:13:5
|
LL | drop(&&owned1);
| ^^^^^^^^^^^^^^
|
note: argument has type `&&SomeStruct`
--> $DIR/drop_ref.rs:13:10
|
LL | drop(&&owned1);
| ^^^^^^^^

error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:14:5
|
LL | drop(&mut owned1);
| ^^^^^^^^^^^^^^^^^
|
note: argument has type `&mut SomeStruct`
--> $DIR/drop_ref.rs:14:10
|
LL | drop(&mut owned1);
| ^^^^^^^^^^^

error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:18:5
|
LL | drop(reference1);
| ^^^^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/drop_ref.rs:18:10
|
LL | drop(reference1);
| ^^^^^^^^^^

error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:21:5
|
LL | drop(reference2);
| ^^^^^^^^^^^^^^^^
|
note: argument has type `&mut SomeStruct`
--> $DIR/drop_ref.rs:21:10
|
LL | drop(reference2);
| ^^^^^^^^^^

error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:24:5
|
LL | drop(reference3);
| ^^^^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/drop_ref.rs:24:10
|
LL | drop(reference3);
| ^^^^^^^^^^

error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:29:5
|
LL | drop(&val);
| ^^^^^^^^^^
|
note: argument has type `&T`
--> $DIR/drop_ref.rs:29:10
|
LL | drop(&val);
| ^^^^

error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:37:5
|
LL | std::mem::drop(&SomeStruct);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/drop_ref.rs:37:20
|
LL | std::mem::drop(&SomeStruct);
| ^^^^^^^^^^^

error: aborting due to 9 previous errors

Loading

0 comments on commit fa32b41

Please sign in to comment.