]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/drop_ref.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / drop_ref.rs
CommitLineData
f20569fa
XL
1#![warn(clippy::drop_ref)]
2#![allow(clippy::toplevel_ref_arg)]
3#![allow(clippy::map_err_ignore)]
04454e1e 4#![allow(clippy::unnecessary_wraps, clippy::drop_non_drop)]
f20569fa
XL
5
6use std::mem::drop;
7
8struct SomeStruct;
9
10fn main() {
11 drop(&SomeStruct);
12
13 let mut owned1 = SomeStruct;
14 drop(&owned1);
15 drop(&&owned1);
16 drop(&mut owned1);
17 drop(owned1); //OK
18
19 let reference1 = &SomeStruct;
20 drop(reference1);
21
22 let reference2 = &mut SomeStruct;
23 drop(reference2);
24
25 let ref reference3 = SomeStruct;
26 drop(reference3);
27}
28
29#[allow(dead_code)]
30fn test_generic_fn_drop<T>(val: T) {
31 drop(&val);
32 drop(val); //OK
33}
34
35#[allow(dead_code)]
36fn test_similarly_named_function() {
37 fn drop<T>(_val: T) {}
38 drop(&SomeStruct); //OK; call to unrelated function which happens to have the same name
39 std::mem::drop(&SomeStruct);
40}
41
42#[derive(Copy, Clone)]
43pub struct Error;
44fn produce_half_owl_error() -> Result<(), Error> {
45 Ok(())
46}
47
48fn produce_half_owl_ok() -> Result<bool, ()> {
49 Ok(true)
50}
51
52#[allow(dead_code)]
53fn test_owl_result() -> Result<(), ()> {
54 produce_half_owl_error().map_err(|_| ())?;
55 produce_half_owl_ok().map(|_| ())?;
56 // the following should not be linted,
57 // we should not force users to use toilet closures
58 // to produce owl results when drop is more convenient
59 produce_half_owl_error().map_err(drop)?;
60 produce_half_owl_ok().map_err(drop)?;
61 Ok(())
62}
63
64#[allow(dead_code)]
65fn test_owl_result_2() -> Result<u8, ()> {
66 produce_half_owl_error().map_err(|_| ())?;
67 produce_half_owl_ok().map(|_| ())?;
68 // the following should not be linted,
69 // we should not force users to use toilet closures
70 // to produce owl results when drop is more convenient
71 produce_half_owl_error().map_err(drop)?;
72 produce_half_owl_ok().map(drop)?;
73 Ok(1)
74}