mut_fn/double_refs.rs
1// File: ./examples/mut_fn/double_refs.rs
2// clear && cargo run --example mut_fn --features ok -- double_refs | bat -l rs
3// clear && cargo run --example mut_fn --features err_01
4// clear && cargo run --example mut_fn --features err_02
5
6//=======
7#![allow(unused)]
8
9
10
11//=======
12#[cfg(feature = "ok")]
13pub fn adjoin() {
14 // ANCHOR: feature-ok
15 // File: ./examples/mut_fn/double_refs.rs
16 // #[cfg(feature = "ok")]
17
18 fn fn_borrowed(mut_ref: &mut i32) {}
19 fn fn_borrow(mut_ref: &mut i32) {
20 fn_borrowed(mut_ref); // mutable borrow occurs here
21 let immut_ref = mut_ref; // immutable borrow occurs here
22
23 println!("{}", immut_ref); // immutable borrow later used here
24 }
25
26 // ANCHOR_END: feature-ok
27}
28
29
30//=======
31#[cfg(feature = "err_01")]
32pub fn adjoin() {
33 // ANCHOR: feature-error_01
34 // File: ./examples/mut_var_sized/string_refs.rs
35 // ANCHOR = "string_refs-error_01"
36 // error[E0382]: borrow of moved value: `mut_ref`
37
38 fn fn_borrowed(mut_ref: &mut i32) {}
39 fn fn_borrow(mut_ref: &mut i32) {
40 let immut_ref = mut_ref;
41 fn_borrowed(mut_ref);
42 println!("{}", immut_ref);
43 }
44
45 // ANCHOR_END: feature-err_01
46}
47
48
49
50//=======
51#[cfg(feature = "err_02")]
52pub fn adjoin() {
53 fn fn_borrowed(mut_ref: &mut i32) {}
54 fn fn_borrow(mut_ref: &mut i32) {
55 let immut_ref_ref = &mut_ref;
56 fn_borrowed(mut_ref);
57 println!("{}", immut_ref_ref);
58 }
59}
60
61
62
63//=======
64#[cfg(all(
65 not(feature = "ok"),
66 not(feature = "err_01"),
67 not(feature = "err_02"),
68))]
69pub fn adjoin() {
70 use aide::*;
71 hello();
72}
73
74// https://doc.rust-lang.org/stable/error-index.html#E0502