]> git.lizzy.rs Git - rust.git/blob - tests/ui/shadow.rs
rustup and compile-fail -> ui test move
[rust.git] / tests / ui / shadow.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #![deny(clippy, clippy_pedantic)]
5 #![allow(unused_parens, unused_variables, missing_docs_in_private_items)]
6
7 fn id<T>(x: T) -> T { x }
8
9 fn first(x: (isize, isize)) -> isize { x.0 }
10
11 fn main() {
12     let mut x = 1;
13     let x = &mut x; //~ERROR `x` is shadowed by itself in `&mut x`
14     let x = { x }; //~ERROR `x` is shadowed by itself in `{ x }`
15     let x = (&*x); //~ERROR `x` is shadowed by itself in `(&*x)`
16     let x = { *x + 1 }; //~ERROR `x` is shadowed by `{ *x + 1 }` which reuses
17     let x = id(x); //~ERROR `x` is shadowed by `id(x)` which reuses
18     let x = (1, x); //~ERROR `x` is shadowed by `(1, x)` which reuses
19     let x = first(x); //~ERROR `x` is shadowed by `first(x)` which reuses
20     let y = 1;
21     let x = y; //~ERROR `x` is shadowed by `y`
22
23     let x; //~ERROR `x` shadows a previous declaration
24     x = 42;
25
26     let o = Some(1_u8);
27
28     if let Some(p) = o { assert_eq!(1, p); }
29     match o {
30         Some(p) => p, // no error, because the p above is in its own scope
31         None => 0,
32     };
33
34     match (x, o) {
35         (1, Some(a)) | (a, Some(1)) => (), // no error though `a` appears twice
36         _ => (),
37     }
38 }