about summary refs log tree commit diff
path: root/clippy_utils
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-25 19:00:59 +0000
committerbors <bors@rust-lang.org>2023-07-25 19:00:59 +0000
commit2153c0fcc893534d61b4d66de80e615e7bff6017 (patch)
tree0a1b6668108e38701898dc5ca3e6cb8d5f71359f /clippy_utils
parent70c5798993afb76c872f72e11e255eb692cdf464 (diff)
parent1c9772c7737e5937f71be1d1a27699bf226d89f1 (diff)
Auto merge of #11226 - GuillaumeGomez:needless-ref-mut-cfg, r=llogiq
Needless ref mut cfg

Fixes https://github.com/rust-lang/rust-clippy/issues/11185.

cc `@Centri3`

changelog: Emit note if function is behind a cfg for `NEEDLESS_PASS_BY_REF_MUT` lint.
Diffstat (limited to 'clippy_utils')
-rw-r--r--clippy_utils/src/lib.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index 8429192437c..beff0e6e1ab 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -2451,6 +2451,17 @@ pub fn is_in_cfg_test(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
         .any(is_cfg_test)
 }
 
+/// 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();
+
+    tcx.has_attr(def_id, sym::cfg)
+        || hir
+            .parent_iter(hir.local_def_id_to_hir_id(def_id))
+            .flat_map(|(parent_id, _)| hir.attrs(parent_id))
+            .any(|attr| attr.has_name(sym::cfg))
+}
+
 /// Checks whether item either has `test` attribute applied, or
 /// is a module with `test` in its name.
 ///