mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Ignore shadow
warns in code from macro expansions
This commit is contained in:
parent
c976ad07ee
commit
628605e07a
@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
|
||||
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
|
||||
let PatKind::Binding(_, id, ident, _) = pat.kind else { return };
|
||||
|
||||
if pat.span.desugaring_kind().is_some() {
|
||||
if pat.span.desugaring_kind().is_some() || pat.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,12 @@ extern crate proc_macro_derive;
|
||||
#[derive(proc_macro_derive::ShadowDerive)]
|
||||
pub struct Nothing;
|
||||
|
||||
macro_rules! reuse {
|
||||
($v:ident) => {
|
||||
let $v = $v + 1;
|
||||
};
|
||||
}
|
||||
|
||||
fn shadow_same() {
|
||||
let x = 1;
|
||||
let x = x;
|
||||
@ -33,6 +39,12 @@ fn shadow_reuse() -> Option<()> {
|
||||
None
|
||||
}
|
||||
|
||||
fn shadow_reuse_macro() {
|
||||
let x = 1;
|
||||
// this should not warn
|
||||
reuse!(x);
|
||||
}
|
||||
|
||||
fn shadow_unrelated() {
|
||||
let x = 1;
|
||||
let x = 2;
|
||||
|
@ -1,278 +1,278 @@
|
||||
error: `x` is shadowed by itself in `x`
|
||||
--> $DIR/shadow.rs:13:9
|
||||
--> $DIR/shadow.rs:19:9
|
||||
|
|
||||
LL | let x = x;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:12:9
|
||||
--> $DIR/shadow.rs:18:9
|
||||
|
|
||||
LL | let x = 1;
|
||||
| ^
|
||||
= note: `-D clippy::shadow-same` implied by `-D warnings`
|
||||
|
||||
error: `mut x` is shadowed by itself in `&x`
|
||||
--> $DIR/shadow.rs:14:13
|
||||
--> $DIR/shadow.rs:20:13
|
||||
|
|
||||
LL | let mut x = &x;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:13:9
|
||||
--> $DIR/shadow.rs:19:9
|
||||
|
|
||||
LL | let x = x;
|
||||
| ^
|
||||
|
||||
error: `x` is shadowed by itself in `&mut x`
|
||||
--> $DIR/shadow.rs:15:9
|
||||
--> $DIR/shadow.rs:21:9
|
||||
|
|
||||
LL | let x = &mut x;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:14:9
|
||||
--> $DIR/shadow.rs:20:9
|
||||
|
|
||||
LL | let mut x = &x;
|
||||
| ^^^^^
|
||||
|
||||
error: `x` is shadowed by itself in `*x`
|
||||
--> $DIR/shadow.rs:16:9
|
||||
--> $DIR/shadow.rs:22:9
|
||||
|
|
||||
LL | let x = *x;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:15:9
|
||||
--> $DIR/shadow.rs:21:9
|
||||
|
|
||||
LL | let x = &mut x;
|
||||
| ^
|
||||
|
||||
error: `x` is shadowed
|
||||
--> $DIR/shadow.rs:21:9
|
||||
--> $DIR/shadow.rs:27:9
|
||||
|
|
||||
LL | let x = x.0;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:20:9
|
||||
--> $DIR/shadow.rs:26:9
|
||||
|
|
||||
LL | let x = ([[0]], ());
|
||||
| ^
|
||||
= note: `-D clippy::shadow-reuse` implied by `-D warnings`
|
||||
|
||||
error: `x` is shadowed
|
||||
--> $DIR/shadow.rs:22:9
|
||||
--> $DIR/shadow.rs:28:9
|
||||
|
|
||||
LL | let x = x[0];
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:21:9
|
||||
--> $DIR/shadow.rs:27:9
|
||||
|
|
||||
LL | let x = x.0;
|
||||
| ^
|
||||
|
||||
error: `x` is shadowed
|
||||
--> $DIR/shadow.rs:23:10
|
||||
--> $DIR/shadow.rs:29:10
|
||||
|
|
||||
LL | let [x] = x;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:22:9
|
||||
--> $DIR/shadow.rs:28:9
|
||||
|
|
||||
LL | let x = x[0];
|
||||
| ^
|
||||
|
||||
error: `x` is shadowed
|
||||
--> $DIR/shadow.rs:24:9
|
||||
--> $DIR/shadow.rs:30:9
|
||||
|
|
||||
LL | let x = Some(x);
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:23:10
|
||||
--> $DIR/shadow.rs:29:10
|
||||
|
|
||||
LL | let [x] = x;
|
||||
| ^
|
||||
|
||||
error: `x` is shadowed
|
||||
--> $DIR/shadow.rs:25:9
|
||||
--> $DIR/shadow.rs:31:9
|
||||
|
|
||||
LL | let x = foo(x);
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:24:9
|
||||
--> $DIR/shadow.rs:30:9
|
||||
|
|
||||
LL | let x = Some(x);
|
||||
| ^
|
||||
|
||||
error: `x` is shadowed
|
||||
--> $DIR/shadow.rs:26:9
|
||||
--> $DIR/shadow.rs:32:9
|
||||
|
|
||||
LL | let x = || x;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:25:9
|
||||
--> $DIR/shadow.rs:31:9
|
||||
|
|
||||
LL | let x = foo(x);
|
||||
| ^
|
||||
|
||||
error: `x` is shadowed
|
||||
--> $DIR/shadow.rs:27:9
|
||||
--> $DIR/shadow.rs:33:9
|
||||
|
|
||||
LL | let x = Some(1).map(|_| x)?;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:26:9
|
||||
--> $DIR/shadow.rs:32:9
|
||||
|
|
||||
LL | let x = || x;
|
||||
| ^
|
||||
|
||||
error: `y` is shadowed
|
||||
--> $DIR/shadow.rs:29:9
|
||||
--> $DIR/shadow.rs:35:9
|
||||
|
|
||||
LL | let y = match y {
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:28:9
|
||||
--> $DIR/shadow.rs:34:9
|
||||
|
|
||||
LL | let y = 1;
|
||||
| ^
|
||||
|
||||
error: `x` shadows a previous, unrelated binding
|
||||
--> $DIR/shadow.rs:38:9
|
||||
--> $DIR/shadow.rs:50:9
|
||||
|
|
||||
LL | let x = 2;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:37:9
|
||||
--> $DIR/shadow.rs:49:9
|
||||
|
|
||||
LL | let x = 1;
|
||||
| ^
|
||||
= note: `-D clippy::shadow-unrelated` implied by `-D warnings`
|
||||
|
||||
error: `x` shadows a previous, unrelated binding
|
||||
--> $DIR/shadow.rs:43:13
|
||||
--> $DIR/shadow.rs:55:13
|
||||
|
|
||||
LL | let x = 1;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:42:10
|
||||
--> $DIR/shadow.rs:54:10
|
||||
|
|
||||
LL | fn f(x: u32) {
|
||||
| ^
|
||||
|
||||
error: `x` shadows a previous, unrelated binding
|
||||
--> $DIR/shadow.rs:48:14
|
||||
--> $DIR/shadow.rs:60:14
|
||||
|
|
||||
LL | Some(x) => {
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:45:9
|
||||
--> $DIR/shadow.rs:57:9
|
||||
|
|
||||
LL | let x = 1;
|
||||
| ^
|
||||
|
||||
error: `x` shadows a previous, unrelated binding
|
||||
--> $DIR/shadow.rs:49:17
|
||||
--> $DIR/shadow.rs:61:17
|
||||
|
|
||||
LL | let x = 1;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:48:14
|
||||
--> $DIR/shadow.rs:60:14
|
||||
|
|
||||
LL | Some(x) => {
|
||||
| ^
|
||||
|
||||
error: `x` shadows a previous, unrelated binding
|
||||
--> $DIR/shadow.rs:53:17
|
||||
--> $DIR/shadow.rs:65:17
|
||||
|
|
||||
LL | if let Some(x) = Some(1) {}
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:45:9
|
||||
--> $DIR/shadow.rs:57:9
|
||||
|
|
||||
LL | let x = 1;
|
||||
| ^
|
||||
|
||||
error: `x` shadows a previous, unrelated binding
|
||||
--> $DIR/shadow.rs:54:20
|
||||
--> $DIR/shadow.rs:66:20
|
||||
|
|
||||
LL | while let Some(x) = Some(1) {}
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:45:9
|
||||
--> $DIR/shadow.rs:57:9
|
||||
|
|
||||
LL | let x = 1;
|
||||
| ^
|
||||
|
||||
error: `x` shadows a previous, unrelated binding
|
||||
--> $DIR/shadow.rs:55:15
|
||||
--> $DIR/shadow.rs:67:15
|
||||
|
|
||||
LL | let _ = |[x]: [u32; 1]| {
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:45:9
|
||||
--> $DIR/shadow.rs:57:9
|
||||
|
|
||||
LL | let x = 1;
|
||||
| ^
|
||||
|
||||
error: `x` shadows a previous, unrelated binding
|
||||
--> $DIR/shadow.rs:56:13
|
||||
--> $DIR/shadow.rs:68:13
|
||||
|
|
||||
LL | let x = 1;
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:55:15
|
||||
--> $DIR/shadow.rs:67:15
|
||||
|
|
||||
LL | let _ = |[x]: [u32; 1]| {
|
||||
| ^
|
||||
|
||||
error: `y` is shadowed
|
||||
--> $DIR/shadow.rs:59:17
|
||||
--> $DIR/shadow.rs:71:17
|
||||
|
|
||||
LL | if let Some(y) = y {}
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:58:9
|
||||
--> $DIR/shadow.rs:70:9
|
||||
|
|
||||
LL | let y = Some(1);
|
||||
| ^
|
||||
|
||||
error: `_b` shadows a previous, unrelated binding
|
||||
--> $DIR/shadow.rs:95:9
|
||||
--> $DIR/shadow.rs:107:9
|
||||
|
|
||||
LL | let _b = _a;
|
||||
| ^^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:94:28
|
||||
--> $DIR/shadow.rs:106:28
|
||||
|
|
||||
LL | pub async fn foo2(_a: i32, _b: i64) {
|
||||
| ^^
|
||||
|
||||
error: `x` shadows a previous, unrelated binding
|
||||
--> $DIR/shadow.rs:101:21
|
||||
--> $DIR/shadow.rs:113:21
|
||||
|
|
||||
LL | if let Some(x) = Some(1) { x } else { 1 }
|
||||
| ^
|
||||
|
|
||||
note: previous binding is here
|
||||
--> $DIR/shadow.rs:100:13
|
||||
--> $DIR/shadow.rs:112:13
|
||||
|
|
||||
LL | let x = 1;
|
||||
| ^
|
||||
|
Loading…
Reference in New Issue
Block a user