fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

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