]> git.lizzy.rs Git - rust.git/blob - tests/ui/toplevel_ref_arg.fixed
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / toplevel_ref_arg.fixed
1 // run-rustfix
2 // aux-build:macro_rules.rs
3 #![warn(clippy::toplevel_ref_arg)]
4 #![allow(clippy::uninlined_format_args)]
5
6 #[macro_use]
7 extern crate macro_rules;
8
9 macro_rules! gen_binding {
10     () => {
11         let _y = &42;
12     };
13 }
14
15 fn main() {
16     // Closures should not warn
17     let y = |ref x| println!("{:?}", x);
18     y(1u8);
19
20     let _x = &1;
21
22     let _y: &(&_, u8) = &(&1, 2);
23
24     let _z = &(1 + 2);
25
26     let _z = &mut (1 + 2);
27
28     let (ref x, _) = (1, 2); // ok, not top level
29     println!("The answer is {}.", x);
30
31     let _x = &vec![1, 2, 3];
32
33     // Make sure that allowing the lint works
34     #[allow(clippy::toplevel_ref_arg)]
35     let ref mut _x = 1_234_543;
36
37     // ok
38     for ref _x in 0..10 {}
39
40     // lint in macro
41     #[allow(unused)]
42     {
43         gen_binding!();
44     }
45
46     // do not lint in external macro
47     {
48         ref_arg_binding!();
49     }
50 }