From 4d87fb5d1125b5bceb83b34eb68bc0e73fcf636a Mon Sep 17 00:00:00 2001 From: akida31 Date: Tue, 11 Oct 2022 17:48:46 +0200 Subject: [PATCH] remove manual `fn_decl` extraction --- .../src/traits/error_reporting/suggestions.rs | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index f20cecdb74f..17206b21af0 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -3412,23 +3412,9 @@ fn hint_missing_borrow<'tcx>( } }; - let fn_decl = match found_node { - Node::Expr(expr) => match &expr.kind { - hir::ExprKind::Closure(hir::Closure { fn_decl, .. }) => fn_decl, - kind => { - span_bug!(found_span, "expression must be a closure but is {:?}", kind) - } - }, - Node::Item(item) => match &item.kind { - hir::ItemKind::Fn(signature, _generics, _body) => signature.decl, - kind => { - span_bug!(found_span, "item must be a function but is {:?}", kind) - } - }, - node => { - span_bug!(found_span, "node must be a expr or item but is {:?}", node) - } - }; + let fn_decl = found_node + .fn_decl() + .unwrap_or_else(|| span_bug!(found_span, "found node must be a function")); let arg_spans = fn_decl.inputs.iter().map(|ty| ty.span);