Skip to content

Commit 21e0ea9

Browse files
committed
Address review
1 parent 8d4f2ac commit 21e0ea9

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

clippy_utils/src/check_proc_macro.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use rustc_ast::ast::{IntTy, LitIntType, LitKind, StrStyle, UintTy};
1616
use rustc_hir::{
1717
intravisit::FnKind, Block, BlockCheckMode, Body, Closure, Destination, Expr, ExprKind, FieldDef, FnHeader, HirId,
18-
Impl, ImplItem, ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, QPath, TraitItem, TraitItemKind,
19-
UnOp, UnsafeSource, Unsafety, Variant, VariantData, YieldSource,
18+
Impl, ImplItem, ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, Node, QPath, TraitItem,
19+
TraitItemKind, UnOp, UnsafeSource, Unsafety, Variant, VariantData, YieldSource,
2020
};
2121
use rustc_lint::{LateContext, LintContext};
2222
use rustc_middle::ty::TyCtxt;
@@ -251,23 +251,21 @@ fn variant_search_pat(v: &Variant<'_>) -> (Pat, Pat) {
251251
}
252252

253253
fn fn_kind_pat(tcx: TyCtxt<'_>, kind: &FnKind<'_>, body: &Body<'_>, hir_id: HirId) -> (Pat, Pat) {
254-
let (start_pat, end_pat, visibility) = match kind {
255-
FnKind::ItemFn(.., header) => (
256-
fn_header_search_pat(*header),
257-
Pat::Str(""),
258-
tcx.visibility(tcx.hir().local_def_id(hir_id)),
259-
),
260-
FnKind::Method(.., sig) => (
261-
fn_header_search_pat(sig.header),
262-
Pat::Str(""),
263-
tcx.visibility(tcx.hir().local_def_id(hir_id)),
264-
),
254+
let (start_pat, end_pat) = match kind {
255+
FnKind::ItemFn(.., header) => (fn_header_search_pat(*header), Pat::Str("")),
256+
FnKind::Method(.., sig) => (fn_header_search_pat(sig.header), Pat::Str("")),
265257
FnKind::Closure => return (Pat::Str(""), expr_search_pat(tcx, &body.value).1),
266258
};
267-
if visibility.is_public() {
268-
(Pat::Str("pub"), end_pat)
269-
} else {
259+
let vis_span = match tcx.hir().get(hir_id) {
260+
Node::Item(Item { vis_span, .. }) => Some(vis_span),
261+
Node::ImplItem(ImplItem { vis_span, .. }) => Some(vis_span),
262+
Node::TraitItem(_) => None,
263+
_ => unreachable!(),
264+
};
265+
if matches!(vis_span, Some(span) if span.is_empty()) {
270266
(start_pat, end_pat)
267+
} else {
268+
(Pat::Str("pub"), end_pat)
271269
}
272270
}
273271

0 commit comments

Comments
 (0)