summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/must_use_candidates.fixed
blob: bbbb3cf621e41446426a319b1898039bdc8ca5f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// run-rustfix
#![feature(never_type)]
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
#![warn(clippy::must_use_candidate)]
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

pub struct MyAtomic(AtomicBool);
pub struct MyPure;

#[must_use] pub fn pure(i: u8) -> u8 {
    i
}

impl MyPure {
    #[must_use] pub fn inherent_pure(&self) -> u8 {
        0
    }
}

pub trait MyPureTrait {
    fn trait_pure(&self, i: u32) -> u32 {
        self.trait_impl_pure(i) + 1
    }

    fn trait_impl_pure(&self, i: u32) -> u32;
}

impl MyPureTrait for MyPure {
    fn trait_impl_pure(&self, i: u32) -> u32 {
        i
    }
}

pub fn without_result() {
    // OK
}

pub fn impure_primitive(i: &mut u8) -> u8 {
    *i
}

pub fn with_callback<F: Fn(u32) -> bool>(f: &F) -> bool {
    f(0)
}

#[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool {
    true
}

pub fn quoth_the_raven(_more: !) -> u32 {
    unimplemented!();
}

pub fn atomics(b: &AtomicBool) -> bool {
    b.load(Ordering::SeqCst)
}

#[must_use] pub fn rcd(_x: Rc<u32>) -> bool {
    true
}

pub fn rcmut(_x: Rc<&mut u32>) -> bool {
    true
}

#[must_use] pub fn arcd(_x: Arc<u32>) -> bool {
    false
}

pub fn inner_types(_m: &MyAtomic) -> bool {
    true
}

static mut COUNTER: usize = 0;

/// # Safety
///
/// Don't ever call this from multiple threads
pub unsafe fn mutates_static() -> usize {
    COUNTER += 1;
    COUNTER
}

#[no_mangle]
pub extern "C" fn unmangled(i: bool) -> bool {
    !i
}

fn main() {
    assert_eq!(1, pure(1));
}