Skip to content

Commit 3cff4e1

Browse files
committed
Add crate level no_std test for swap
1 parent fe98155 commit 3cff4e1

File tree

5 files changed

+49
-70
lines changed

5 files changed

+49
-70
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![no_std]
2+
#![feature(lang_items, start, libc)]
3+
4+
use core::panic::PanicInfo;
5+
6+
#[warn(clippy::all)]
7+
fn main() {
8+
// TODO: do somethjing with swap
9+
let mut a = 42;
10+
let mut b = 1337;
11+
12+
a = b;
13+
b = a;
14+
}
15+
16+
#[allow(clippy::empty_loop)]
17+
#[panic_handler]
18+
fn panic(_info: &PanicInfo) -> ! {
19+
loop {}
20+
}
21+
22+
#[lang = "eh_personality"]
23+
extern "C" fn eh_personality() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: this looks like you are trying to swap `a` and `b`
2+
--> $DIR/no_std_swap.rs:12:5
3+
|
4+
LL | / a = b;
5+
LL | | b = a;
6+
| |_________^ help: try: `core::mem::swap(&mut a, &mut b)`
7+
|
8+
= note: `-D clippy::almost-swapped` implied by `-D warnings`
9+
= note: or maybe you should use `core::mem::replace`?
10+
11+
error: aborting due to previous error
12+

tests/ui/swap.fixed

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
dead_code,
1010
unused_assignments
1111
)]
12-
#![feature(no_core)]
1312

1413
struct Foo(u32);
1514

@@ -107,28 +106,6 @@ fn distinct_slice() {
107106
std::mem::swap(&mut foo[0][1], &mut bar[1][0]);
108107
}
109108

110-
fn test_no_std() {
111-
#![allow(unused_attributes)]
112-
#![no_std]
113-
114-
let mut a = 42;
115-
let mut b = 1337;
116-
117-
core::mem::swap(&mut a, &mut b);
118-
}
119-
120-
fn test_no_std_and_core() {
121-
#![allow(unused_attributes)]
122-
#![no_std]
123-
#![no_core]
124-
125-
let mut a = 42;
126-
let mut b = 1337;
127-
128-
a = b;
129-
b = a;
130-
}
131-
132109
#[rustfmt::skip]
133110
fn main() {
134111

tests/ui/swap.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
dead_code,
1010
unused_assignments
1111
)]
12-
#![feature(no_core)]
1312

1413
struct Foo(u32);
1514

@@ -123,29 +122,6 @@ fn distinct_slice() {
123122
bar[1][0] = temp;
124123
}
125124

126-
fn test_no_std() {
127-
#![allow(unused_attributes)]
128-
#![no_std]
129-
130-
let mut a = 42;
131-
let mut b = 1337;
132-
133-
a = b;
134-
b = a;
135-
}
136-
137-
fn test_no_std_and_core() {
138-
#![allow(unused_attributes)]
139-
#![no_std]
140-
#![no_core]
141-
142-
let mut a = 42;
143-
let mut b = 1337;
144-
145-
a = b;
146-
b = a;
147-
}
148-
149125
#[rustfmt::skip]
150126
fn main() {
151127

tests/ui/swap.stderr

Lines changed: 14 additions & 23 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:24:5
33
|
44
LL | / let temp = bar.a;
55
LL | | bar.a = bar.b;
@@ -10,55 +10,55 @@ LL | | bar.b = temp;
1010
= note: or maybe you should use `std::mem::replace`?
1111

1212
error: this looks like you are swapping elements of `foo` manually
13-
--> $DIR/swap.rs:37:5
13+
--> $DIR/swap.rs:36: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:45: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:64: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:75: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:83: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:91: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:120:5
6262
|
6363
LL | / let temp = foo[0][1];
6464
LL | | foo[0][1] = bar[1][0];
@@ -67,18 +67,8 @@ LL | | bar[1][0] = temp;
6767
|
6868
= note: or maybe you should use `std::mem::replace`?
6969

70-
error: this looks like you are trying to swap `a` and `b`
71-
--> $DIR/swap.rs:133:5
72-
|
73-
LL | / a = b;
74-
LL | | b = a;
75-
| |_________^ help: try: `core::mem::swap(&mut a, &mut b)`
76-
|
77-
= note: `-D clippy::almost-swapped` implied by `-D warnings`
78-
= note: or maybe you should use `core::mem::replace`?
79-
8070
error: this looks like you are swapping `a` and `b` manually
81-
--> $DIR/swap.rs:158:7
71+
--> $DIR/swap.rs:134:7
8272
|
8373
LL | ; let t = a;
8474
| _______^
@@ -89,7 +79,7 @@ LL | | b = t;
8979
= note: or maybe you should use `std::mem::replace`?
9080

9181
error: this looks like you are swapping `c.0` and `a` manually
92-
--> $DIR/swap.rs:167:7
82+
--> $DIR/swap.rs:143:7
9383
|
9484
LL | ; let t = c.0;
9585
| _______^
@@ -100,22 +90,23 @@ LL | | a = t;
10090
= note: or maybe you should use `std::mem::replace`?
10191

10292
error: this looks like you are trying to swap `a` and `b`
103-
--> $DIR/swap.rs:155:5
93+
--> $DIR/swap.rs:131:5
10494
|
10595
LL | / a = b;
10696
LL | | b = a;
10797
| |_________^ help: try: `std::mem::swap(&mut a, &mut b)`
10898
|
99+
= note: `-D clippy::almost-swapped` implied by `-D warnings`
109100
= note: or maybe you should use `std::mem::replace`?
110101

111102
error: this looks like you are trying to swap `c.0` and `a`
112-
--> $DIR/swap.rs:164:5
103+
--> $DIR/swap.rs:140:5
113104
|
114105
LL | / c.0 = a;
115106
LL | | a = c.0;
116107
| |___________^ help: try: `std::mem::swap(&mut c.0, &mut a)`
117108
|
118109
= note: or maybe you should use `std::mem::replace`?
119110

120-
error: aborting due to 13 previous errors
111+
error: aborting due to 12 previous errors
121112

0 commit comments

Comments
 (0)