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