From 2c282252a93effa847517a4ced1b24036372dd46 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 28 Aug 2019 18:27:06 +0900 Subject: [PATCH] Replace `Arg` with `Param` --- clippy_lints/src/bytecount.rs | 4 ++-- clippy_lints/src/escape.rs | 2 +- clippy_lints/src/eta_reduction.rs | 5 ++++- clippy_lints/src/functions.rs | 2 +- clippy_lints/src/map_clone.rs | 2 +- clippy_lints/src/map_unit_fn.rs | 5 ++++- clippy_lints/src/methods/mod.rs | 8 ++++---- clippy_lints/src/methods/unnecessary_filter_map.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/types.rs | 2 +- clippy_lints/src/utils/mod.rs | 6 +++--- clippy_lints/src/utils/ptr.rs | 4 ++-- 12 files changed, 25 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index ab9cf951261..1e1e4317e34 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -47,8 +47,8 @@ fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) { then { let body = cx.tcx.hir().body(body_id); if_chain! { - if body.arguments.len() == 1; - if let Some(argname) = get_pat_name(&body.arguments[0].pat); + if body.params.len() == 1; + if let Some(argname) = get_pat_name(&body.params[0].pat); if let ExprKind::Binary(ref op, ref l, ref r) = body.value.node; if op.node == BinOpKind::Eq; if match_type(cx, diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index c37efbd6e49..e174cdfb860 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -108,7 +108,7 @@ fn is_argument(map: &hir::map::Map<'_>, id: HirId) -> bool { } match map.find(map.get_parent_node(id)) { - Some(Node::Arg(_)) => true, + Some(Node::Param(_)) => true, _ => false, } } diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index e4fcd271bbc..485a29ed3d8 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -202,7 +202,10 @@ fn get_type_name(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> String { } } -fn compare_inputs(closure_inputs: &mut dyn Iterator, call_args: &mut dyn Iterator) -> bool { +fn compare_inputs( + closure_inputs: &mut dyn Iterator, + call_args: &mut dyn Iterator, +) -> bool { for (closure_input, function_arg) in closure_inputs.zip(call_args) { if let PatKind::Binding(_, _, ident, _) = closure_input.pat.node { // XXXManishearth Should I be checking the binding mode here? diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 9772a603ba0..e009d28db68 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -280,7 +280,7 @@ fn check_raw_ptr( } } -fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option { +fn raw_ptr_arg(arg: &hir::Param, ty: &hir::Ty) -> Option { if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) { Some(id) } else { diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 09c1f4b3c97..5c44346aa6d 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -57,7 +57,7 @@ fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) { let closure_body = cx.tcx.hir().body(body_id); let closure_expr = remove_blocks(&closure_body.value); then { - match closure_body.arguments[0].pat.node { + match closure_body.params[0].pat.node { hir::PatKind::Ref(ref inner, _) => if let hir::PatKind::Binding( hir::BindingAnnotation::Unannotated, .., name, None ) = inner.node { diff --git a/clippy_lints/src/map_unit_fn.rs b/clippy_lints/src/map_unit_fn.rs index 7d46478a6fd..0df14c2664a 100644 --- a/clippy_lints/src/map_unit_fn.rs +++ b/clippy_lints/src/map_unit_fn.rs @@ -161,7 +161,10 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) -> } } -fn unit_closure<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'a hir::Expr) -> Option<(&'tcx hir::Arg, &'a hir::Expr)> { +fn unit_closure<'a, 'tcx>( + cx: &LateContext<'a, 'tcx>, + expr: &'a hir::Expr, +) -> Option<(&'tcx hir::Param, &'a hir::Expr)> { if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.node { let body = cx.tcx.hir().body(inner_expr_id); let body_expr = &body.value; diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index cc22d3b9865..81a8e69220c 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1732,8 +1732,8 @@ fn check_fold_with_op( if bin_op.node == op; // Extract the names of the two arguments to the closure - if let Some(first_arg_ident) = get_arg_name(&closure_body.arguments[0].pat); - if let Some(second_arg_ident) = get_arg_name(&closure_body.arguments[1].pat); + if let Some(first_arg_ident) = get_arg_name(&closure_body.params[0].pat); + if let Some(second_arg_ident) = get_arg_name(&closure_body.params[1].pat); if match_var(&*left_expr, first_arg_ident); if replacement_has_args || match_var(&*right_expr, second_arg_ident); @@ -2345,7 +2345,7 @@ fn lint_flat_map_identity<'a, 'tcx>( if let hir::ExprKind::Closure(_, _, body_id, _, _) = arg_node; let body = cx.tcx.hir().body(*body_id); - if let hir::PatKind::Binding(_, _, binding_ident, _) = body.arguments[0].pat.node; + if let hir::PatKind::Binding(_, _, binding_ident, _) = body.params[0].pat.node; if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = body.value.node; if path.segments.len() == 1; @@ -2390,7 +2390,7 @@ fn lint_search_is_some<'a, 'tcx>( if search_method == "find"; if let hir::ExprKind::Closure(_, _, body_id, ..) = search_args[1].node; let closure_body = cx.tcx.hir().body(body_id); - if let Some(closure_arg) = closure_body.arguments.get(0); + if let Some(closure_arg) = closure_body.params.get(0); if let hir::PatKind::Ref(..) = closure_arg.pat.node; then { Some(search_snippet.replacen('&', "", 1)) diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index a28e9b1e307..1d562566fdf 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -17,7 +17,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].node { let body = cx.tcx.hir().body(body_id); - let arg_id = body.arguments[0].pat.hir_id; + let arg_id = body.params[0].pat.hir_id; let mutates_arg = match mutated_variables(&body.value, cx) { Some(used_mutably) => used_mutably.contains(&arg_id), None => true, diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index f09fb22f82a..d3ca5cb539a 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -152,7 +152,7 @@ fn check_fn( let fn_sig = cx.tcx.fn_sig(fn_def_id); let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig); - for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(&body.arguments).enumerate() { + for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(&body.params).enumerate() { // All spans generated from a proc-macro invocation are the same... if span == input.span { return; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 24eba166c7b..28d337d3cd6 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -2056,7 +2056,7 @@ fn suggestion<'a, 'tcx>( continue; } let generics_suggestion_span = generics.span.substitute_dummy({ - let pos = snippet_opt(cx, item.span.until(body.arguments[0].pat.span)) + let pos = snippet_opt(cx, item.span.until(body.params[0].pat.span)) .and_then(|snip| { let i = snip.find("fn")?; Some(item.span.lo() + BytePos((i + (&snip[i..]).find('(')?) as u32)) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 408deb1b402..8fb45899653 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -835,7 +835,7 @@ pub fn remove_blocks(expr: &Expr) -> &Expr { } } -pub fn is_self(slf: &Arg) -> bool { +pub fn is_self(slf: &Param) -> bool { if let PatKind::Binding(.., name, _) = slf.pat.node { name.name == kw::SelfLower } else { @@ -855,8 +855,8 @@ pub fn is_self_ty(slf: &hir::Ty) -> bool { false } -pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body) -> impl Iterator { - (0..decl.inputs.len()).map(move |i| &body.arguments[i]) +pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body) -> impl Iterator { + (0..decl.inputs.len()).map(move |i| &body.params[i]) } /// Checks if a given expression is a match expression expanded from the `?` diff --git a/clippy_lints/src/utils/ptr.rs b/clippy_lints/src/utils/ptr.rs index e378ef0c0a9..be7bd0d21f6 100644 --- a/clippy_lints/src/utils/ptr.rs +++ b/clippy_lints/src/utils/ptr.rs @@ -13,7 +13,7 @@ pub fn get_spans( replacements: &[(&'static str, &'static str)], ) -> Option)>> { if let Some(body) = opt_body_id.map(|id| cx.tcx.hir().body(id)) { - get_binding_name(&body.arguments[idx]).map_or_else( + get_binding_name(&body.params[idx]).map_or_else( || Some(vec![]), |name| extract_clone_suggestions(cx, name, replacements, body), ) @@ -80,6 +80,6 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { } } -fn get_binding_name(arg: &Arg) -> Option { +fn get_binding_name(arg: &Param) -> Option { get_pat_name(&arg.pat) } -- 2.44.0