diff options
| author | Igor Aleksanov <popzxc@yandex.ru> | 2021-06-19 21:14:05 +0300 |
|---|---|---|
| committer | Igor Aleksanov <popzxc@yandex.ru> | 2021-06-25 12:36:22 +0300 |
| commit | 28d3873ef52fd1e4f9efa115d18235e92fecfa83 (patch) | |
| tree | 0e7245159e423c9ff17f35c3ee0cdbf5befcb800 /clippy_utils/src | |
| parent | 7869e625572702d4f0a5d92735631c6260484335 (diff) | |
| download | rust-28d3873ef52fd1e4f9efa115d18235e92fecfa83.tar.gz rust-28d3873ef52fd1e4f9efa115d18235e92fecfa83.zip | |
Do not spawn blacklisted_name lint in test context
Fix detecting of the 'test' attribute Update UI test to actually check that warning is not triggered in the test code Fix approach for detecting the test module Add nested test case Remove code duplication by extracting 'is_test_module_or_function' into 'clippy_utils' Cleanup the code
Diffstat (limited to 'clippy_utils/src')
| -rw-r--r-- | clippy_utils/src/lib.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 66e75b0c206..ef4854afc83 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1727,3 +1727,15 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool { } } } + +/// Checks whether item either has `test` attribute applied, or +/// is a module with `test` in its name. +pub fn is_test_module_or_function(tcx: TyCtxt<'_>, item: &Item<'_>) -> bool { + if let Some(def_id) = tcx.hir().opt_local_def_id(item.hir_id()) { + if tcx.has_attr(def_id.to_def_id(), sym::test) { + return true; + } + } + + matches!(item.kind, ItemKind::Mod(..)) && item.ident.name.as_str().contains("test") +} |
