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