mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-27 07:03:45 +00:00
Add test for swap
lint when no_std
is present
Adds additional test to check for `swap` suggestion when `no_std` is present
This commit is contained in:
parent
2d037aa4a6
commit
dcd1a16dd0
15
tests/ui/crate_level_checks/no_std_swap.rs
Normal file
15
tests/ui/crate_level_checks/no_std_swap.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![feature(lang_items, start, libc)]
|
||||||
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
#[warn(clippy::all)]
|
||||||
|
fn main() {
|
||||||
|
// TODO: do somethjing with swap
|
||||||
|
let mut a = 42;
|
||||||
|
let mut b = 1337;
|
||||||
|
|
||||||
|
a = b;
|
||||||
|
b = a;
|
||||||
|
}
|
12
tests/ui/crate_level_checks/no_std_swap.stderr
Normal file
12
tests/ui/crate_level_checks/no_std_swap.stderr
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
error: this looks like you are trying to swap `a` and `b`
|
||||||
|
--> $DIR/no_std_swap.rs:13:5
|
||||||
|
|
|
||||||
|
LL | / a = b;
|
||||||
|
LL | | b = a;
|
||||||
|
| |_________^ help: try: `core::mem::swap(&mut a, &mut b)`
|
||||||
|
|
|
||||||
|
= note: `-D clippy::almost-swapped` implied by `-D warnings`
|
||||||
|
= note: or maybe you should use `core::mem::replace`?
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user