diff options
| author | lapla-cogito <me@lapla.dev> | 2025-01-14 20:37:35 +0900 |
|---|---|---|
| committer | lapla-cogito <me@lapla.dev> | 2025-01-28 06:29:45 +0900 |
| commit | d99eae432563b955da5bddff8ca678ac3f7eb9c8 (patch) | |
| tree | cf5f51418691c6e6128e0d58a39a76093ee93d0b /tests | |
| parent | cb0a479d1f15831f99f0c8b6b730b3c804c5f9e1 (diff) | |
| download | rust-d99eae432563b955da5bddff8ca678ac3f7eb9c8.tar.gz rust-d99eae432563b955da5bddff8ca678ac3f7eb9c8.zip | |
correct suggestion for `drain_collect` in a `no_std` environment
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/drain_collect_nostd.fixed | 8 | ||||
| -rw-r--r-- | tests/ui/drain_collect_nostd.rs | 8 | ||||
| -rw-r--r-- | tests/ui/drain_collect_nostd.stderr | 11 |
3 files changed, 27 insertions, 0 deletions
diff --git a/tests/ui/drain_collect_nostd.fixed b/tests/ui/drain_collect_nostd.fixed new file mode 100644 index 00000000000..a4ab2956f2a --- /dev/null +++ b/tests/ui/drain_collect_nostd.fixed @@ -0,0 +1,8 @@ +#![warn(clippy::drain_collect)] +#![no_std] +extern crate alloc; +use alloc::vec::Vec; + +fn remove_all(v: &mut Vec<i32>) -> Vec<i32> { + core::mem::take(v) +} diff --git a/tests/ui/drain_collect_nostd.rs b/tests/ui/drain_collect_nostd.rs new file mode 100644 index 00000000000..a8be1ce6bbd --- /dev/null +++ b/tests/ui/drain_collect_nostd.rs @@ -0,0 +1,8 @@ +#![warn(clippy::drain_collect)] +#![no_std] +extern crate alloc; +use alloc::vec::Vec; + +fn remove_all(v: &mut Vec<i32>) -> Vec<i32> { + v.drain(..).collect() +} diff --git a/tests/ui/drain_collect_nostd.stderr b/tests/ui/drain_collect_nostd.stderr new file mode 100644 index 00000000000..91b38932fee --- /dev/null +++ b/tests/ui/drain_collect_nostd.stderr @@ -0,0 +1,11 @@ +error: you seem to be trying to move all elements into a new `Vec` + --> tests/ui/drain_collect_nostd.rs:7:5 + | +LL | v.drain(..).collect() + | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `mem::take`: `core::mem::take(v)` + | + = note: `-D clippy::drain-collect` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::drain_collect)]` + +error: aborting due to 1 previous error + |
