]> git.lizzy.rs Git - rust.git/blob - tests/ui/must_use_candidates.fixed
Rollup merge of #4830 - lzutao:str-repeat, r=flip1995
[rust.git] / tests / ui / must_use_candidates.fixed
1 // run-rustfix
2 #![allow(unused_mut)]
3 #![warn(clippy::must_use_candidate)]
4 use std::rc::Rc;
5 use std::sync::atomic::{AtomicBool, Ordering};
6 use std::sync::Arc;
7
8 pub struct MyAtomic(AtomicBool);
9 pub struct MyPure;
10
11 #[must_use] pub fn pure(i: u8) -> u8 {
12     i
13 }
14
15 impl MyPure {
16     #[must_use] pub fn inherent_pure(&self) -> u8 {
17         0
18     }
19 }
20
21 pub trait MyPureTrait {
22     fn trait_pure(&self, i: u32) -> u32 {
23         self.trait_impl_pure(i) + 1
24     }
25
26     fn trait_impl_pure(&self, i: u32) -> u32;
27 }
28
29 impl MyPureTrait for MyPure {
30     fn trait_impl_pure(&self, i: u32) -> u32 {
31         i
32     }
33 }
34
35 pub fn without_result() {
36     // OK
37 }
38
39 pub fn impure_primitive(i: &mut u8) -> u8 {
40     *i
41 }
42
43 pub fn with_callback<F: Fn(u32) -> bool>(f: &F) -> bool {
44     f(0)
45 }
46
47 #[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool {
48     true
49 }
50
51 pub fn quoth_the_raven(_more: !) -> u32 {
52     unimplemented!();
53 }
54
55 pub fn atomics(b: &AtomicBool) -> bool {
56     b.load(Ordering::SeqCst)
57 }
58
59 #[must_use] pub fn rcd(_x: Rc<u32>) -> bool {
60     true
61 }
62
63 pub fn rcmut(_x: Rc<&mut u32>) -> bool {
64     true
65 }
66
67 #[must_use] pub fn arcd(_x: Arc<u32>) -> bool {
68     false
69 }
70
71 pub fn inner_types(_m: &MyAtomic) -> bool {
72     true
73 }
74
75 static mut COUNTER: usize = 0;
76
77 /// # Safety
78 ///
79 /// Don't ever call this from multiple threads
80 pub unsafe fn mutates_static() -> usize {
81     COUNTER += 1;
82     COUNTER
83 }
84
85 fn main() {
86     assert_eq!(1, pure(1));
87 }