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