Do not store attrs in FnKind.

This commit is contained in:
Camille GILLOT
2020-11-27 09:24:42 +01:00
parent 8d5e0f512f
commit 476c5283d5
10 changed files with 19 additions and 20 deletions

View File

@@ -76,8 +76,8 @@ impl CognitiveComplexity {
if rust_cc > self.limit.limit() { if rust_cc > self.limit.limit() {
let fn_span = match kind { let fn_span = match kind {
FnKind::ItemFn(ident, _, _, _, _) | FnKind::Method(ident, _, _, _) => ident.span, FnKind::ItemFn(ident, _, _, _) | FnKind::Method(ident, _, _) => ident.span,
FnKind::Closure(_) => { FnKind::Closure => {
let header_span = body_span.with_hi(decl.output.span().lo()); let header_span = body_span.with_hi(decl.output.span().lo());
let pos = snippet_opt(cx, header_span).and_then(|snip| { let pos = snippet_opt(cx, header_span).and_then(|snip| {
let low_offset = snip.find('|')?; let low_offset = snip.find('|')?;

View File

@@ -251,9 +251,9 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
hir_id: hir::HirId, hir_id: hir::HirId,
) { ) {
let unsafety = match kind { let unsafety = match kind {
intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }, _, _) => unsafety, intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }, _) => unsafety,
intravisit::FnKind::Method(_, sig, _, _) => sig.header.unsafety, intravisit::FnKind::Method(_, sig, _) => sig.header.unsafety,
intravisit::FnKind::Closure(_) => return, intravisit::FnKind::Closure => return,
}; };
// don't warn for implementations, it's not their fault // don't warn for implementations, it's not their fault
@@ -267,9 +267,8 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
.. ..
}, },
_, _,
_,
) )
| intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: Abi::Rust, .. }, _, _) => { | intravisit::FnKind::ItemFn(_, _, hir::FnHeader { abi: Abi::Rust, .. }, _) => {
self.check_arg_number(cx, decl, span.with_hi(decl.output.span().hi())) self.check_arg_number(cx, decl, span.with_hi(decl.output.span().hi()))
}, },
_ => {}, _ => {},

View File

@@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
_: Span, _: Span,
hir_id: HirId, hir_id: HirId,
) { ) {
if let FnKind::Closure(_) = kind { if let FnKind::Closure = kind {
return; return;
} }
let ret_ty = utils::return_ty(cx, hir_id); let ret_ty = utils::return_ty(cx, hir_id);

View File

@@ -278,7 +278,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
span: Span, span: Span,
_: HirId, _: HirId,
) { ) {
if let FnKind::Closure(_) = k { if let FnKind::Closure = k {
// Does not apply to closures // Does not apply to closures
return; return;
} }

View File

@@ -133,7 +133,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
return; return;
} }
}, },
FnKind::Closure(..) => return, FnKind::Closure => return,
} }
let mir = cx.tcx.optimized_mir(def_id); let mir = cx.tcx.optimized_mir(def_id);

View File

@@ -80,13 +80,14 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
} }
match kind { match kind {
FnKind::ItemFn(.., header, _, attrs) => { FnKind::ItemFn(.., header, _) => {
let attrs = cx.tcx.hir().attrs(hir_id);
if header.abi != Abi::Rust || requires_exact_signature(attrs) { if header.abi != Abi::Rust || requires_exact_signature(attrs) {
return; return;
} }
}, },
FnKind::Method(..) => (), FnKind::Method(..) => (),
FnKind::Closure(..) => return, FnKind::Closure => return,
} }
// Exclude non-inherent impls // Exclude non-inherent impls

View File

@@ -43,9 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicInResultFn {
span: Span, span: Span,
hir_id: hir::HirId, hir_id: hir::HirId,
) { ) {
if !matches!(fn_kind, FnKind::Closure(_)) if !matches!(fn_kind, FnKind::Closure) && is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) {
&& is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type)
{
lint_impl_body(cx, span, body); lint_impl_body(cx, span, body);
} }
} }

View File

@@ -224,10 +224,11 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
} }
match kind { match kind {
FnKind::ItemFn(.., header, _, attrs) => { FnKind::ItemFn(.., header, _) => {
if header.abi != Abi::Rust { if header.abi != Abi::Rust {
return; return;
} }
let attrs = cx.tcx.hir().attrs(hir_id);
for a in attrs { for a in attrs {
if let Some(meta_items) = a.meta_item_list() { if let Some(meta_items) = a.meta_item_list() {
if a.has_name(sym::proc_macro_derive) if a.has_name(sym::proc_macro_derive)
@@ -239,7 +240,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
} }
}, },
FnKind::Method(..) => (), FnKind::Method(..) => (),
FnKind::Closure(..) => return, FnKind::Closure => return,
} }
// Exclude non-inherent impls // Exclude non-inherent impls

View File

@@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for Return {
_: HirId, _: HirId,
) { ) {
match kind { match kind {
FnKind::Closure(_) => { FnKind::Closure => {
// when returning without value in closure, replace this `return` // when returning without value in closure, replace this `return`
// with an empty block to prevent invalid suggestion (see #6501) // with an empty block to prevent invalid suggestion (see #6501)
let replacement = if let ExprKind::Ret(None) = &body.value.kind { let replacement = if let ExprKind::Ret(None) = &body.value.kind {

View File

@@ -66,12 +66,12 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
) { ) {
// Abort if public function/method or closure. // Abort if public function/method or closure.
match fn_kind { match fn_kind {
FnKind::ItemFn(.., visibility, _) | FnKind::Method(.., Some(visibility), _) => { FnKind::ItemFn(.., visibility) | FnKind::Method(.., Some(visibility)) => {
if visibility.node.is_pub() { if visibility.node.is_pub() {
return; return;
} }
}, },
FnKind::Closure(..) => return, FnKind::Closure => return,
_ => (), _ => (),
} }