about summary refs log tree commit diff
diff options
context:
space:
mode:
authordAxpeDDa <daxpedda@gmail.com>2022-08-09 04:48:05 +0200
committerdAxpeDDa <daxpedda@gmail.com>2022-08-09 04:56:04 +0200
commit6f5d64842bfce445cbe251bec492c80481bca7f3 (patch)
treeb22bcb605a24477b17f61ceefd5fd3d44898546e
parent8d4f2ac38195567ee8eca0123d428951821db507 (diff)
downloadrust-6f5d64842bfce445cbe251bec492c80481bca7f3.tar.gz
rust-6f5d64842bfce445cbe251bec492c80481bca7f3.zip
Address review
-rw-r--r--clippy_utils/src/check_proc_macro.rs29
1 files changed, 13 insertions, 16 deletions
diff --git a/clippy_utils/src/check_proc_macro.rs b/clippy_utils/src/check_proc_macro.rs
index 1062f223912..da3db9230a0 100644
--- a/clippy_utils/src/check_proc_macro.rs
+++ b/clippy_utils/src/check_proc_macro.rs
@@ -15,8 +15,8 @@
 use rustc_ast::ast::{IntTy, LitIntType, LitKind, StrStyle, UintTy};
 use rustc_hir::{
     intravisit::FnKind, Block, BlockCheckMode, Body, Closure, Destination, Expr, ExprKind, FieldDef, FnHeader, HirId,
-    Impl, ImplItem, ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, QPath, TraitItem, TraitItemKind,
-    UnOp, UnsafeSource, Unsafety, Variant, VariantData, YieldSource,
+    Impl, ImplItem, ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, Node, QPath, TraitItem,
+    TraitItemKind, UnOp, UnsafeSource, Unsafety, Variant, VariantData, YieldSource,
 };
 use rustc_lint::{LateContext, LintContext};
 use rustc_middle::ty::TyCtxt;
@@ -251,23 +251,20 @@ fn variant_search_pat(v: &Variant<'_>) -> (Pat, Pat) {
 }
 
 fn fn_kind_pat(tcx: TyCtxt<'_>, kind: &FnKind<'_>, body: &Body<'_>, hir_id: HirId) -> (Pat, Pat) {
-    let (start_pat, end_pat, visibility) = match kind {
-        FnKind::ItemFn(.., header) => (
-            fn_header_search_pat(*header),
-            Pat::Str(""),
-            tcx.visibility(tcx.hir().local_def_id(hir_id)),
-        ),
-        FnKind::Method(.., sig) => (
-            fn_header_search_pat(sig.header),
-            Pat::Str(""),
-            tcx.visibility(tcx.hir().local_def_id(hir_id)),
-        ),
+    let (start_pat, end_pat) = match kind {
+        FnKind::ItemFn(.., header) => (fn_header_search_pat(*header), Pat::Str("")),
+        FnKind::Method(.., sig) => (fn_header_search_pat(sig.header), Pat::Str("")),
         FnKind::Closure => return (Pat::Str(""), expr_search_pat(tcx, &body.value).1),
     };
-    if visibility.is_public() {
-        (Pat::Str("pub"), end_pat)
-    } else {
+    let vis_span = match tcx.hir().get(hir_id) {
+        Node::Item(Item { vis_span, .. }) | Node::ImplItem(ImplItem { vis_span, .. }) => Some(vis_span),
+        Node::TraitItem(_) => None,
+        _ => unreachable!(),
+    };
+    if matches!(vis_span, Some(span) if span.is_empty()) {
         (start_pat, end_pat)
+    } else {
+        (Pat::Str("pub"), end_pat)
     }
 }