Skip to content

Commit 742cba3

Browse files
committed
fix FnPtr
1 parent c7b7588 commit 742cba3

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)]
@@ -415,29 +415,31 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) {
415415
}
416416

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

420420
match &ty.kind {
421421
TyKind::Slice(..) | TyKind::Array(..) => (Pat::Str("["), Pat::Str("]")),
422422
TyKind::Ptr(MutTy { ty, .. }) => (Pat::Str("*"), ast_ty_search_pat(ty).1),
423423
TyKind::Ref(_, MutTy { ty, .. }) => (Pat::Str("&"), ast_ty_search_pat(ty).1),
424424
TyKind::FnPtr(fn_ptr) => (
425-
if fn_ptr.safety.is_unsafe() {
425+
if let Safety::Unsafe(_) = fn_ptr.safety {
426426
Pat::Str("unsafe")
427-
} else if fn_ptr.abi != ExternAbi::Rust {
428-
Pat::Str("extern")
429-
} else {
427+
} else if let Extern::Explicit(strlit, _) = fn_ptr.ext
428+
&& strlit.symbol == sym::rust
429+
{
430430
Pat::MultiStr(&["fn", "extern"])
431+
} else {
432+
Pat::Str("extern")
431433
},
432-
match fn_ptr.decl.output {
433-
FnRetTy::DefaultReturn(_) => {
434-
if let [.., ty] = fn_ptr.decl.inputs {
435-
ast_ty_search_pat(ty).1
434+
match &fn_ptr.decl.output {
435+
FnRetTy::Default(_) => {
436+
if let [.., param] = &*fn_ptr.decl.inputs {
437+
ast_ty_search_pat(&param.ty).1
436438
} else {
437439
Pat::Str("(")
438440
}
439441
},
440-
FnRetTy::Return(ty) => ast_ty_search_pat(ty).1,
442+
FnRetTy::Ty(ty) => ast_ty_search_pat(ty).1,
441443
},
442444
),
443445
TyKind::Never => (Pat::Str("!"), Pat::Str("!")),

0 commit comments

Comments
 (0)