2023-07-02 12:35:19 +00:00
|
|
|
//@aux-build:proc_macro_derive.rs:proc-macro
|
2023-04-23 11:03:09 +00:00
|
|
|
|
2021-10-07 09:21:30 +00:00
|
|
|
#![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)]
|
2023-07-31 21:53:53 +00:00
|
|
|
#![allow(
|
|
|
|
clippy::let_unit_value,
|
|
|
|
clippy::needless_if,
|
|
|
|
clippy::redundant_guards,
|
|
|
|
clippy::redundant_locals
|
|
|
|
)]
|
2021-10-07 09:21:30 +00:00
|
|
|
|
2023-04-23 11:03:09 +00:00
|
|
|
extern crate proc_macro_derive;
|
|
|
|
|
|
|
|
#[derive(proc_macro_derive::ShadowDerive)]
|
|
|
|
pub struct Nothing;
|
|
|
|
|
2023-05-05 15:45:49 +00:00
|
|
|
macro_rules! reuse {
|
|
|
|
($v:ident) => {
|
|
|
|
let $v = $v + 1;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-10-07 09:21:30 +00:00
|
|
|
fn shadow_same() {
|
|
|
|
let x = 1;
|
|
|
|
let x = x;
|
|
|
|
let mut x = &x;
|
|
|
|
let x = &mut x;
|
|
|
|
let x = *x;
|
2018-12-09 22:26:16 +00:00
|
|
|
}
|
2015-08-21 15:11:34 +00:00
|
|
|
|
2021-10-07 09:21:30 +00:00
|
|
|
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)?;
|
2021-10-21 11:11:36 +00:00
|
|
|
let y = 1;
|
|
|
|
let y = match y {
|
|
|
|
1 => 2,
|
|
|
|
_ => 3,
|
|
|
|
};
|
2021-10-07 09:21:30 +00:00
|
|
|
None
|
2018-12-09 22:26:16 +00:00
|
|
|
}
|
2015-08-21 15:11:34 +00:00
|
|
|
|
2023-05-05 15:45:49 +00:00
|
|
|
fn shadow_reuse_macro() {
|
|
|
|
let x = 1;
|
|
|
|
// this should not warn
|
|
|
|
reuse!(x);
|
|
|
|
}
|
|
|
|
|
2021-10-07 09:21:30 +00:00
|
|
|
fn shadow_unrelated() {
|
|
|
|
let x = 1;
|
|
|
|
let x = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn syntax() {
|
|
|
|
fn f(x: u32) {
|
|
|
|
let x = 1;
|
|
|
|
}
|
|
|
|
let x = 1;
|
|
|
|
match Some(1) {
|
|
|
|
Some(1) => {},
|
|
|
|
Some(x) => {
|
|
|
|
let x = 1;
|
|
|
|
},
|
|
|
|
_ => {},
|
2018-12-09 22:26:16 +00:00
|
|
|
}
|
2021-10-07 09:21:30 +00:00
|
|
|
if let Some(x) = Some(1) {}
|
|
|
|
while let Some(x) = Some(1) {}
|
|
|
|
let _ = |[x]: [u32; 1]| {
|
|
|
|
let x = 1;
|
2015-08-25 21:48:22 +00:00
|
|
|
};
|
2021-12-30 14:10:43 +00:00
|
|
|
let y = Some(1);
|
|
|
|
if let Some(y) = y {}
|
2021-10-07 09:21:30 +00:00
|
|
|
}
|
2015-09-08 09:50:04 +00:00
|
|
|
|
2021-10-07 09:21:30 +00:00
|
|
|
fn negative() {
|
|
|
|
match Some(1) {
|
|
|
|
Some(x) if x == 1 => {},
|
|
|
|
Some(x) => {},
|
|
|
|
None => {},
|
2015-09-08 09:50:04 +00:00
|
|
|
}
|
2021-10-07 09:21:30 +00:00
|
|
|
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
|
2015-08-21 15:11:34 +00:00
|
|
|
}
|
2021-10-07 09:21:30 +00:00
|
|
|
|
2021-12-06 11:33:31 +00:00
|
|
|
pub async fn foo1(_a: i32) {}
|
|
|
|
|
|
|
|
pub async fn foo2(_a: i32, _b: i64) {
|
|
|
|
let _b = _a;
|
|
|
|
}
|
|
|
|
|
2022-06-04 11:34:07 +00:00
|
|
|
fn ice_8748() {
|
|
|
|
let _ = [0; {
|
|
|
|
let x = 1;
|
|
|
|
if let Some(x) = Some(1) { x } else { 1 }
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2021-10-07 09:21:30 +00:00
|
|
|
fn main() {}
|