-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only emit
useless_vec
suggestion if the macro does not contain code…
… comments (#13911) Fixes #13692. If the `vec!` macro call contains comments, we should not provide suggestions and let users handle it however they see fit. changelog: Only emit `useless_vec` suggestion if the macro does not contain code comments
- Loading branch information
Showing
3 changed files
with
49 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//@no-rustfix: no suggestions | ||
|
||
#![warn(clippy::useless_vec)] | ||
|
||
// Regression test for <https://github.com/rust-lang/rust-clippy/issues/13692>. | ||
fn foo() { | ||
// There should be no suggestion in this case. | ||
let _some_variable = vec![ | ||
//~^ useless_vec | ||
1, 2, // i'm here to stay | ||
3, 4, // but this one going away ;-; | ||
]; // that is life anyways | ||
} | ||
|
||
fn main() {} |
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,21 @@ | ||
error: useless use of `vec!` | ||
--> tests/ui/useless_vec.rs:8:26 | ||
| | ||
LL | let _some_variable = vec![ | ||
| __________________________^ | ||
LL | | | ||
LL | | 1, 2, // i'm here to stay | ||
LL | | 3, 4, // but this one going away ;-; | ||
LL | | ]; // that is life anyways | ||
| |_____^ | ||
| | ||
= note: `-D clippy::useless-vec` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::useless_vec)]` | ||
help: you can use an array directly | ||
| | ||
LL ~ let _some_variable = [1, 2, // i'm here to stay | ||
LL ~ 3, 4]; // that is life anyways | ||
| | ||
|
||
error: aborting due to 1 previous error | ||
|