-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
correct suggestions in no_std
#13999
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43b29da
correct suggestion for `redundant_closure` in a `no_std` environment
lapla-cogito e146039
correct suggestion for `repeat_vec_with_capacity` in a `no_std` envir…
lapla-cogito cb0a479
don't suggest to use `std::vec::Vec` for `single_range_in_vec_init` i…
lapla-cogito d99eae4
correct suggestion for `drain_collect` in a `no_std` environment
lapla-cogito 3b0b8b0
correct suggestion for `map_with_unused_argument_over_ranges` in a `n…
lapla-cogito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![warn(clippy::redundant_closure)] | ||
#![no_std] | ||
|
||
extern crate alloc; | ||
use alloc::vec; | ||
use alloc::vec::Vec; | ||
|
||
fn issue_13895() { | ||
let _: Option<Vec<u8>> = true.then(alloc::vec::Vec::new); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![warn(clippy::redundant_closure)] | ||
#![no_std] | ||
|
||
extern crate alloc; | ||
use alloc::vec; | ||
use alloc::vec::Vec; | ||
|
||
fn issue_13895() { | ||
let _: Option<Vec<u8>> = true.then(|| vec![]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: redundant closure | ||
--> tests/ui/eta_nostd.rs:9:40 | ||
| | ||
LL | let _: Option<Vec<u8>> = true.then(|| vec![]); | ||
| ^^^^^^^^^ help: replace the closure with `Vec::new`: `alloc::vec::Vec::new` | ||
| | ||
= note: `-D clippy::redundant-closure` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]` | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![warn(clippy::map_with_unused_argument_over_ranges)] | ||
#![no_std] | ||
extern crate alloc; | ||
use alloc::vec::Vec; | ||
|
||
fn nostd(v: &mut [i32]) { | ||
let _: Vec<_> = core::iter::repeat_n(3 + 1, 10).collect(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![warn(clippy::map_with_unused_argument_over_ranges)] | ||
#![no_std] | ||
extern crate alloc; | ||
use alloc::vec::Vec; | ||
|
||
fn nostd(v: &mut [i32]) { | ||
let _: Vec<_> = (0..10).map(|_| 3 + 1).collect(); | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/ui/map_with_unused_argument_over_ranges_nostd.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: map of a closure that does not depend on its parameter over a range | ||
--> tests/ui/map_with_unused_argument_over_ranges_nostd.rs:7:21 | ||
| | ||
LL | let _: Vec<_> = (0..10).map(|_| 3 + 1).collect(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::map-with-unused-argument-over-ranges` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::map_with_unused_argument_over_ranges)]` | ||
help: remove the explicit range and use `repeat_n` | ||
| | ||
LL | let _: Vec<_> = core::iter::repeat_n(3 + 1, 10).collect(); | ||
| ~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~ | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![warn(clippy::repeat_vec_with_capacity)] | ||
#![allow(clippy::manual_repeat_n)] | ||
#![no_std] | ||
use core::iter; | ||
extern crate alloc; | ||
use alloc::vec::Vec; | ||
|
||
fn nostd() { | ||
let _: Vec<Vec<u8>> = core::iter::repeat_with(|| Vec::with_capacity(42)).take(123).collect(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![warn(clippy::repeat_vec_with_capacity)] | ||
#![allow(clippy::manual_repeat_n)] | ||
#![no_std] | ||
use core::iter; | ||
extern crate alloc; | ||
use alloc::vec::Vec; | ||
|
||
fn nostd() { | ||
let _: Vec<Vec<u8>> = iter::repeat(Vec::with_capacity(42)).take(123).collect(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error: repeating `Vec::with_capacity` using `iter::repeat`, which does not retain capacity | ||
--> tests/ui/repeat_vec_with_capacity_nostd.rs:9:27 | ||
| | ||
LL | let _: Vec<Vec<u8>> = iter::repeat(Vec::with_capacity(42)).take(123).collect(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: none of the yielded `Vec`s will have the requested capacity | ||
= note: `-D clippy::repeat-vec-with-capacity` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::repeat_vec_with_capacity)]` | ||
help: if you intended to create an iterator that yields `Vec`s with an initial capacity, try | ||
| | ||
LL | let _: Vec<Vec<u8>> = core::iter::repeat_with(|| Vec::with_capacity(42)).take(123).collect(); | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to 1 previous error | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a
no_std
environment, we may usealloc::vec::Vec
, but this assumes the existence of a heap allocator, so Clippy shouldn't suggest to usealloc::vec::Vec
in general because it violates the purpose ofApplicability::MaybeIncorrect
. Also, usingApplicability::Unspecified
is noisy in such environments.