-#![feature(plugin)]
-#![plugin(clippy)]
+#![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)]
-#![deny(clippy, clippy_pedantic)]
-#![allow(unused_parens, unused_variables, missing_docs_in_private_items)]
-
-fn id<T>(x: T) -> T { x }
-
-fn first(x: (isize, isize)) -> isize { x.0 }
-
-fn main() {
- let mut x = 1;
- let x = &mut x; //~ERROR `x` is shadowed by itself in `&mut x`
- let x = { x }; //~ERROR `x` is shadowed by itself in `{ x }`
- let x = (&*x); //~ERROR `x` is shadowed by itself in `(&*x)`
- let x = { *x + 1 }; //~ERROR `x` is shadowed by `{ *x + 1 }` which reuses
- let x = id(x); //~ERROR `x` is shadowed by `id(x)` which reuses
- let x = (1, x); //~ERROR `x` is shadowed by `(1, x)` which reuses
- let x = first(x); //~ERROR `x` is shadowed by `first(x)` which reuses
- let y = 1;
- let x = y; //~ERROR `x` is shadowed by `y`
+fn shadow_same() {
+ let x = 1;
+ let x = x;
+ let mut x = &x;
+ let x = &mut x;
+ let x = *x;
+}
- let x; //~ERROR `x` shadows a previous declaration
- x = 42;
+fn shadow_reuse() -> Option<()> {
+ let x = ([[0]], ());
+ let x = x.0;
+ let x = x[0];
+ let [x] = x;
+ let x = Some(x);
+ let x = foo(x);
+ let x = || x;
+ let x = Some(1).map(|_| x)?;
+ None
+}
- let o = Some(1_u8);
+fn shadow_unrelated() {
+ let x = 1;
+ let x = 2;
+}
- if let Some(p) = o { assert_eq!(1, p); }
- match o {
- Some(p) => p, // no error, because the p above is in its own scope
- None => 0,
+fn syntax() {
+ fn f(x: u32) {
+ let x = 1;
+ }
+ let x = 1;
+ match Some(1) {
+ Some(1) => {},
+ Some(x) => {
+ let x = 1;
+ },
+ _ => {},
+ }
+ if let Some(x) = Some(1) {}
+ while let Some(x) = Some(1) {}
+ let _ = |[x]: [u32; 1]| {
+ let x = 1;
};
+}
- match (x, o) {
- (1, Some(a)) | (a, Some(1)) => (), // no error though `a` appears twice
- _ => (),
+fn negative() {
+ match Some(1) {
+ Some(x) if x == 1 => {},
+ Some(x) => {},
+ None => {},
+ }
+ match [None, Some(1)] {
+ [Some(x), None] | [None, Some(x)] => {},
+ _ => {},
}
+ if let Some(x) = Some(1) {
+ let y = 1;
+ } else {
+ let x = 1;
+ let y = 1;
+ }
+ let x = 1;
+ #[allow(clippy::shadow_unrelated)]
+ let x = 1;
}
+
+fn foo<T>(_: T) {}
+
+fn question_mark() -> Option<()> {
+ let val = 1;
+ // `?` expands with a `val` binding
+ None?;
+ None
+}
+
+fn main() {}