Skip to content

Commit e2ba75d

Browse files
committed
Add macro test
1 parent 3eea494 commit e2ba75d

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

tests/ui/swap.fixed

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
redundant_semicolons,
99
dead_code,
1010
unused_assignments,
11-
unused_variables
11+
unused_variables,
12+
clippy::let_and_return
1213
)]
1314

1415
struct Foo(u32);
@@ -187,8 +188,16 @@ const fn issue_9864(mut u: u32) -> u32 {
187188
u + v
188189
}
189190

190-
#[allow(clippy::let_and_return)]
191+
macro_rules! issue_10421 {
192+
() => {
193+
let a = 1;
194+
let b = a;
195+
let b = b;
196+
};
197+
}
198+
191199
const fn issue_10421(x: u32) -> u32 {
200+
issue_10421!();
192201
let a = x;
193202
let a = a;
194203
let a = a;

tests/ui/swap.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
redundant_semicolons,
99
dead_code,
1010
unused_assignments,
11-
unused_variables
11+
unused_variables,
12+
clippy::let_and_return
1213
)]
1314

1415
struct Foo(u32);
@@ -216,8 +217,16 @@ const fn issue_9864(mut u: u32) -> u32 {
216217
u + v
217218
}
218219

219-
#[allow(clippy::let_and_return)]
220+
macro_rules! issue_10421 {
221+
() => {
222+
let a = 1;
223+
let b = a;
224+
let b = b;
225+
};
226+
}
227+
220228
const fn issue_10421(x: u32) -> u32 {
229+
issue_10421!();
221230
let a = x;
222231
let a = a;
223232
let a = a;

tests/ui/swap.stderr

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this looks like you are swapping `bar.a` and `bar.b` manually
2-
--> $DIR/swap.rs:25:5
2+
--> $DIR/swap.rs:26:5
33
|
44
LL | / let temp = bar.a;
55
LL | | bar.a = bar.b;
@@ -10,55 +10,55 @@ LL | | bar.b = temp;
1010
= note: `-D clippy::manual-swap` implied by `-D warnings`
1111

1212
error: this looks like you are swapping elements of `foo` manually
13-
--> $DIR/swap.rs:37:5
13+
--> $DIR/swap.rs:38:5
1414
|
1515
LL | / let temp = foo[0];
1616
LL | | foo[0] = foo[1];
1717
LL | | foo[1] = temp;
1818
| |__________________^ help: try: `foo.swap(0, 1);`
1919

2020
error: this looks like you are swapping elements of `foo` manually
21-
--> $DIR/swap.rs:46:5
21+
--> $DIR/swap.rs:47:5
2222
|
2323
LL | / let temp = foo[0];
2424
LL | | foo[0] = foo[1];
2525
LL | | foo[1] = temp;
2626
| |__________________^ help: try: `foo.swap(0, 1);`
2727

2828
error: this looks like you are swapping elements of `foo` manually
29-
--> $DIR/swap.rs:65:5
29+
--> $DIR/swap.rs:66:5
3030
|
3131
LL | / let temp = foo[0];
3232
LL | | foo[0] = foo[1];
3333
LL | | foo[1] = temp;
3434
| |__________________^ help: try: `foo.swap(0, 1);`
3535

3636
error: this looks like you are swapping `a` and `b` manually
37-
--> $DIR/swap.rs:76:5
37+
--> $DIR/swap.rs:77:5
3838
|
3939
LL | / a ^= b;
4040
LL | | b ^= a;
4141
LL | | a ^= b;
4242
| |___________^ help: try: `std::mem::swap(&mut a, &mut b);`
4343

4444
error: this looks like you are swapping `bar.a` and `bar.b` manually
45-
--> $DIR/swap.rs:84:5
45+
--> $DIR/swap.rs:85:5
4646
|
4747
LL | / bar.a ^= bar.b;
4848
LL | | bar.b ^= bar.a;
4949
LL | | bar.a ^= bar.b;
5050
| |___________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b);`
5151

5252
error: this looks like you are swapping elements of `foo` manually
53-
--> $DIR/swap.rs:92:5
53+
--> $DIR/swap.rs:93:5
5454
|
5555
LL | / foo[0] ^= foo[1];
5656
LL | | foo[1] ^= foo[0];
5757
LL | | foo[0] ^= foo[1];
5858
| |_____________________^ help: try: `foo.swap(0, 1);`
5959

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

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

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

9292
error: this looks like you are swapping `b` and `a` manually
93-
--> $DIR/swap.rs:170:5
93+
--> $DIR/swap.rs:171:5
9494
|
9595
LL | / let t = b;
9696
LL | | b = a;
@@ -100,7 +100,7 @@ LL | | a = t;
100100
= note: or maybe you should use `std::mem::replace`?
101101

102102
error: this looks like you are trying to swap `a` and `b`
103-
--> $DIR/swap.rs:132:5
103+
--> $DIR/swap.rs:133:5
104104
|
105105
LL | / a = b;
106106
LL | | b = a;
@@ -110,7 +110,7 @@ LL | | b = a;
110110
= note: `-D clippy::almost-swapped` implied by `-D warnings`
111111

112112
error: this looks like you are trying to swap `c.0` and `a`
113-
--> $DIR/swap.rs:141:5
113+
--> $DIR/swap.rs:142:5
114114
|
115115
LL | / c.0 = a;
116116
LL | | a = c.0;
@@ -119,7 +119,7 @@ LL | | a = c.0;
119119
= note: or maybe you should use `std::mem::replace`?
120120

121121
error: this looks like you are trying to swap `a` and `b`
122-
--> $DIR/swap.rs:148:5
122+
--> $DIR/swap.rs:149:5
123123
|
124124
LL | / let a = b;
125125
LL | | let b = a;
@@ -128,7 +128,7 @@ LL | | let b = a;
128128
= note: or maybe you should use `std::mem::replace`?
129129

130130
error: this looks like you are trying to swap `d` and `c`
131-
--> $DIR/swap.rs:153:5
131+
--> $DIR/swap.rs:154:5
132132
|
133133
LL | / d = c;
134134
LL | | c = d;
@@ -137,7 +137,7 @@ LL | | c = d;
137137
= note: or maybe you should use `std::mem::replace`?
138138

139139
error: this looks like you are trying to swap `a` and `b`
140-
--> $DIR/swap.rs:157:5
140+
--> $DIR/swap.rs:158:5
141141
|
142142
LL | / let a = b;
143143
LL | | b = a;
@@ -146,7 +146,7 @@ LL | | b = a;
146146
= note: or maybe you should use `std::mem::replace`?
147147

148148
error: this looks like you are swapping `s.0.x` and `s.0.y` manually
149-
--> $DIR/swap.rs:205:5
149+
--> $DIR/swap.rs:206:5
150150
|
151151
LL | / let t = s.0.x;
152152
LL | | s.0.x = s.0.y;

0 commit comments

Comments
 (0)