]> git.lizzy.rs Git - rust.git/blob - tests/ui/auxiliary/macro_rules.rs
Rollup merge of #81038 - flip1995:clippyup, r=Manishearth
[rust.git] / tests / ui / auxiliary / macro_rules.rs
1 #![allow(dead_code)]
2
3 //! Used to test that certain lints don't trigger in imported external macros
4
5 #[macro_export]
6 macro_rules! foofoo {
7     () => {
8         loop {}
9     };
10 }
11
12 #[macro_export]
13 macro_rules! must_use_unit {
14     () => {
15         #[must_use]
16         fn foo() {}
17     };
18 }
19
20 #[macro_export]
21 macro_rules! try_err {
22     () => {
23         pub fn try_err_fn() -> Result<i32, i32> {
24             let err: i32 = 1;
25             // To avoid warnings during rustfix
26             if true {
27                 Err(err)?
28             } else {
29                 Ok(2)
30             }
31         }
32     };
33 }
34
35 #[macro_export]
36 macro_rules! string_add {
37     () => {
38         let y = "".to_owned();
39         let z = y + "...";
40     };
41 }
42
43 #[macro_export]
44 macro_rules! take_external {
45     ($s:expr) => {
46         std::mem::replace($s, Default::default())
47     };
48 }
49
50 #[macro_export]
51 macro_rules! option_env_unwrap_external {
52     ($env: expr) => {
53         option_env!($env).unwrap()
54     };
55     ($env: expr, $message: expr) => {
56         option_env!($env).expect($message)
57     };
58 }
59
60 #[macro_export]
61 macro_rules! ref_arg_binding {
62     () => {
63         let ref _y = 42;
64     };
65 }
66
67 #[macro_export]
68 macro_rules! ref_arg_function {
69     () => {
70         fn fun_example(ref _x: usize) {}
71     };
72 }
73
74 #[macro_export]
75 macro_rules! as_conv_with_arg {
76     (0u32 as u64) => {
77         ()
78     };
79 }
80
81 #[macro_export]
82 macro_rules! as_conv {
83     () => {
84         0u32 as u64
85     };
86 }
87
88 #[macro_export]
89 macro_rules! large_enum_variant {
90     () => {
91         enum LargeEnumInMacro {
92             A(i32),
93             B([i32; 8000]),
94         }
95     };
96 }
97
98 #[macro_export]
99 macro_rules! field_reassign_with_default {
100     () => {
101         #[derive(Default)]
102         struct A {
103             pub i: i32,
104             pub j: i64,
105         }
106         fn lint() {
107             let mut a: A = Default::default();
108             a.i = 42;
109             a;
110         }
111     };
112 }