[slow_vector_initialization]: only warn on vec![] expn
This commit is contained in:
parent
78983d9e3f
commit
51206323a1
3 changed files with 35 additions and 3 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use std::iter::repeat;
|
||||
//@no-rustfix
|
||||
use std::iter::repeat;
|
||||
fn main() {
|
||||
resize_vector();
|
||||
extend_vector();
|
||||
|
|
@ -86,6 +86,20 @@ fn from_empty_vec() {
|
|||
vec1 = Vec::new();
|
||||
vec1.resize(10, 0);
|
||||
//~^ ERROR: slow zero-filling initialization
|
||||
|
||||
vec1 = vec![];
|
||||
vec1.resize(10, 0);
|
||||
//~^ ERROR: slow zero-filling initialization
|
||||
|
||||
macro_rules! x {
|
||||
() => {
|
||||
vec![]
|
||||
};
|
||||
}
|
||||
|
||||
// `vec![]` comes from another macro, don't warn
|
||||
vec1 = x!();
|
||||
vec1.resize(10, 0);
|
||||
}
|
||||
|
||||
fn do_stuff(vec: &mut [u8]) {}
|
||||
|
|
|
|||
|
|
@ -96,13 +96,21 @@ LL | vec1 = Vec::new();
|
|||
LL | vec1.resize(10, 0);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: slow zero-filling initialization
|
||||
--> $DIR/slow_vector_initialization.rs:91:5
|
||||
|
|
||||
LL | vec1 = vec![];
|
||||
| ------ help: consider replacing this with: `vec![0; 10]`
|
||||
LL | vec1.resize(10, 0);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this argument is a mutable reference, but not used mutably
|
||||
--> $DIR/slow_vector_initialization.rs:91:18
|
||||
--> $DIR/slow_vector_initialization.rs:105:18
|
||||
|
|
||||
LL | fn do_stuff(vec: &mut [u8]) {}
|
||||
| ^^^^^^^^^ help: consider changing to: `&[u8]`
|
||||
|
|
||||
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
error: aborting due to 14 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue