Skip to content

Commit cad7e00

Browse files
committed
fix FnPtr
1 parent 0ac9d83 commit cad7e00

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

clippy_utils/src/check_proc_macro.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_lint::{EarlyContext, LateContext, LintContext};
2929
use rustc_middle::ty::TyCtxt;
3030
use rustc_session::Session;
3131
use rustc_span::symbol::{Ident, kw};
32-
use rustc_span::{Span, Symbol};
32+
use rustc_span::{Span, Symbol, sym};
3333

3434
/// The search pattern to look for. Used by `span_matches_pat`
3535
#[derive(Clone)]
@@ -412,29 +412,31 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) {
412412
}
413413

414414
fn ast_ty_search_pat(ty: &ast::Ty) -> (Pat, Pat) {
415-
use ast::{FnRetTy, MutTy, TraitObjectSyntax, TyKind};
415+
use ast::{Extern, FnRetTy, MutTy, Safety, TraitObjectSyntax, TyKind};
416416

417417
match &ty.kind {
418418
TyKind::Slice(..) | TyKind::Array(..) => (Pat::Str("["), Pat::Str("]")),
419419
TyKind::Ptr(MutTy { ty, .. }) => (Pat::Str("*"), ast_ty_search_pat(ty).1),
420420
TyKind::Ref(_, MutTy { ty, .. }) => (Pat::Str("&"), ast_ty_search_pat(ty).1),
421421
TyKind::FnPtr(fn_ptr) => (
422-
if fn_ptr.safety.is_unsafe() {
422+
if let Safety::Unsafe(_) = fn_ptr.safety {
423423
Pat::Str("unsafe")
424-
} else if fn_ptr.abi != ExternAbi::Rust {
425-
Pat::Str("extern")
426-
} else {
424+
} else if let Extern::Explicit(strlit, _) = fn_ptr.ext
425+
&& strlit.symbol == sym::rust
426+
{
427427
Pat::MultiStr(&["fn", "extern"])
428+
} else {
429+
Pat::Str("extern")
428430
},
429-
match fn_ptr.decl.output {
430-
FnRetTy::DefaultReturn(_) => {
431-
if let [.., ty] = fn_ptr.decl.inputs {
432-
ast_ty_search_pat(ty).1
431+
match &fn_ptr.decl.output {
432+
FnRetTy::Default(_) => {
433+
if let [.., param] = &*fn_ptr.decl.inputs {
434+
ast_ty_search_pat(&param.ty).1
433435
} else {
434436
Pat::Str("(")
435437
}
436438
},
437-
FnRetTy::Return(ty) => ast_ty_search_pat(ty).1,
439+
FnRetTy::Ty(ty) => ast_ty_search_pat(ty).1,
438440
},
439441
),
440442
TyKind::Never => (Pat::Str("!"), Pat::Str("!")),

0 commit comments

Comments
 (0)