diff options
| author | Andre Bogus <bogusandre@gmail.com> | 2024-04-28 00:01:14 +0200 |
|---|---|---|
| committer | blyxyas <blyxyas@gmail.com> | 2024-04-28 22:07:56 +0200 |
| commit | 87efce4fa22f51075e1fd25904f757f783eebfdc (patch) | |
| tree | e195fd5cf9ef50ad05d866818f5161544f988332 /clippy_utils | |
| parent | c6bf9548d53233f8a08928955a996f4bf30ea1bd (diff) | |
| download | rust-87efce4fa22f51075e1fd25904f757f783eebfdc.tar.gz rust-87efce4fa22f51075e1fd25904f757f783eebfdc.zip | |
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`.
Diffstat (limited to 'clippy_utils')
| -rw-r--r-- | clippy_utils/src/lib.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index fccd75d8153..26ee5225f99 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -2548,6 +2548,11 @@ pub fn is_in_cfg_test(tcx: TyCtxt<'_>, id: HirId) -> bool { .any(|parent_id| is_cfg_test(tcx, parent_id)) } +/// Checks if the node is in a `#[test]` function or has any parent node marked `#[cfg(test)]` +pub fn is_in_test(tcx: TyCtxt<'_>, hir_id: HirId) -> bool { + is_in_test_function(tcx, hir_id) || is_in_cfg_test(tcx, hir_id) +} + /// Checks if the item of any of its parents has `#[cfg(...)]` attribute applied. pub fn inherits_cfg(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { let hir = tcx.hir(); |
