forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#12725 - llogiq:allow-useless-test-vecs, r=bly…
…xyas configurably allow `useless_vec` in tests This adds a `àllow-useless-vec-in-test` configuration which, when set to `true` will allow the `useless_vec` lint in `#[test]` functions and code within `#[cfg(test)]`. It also moves a `is_in_test` helper to `clippy_utils`. --- changelog: configurably allow [`useless_vec`] in test code
- Loading branch information
Showing
12 changed files
with
97 additions
and
8 deletions.
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
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 @@ | ||
allow-useless-vec-in-tests = true |
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,26 @@ | ||
//@compile-flags: --test | ||
#![warn(clippy::useless_vec)] | ||
#![allow(clippy::unnecessary_operation, clippy::no_effect)] | ||
|
||
fn foo(_: &[u32]) {} | ||
|
||
fn main() { | ||
foo(&[1_u32]); | ||
} | ||
|
||
#[test] | ||
pub fn in_test() { | ||
foo(&vec![2_u32]); | ||
} | ||
|
||
#[cfg(test)] | ||
fn in_cfg_test() { | ||
foo(&vec![3_u32]); | ||
} | ||
|
||
#[cfg(test)] | ||
mod mod1 { | ||
fn in_cfg_test_mod() { | ||
super::foo(&vec![4_u32]); | ||
} | ||
} |
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,26 @@ | ||
//@compile-flags: --test | ||
#![warn(clippy::useless_vec)] | ||
#![allow(clippy::unnecessary_operation, clippy::no_effect)] | ||
|
||
fn foo(_: &[u32]) {} | ||
|
||
fn main() { | ||
foo(&vec![1_u32]); | ||
} | ||
|
||
#[test] | ||
pub fn in_test() { | ||
foo(&vec![2_u32]); | ||
} | ||
|
||
#[cfg(test)] | ||
fn in_cfg_test() { | ||
foo(&vec![3_u32]); | ||
} | ||
|
||
#[cfg(test)] | ||
mod mod1 { | ||
fn in_cfg_test_mod() { | ||
super::foo(&vec![4_u32]); | ||
} | ||
} |
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: useless use of `vec!` | ||
--> tests/ui-toml/useless_vec/useless_vec.rs:8:9 | ||
| | ||
LL | foo(&vec![1_u32]); | ||
| ^^^^^^^^^^^^ help: you can use a slice directly: `&[1_u32]` | ||
| | ||
= note: `-D clippy::useless-vec` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::useless_vec)]` | ||
|
||
error: aborting due to 1 previous error | ||
|