|
15 | 15 | use rustc_ast::ast::{IntTy, LitIntType, LitKind, StrStyle, UintTy};
|
16 | 16 | use rustc_hir::{
|
17 | 17 | 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, |
20 | 20 | };
|
21 | 21 | use rustc_lint::{LateContext, LintContext};
|
22 | 22 | use rustc_middle::ty::TyCtxt;
|
@@ -251,23 +251,21 @@ fn variant_search_pat(v: &Variant<'_>) -> (Pat, Pat) {
|
251 | 251 | }
|
252 | 252 |
|
253 | 253 | 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("")), |
265 | 257 | FnKind::Closure => return (Pat::Str(""), expr_search_pat(tcx, &body.value).1),
|
266 | 258 | };
|
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()) { |
270 | 266 | (start_pat, end_pat)
|
| 267 | + } else { |
| 268 | + (Pat::Str("pub"), end_pat) |
271 | 269 | }
|
272 | 270 | }
|
273 | 271 |
|
|
0 commit comments