Skip to content

Commit

Permalink
Add external macro test
Browse files Browse the repository at this point in the history
  • Loading branch information
blyxyas committed Mar 16, 2023
1 parent e2ba75d commit 8462b08
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
9 changes: 9 additions & 0 deletions tests/ui/auxiliary/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ macro_rules! mut_mut {
let mut_mut_ty: &mut &mut u32 = &mut &mut 1u32;
};
}

#[macro_export]
macro_rules! issue_10421 {
() => {
let a = 1;
let a = a;
let a = a;
};
}
10 changes: 3 additions & 7 deletions tests/ui/swap.fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-rustfix
// aux-build: macro_rules.rs

#![warn(clippy::all)]
#![allow(
Expand Down Expand Up @@ -188,13 +189,8 @@ const fn issue_9864(mut u: u32) -> u32 {
u + v
}

macro_rules! issue_10421 {
() => {
let a = 1;
let b = a;
let b = b;
};
}
#[macro_use]
extern crate macro_rules;

const fn issue_10421(x: u32) -> u32 {
issue_10421!();
Expand Down
10 changes: 3 additions & 7 deletions tests/ui/swap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-rustfix
// aux-build: macro_rules.rs

#![warn(clippy::all)]
#![allow(
Expand Down Expand Up @@ -217,13 +218,8 @@ const fn issue_9864(mut u: u32) -> u32 {
u + v
}

macro_rules! issue_10421 {
() => {
let a = 1;
let b = a;
let b = b;
};
}
#[macro_use]
extern crate macro_rules;

const fn issue_10421(x: u32) -> u32 {
issue_10421!();
Expand Down
34 changes: 17 additions & 17 deletions tests/ui/swap.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: this looks like you are swapping `bar.a` and `bar.b` manually
--> $DIR/swap.rs:26:5
--> $DIR/swap.rs:27:5
|
LL | / let temp = bar.a;
LL | | bar.a = bar.b;
Expand All @@ -10,55 +10,55 @@ LL | | bar.b = temp;
= note: `-D clippy::manual-swap` implied by `-D warnings`

error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:38:5
--> $DIR/swap.rs:39:5
|
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
LL | | foo[1] = temp;
| |__________________^ help: try: `foo.swap(0, 1);`

error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:47:5
--> $DIR/swap.rs:48:5
|
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
LL | | foo[1] = temp;
| |__________________^ help: try: `foo.swap(0, 1);`

error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:66:5
--> $DIR/swap.rs:67:5
|
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
LL | | foo[1] = temp;
| |__________________^ help: try: `foo.swap(0, 1);`

error: this looks like you are swapping `a` and `b` manually
--> $DIR/swap.rs:77:5
--> $DIR/swap.rs:78:5
|
LL | / a ^= b;
LL | | b ^= a;
LL | | a ^= b;
| |___________^ help: try: `std::mem::swap(&mut a, &mut b);`

error: this looks like you are swapping `bar.a` and `bar.b` manually
--> $DIR/swap.rs:85:5
--> $DIR/swap.rs:86:5
|
LL | / bar.a ^= bar.b;
LL | | bar.b ^= bar.a;
LL | | bar.a ^= bar.b;
| |___________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b);`

error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:93:5
--> $DIR/swap.rs:94:5
|
LL | / foo[0] ^= foo[1];
LL | | foo[1] ^= foo[0];
LL | | foo[0] ^= foo[1];
| |_____________________^ help: try: `foo.swap(0, 1);`

error: this looks like you are swapping `foo[0][1]` and `bar[1][0]` manually
--> $DIR/swap.rs:122:5
--> $DIR/swap.rs:123:5
|
LL | / let temp = foo[0][1];
LL | | foo[0][1] = bar[1][0];
Expand All @@ -68,7 +68,7 @@ LL | | bar[1][0] = temp;
= note: or maybe you should use `std::mem::replace`?

error: this looks like you are swapping `a` and `b` manually
--> $DIR/swap.rs:136:7
--> $DIR/swap.rs:137:7
|
LL | ; let t = a;
| _______^
Expand All @@ -79,7 +79,7 @@ LL | | b = t;
= note: or maybe you should use `std::mem::replace`?

error: this looks like you are swapping `c.0` and `a` manually
--> $DIR/swap.rs:145:7
--> $DIR/swap.rs:146:7
|
LL | ; let t = c.0;
| _______^
Expand All @@ -90,7 +90,7 @@ LL | | a = t;
= note: or maybe you should use `std::mem::replace`?

error: this looks like you are swapping `b` and `a` manually
--> $DIR/swap.rs:171:5
--> $DIR/swap.rs:172:5
|
LL | / let t = b;
LL | | b = a;
Expand All @@ -100,7 +100,7 @@ LL | | a = t;
= note: or maybe you should use `std::mem::replace`?

error: this looks like you are trying to swap `a` and `b`
--> $DIR/swap.rs:133:5
--> $DIR/swap.rs:134:5
|
LL | / a = b;
LL | | b = a;
Expand All @@ -110,7 +110,7 @@ LL | | b = a;
= note: `-D clippy::almost-swapped` implied by `-D warnings`

error: this looks like you are trying to swap `c.0` and `a`
--> $DIR/swap.rs:142:5
--> $DIR/swap.rs:143:5
|
LL | / c.0 = a;
LL | | a = c.0;
Expand All @@ -119,7 +119,7 @@ LL | | a = c.0;
= note: or maybe you should use `std::mem::replace`?

error: this looks like you are trying to swap `a` and `b`
--> $DIR/swap.rs:149:5
--> $DIR/swap.rs:150:5
|
LL | / let a = b;
LL | | let b = a;
Expand All @@ -128,7 +128,7 @@ LL | | let b = a;
= note: or maybe you should use `std::mem::replace`?

error: this looks like you are trying to swap `d` and `c`
--> $DIR/swap.rs:154:5
--> $DIR/swap.rs:155:5
|
LL | / d = c;
LL | | c = d;
Expand All @@ -137,7 +137,7 @@ LL | | c = d;
= note: or maybe you should use `std::mem::replace`?

error: this looks like you are trying to swap `a` and `b`
--> $DIR/swap.rs:158:5
--> $DIR/swap.rs:159:5
|
LL | / let a = b;
LL | | b = a;
Expand All @@ -146,7 +146,7 @@ LL | | b = a;
= note: or maybe you should use `std::mem::replace`?

error: this looks like you are swapping `s.0.x` and `s.0.y` manually
--> $DIR/swap.rs:206:5
--> $DIR/swap.rs:207:5
|
LL | / let t = s.0.x;
LL | | s.0.x = s.0.y;
Expand Down

0 comments on commit 8462b08

Please sign in to comment.