]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/toplevel_ref_arg.rs
Rollup merge of #102187 - b-naber:inline-const-source-info, r=eholk
[rust.git] / src / tools / clippy / tests / ui / toplevel_ref_arg.rs
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 ref _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 ref _x = 1;
21
22     let ref _y: (&_, u8) = (&1, 2);
23
24     let ref _z = 1 + 2;
25
26     let ref mut _z = 1 + 2;
27
28     let (ref x, _) = (1, 2); // ok, not top level
29     println!("The answer is {}.", x);
30
31     let ref _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 }