]> git.lizzy.rs Git - rust.git/blob - tests/ui/toplevel_ref_arg.rs
rustup and compile-fail -> ui test move
[rust.git] / tests / ui / toplevel_ref_arg.rs
1 #![feature(plugin)]
2
3 #![plugin(clippy)]
4 #![deny(clippy)]
5 #![allow(unused)]
6
7 fn the_answer(ref mut x: u8) {  //~ ERROR `ref` directly on a function argument is ignored
8   *x = 42;
9 }
10
11 fn main() {
12   let mut x = 0;
13   the_answer(x);
14   // Closures should not warn
15   let y = |ref x| { println!("{:?}", x) };
16   y(1u8);
17
18   let ref x = 1;
19   //~^ ERROR `ref` on an entire `let` pattern is discouraged
20   //~| HELP try
21   //~| SUGGESTION let x = &1;
22
23   let ref y: (&_, u8) = (&1, 2);
24   //~^ ERROR `ref` on an entire `let` pattern is discouraged
25   //~| HELP try
26   //~| SUGGESTION let y: &(&_, u8) = &(&1, 2);
27
28   let ref z = 1 + 2;
29   //~^ ERROR `ref` on an entire `let` pattern is discouraged
30   //~| HELP try
31   //~| SUGGESTION let z = &(1 + 2);
32
33   let ref mut z = 1 + 2;
34   //~^ ERROR `ref` on an entire `let` pattern is discouraged
35   //~| HELP try
36   //~| SUGGESTION let z = &mut (1 + 2);
37
38   let (ref x, _) = (1,2); // okay, not top level
39   println!("The answer is {}.", x);
40 }