Skip to content

Replace Arg with Param #4462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clippy_lints/src/bytecount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
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,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
5 changes: 4 additions & 1 deletion clippy_lints/src/eta_reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ fn get_type_name(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> String {
}
}

fn compare_inputs(closure_inputs: &mut dyn Iterator<Item = &Arg>, call_args: &mut dyn Iterator<Item = &Expr>) -> bool {
fn compare_inputs(
closure_inputs: &mut dyn Iterator<Item = &Param>,
call_args: &mut dyn Iterator<Item = &Expr>,
) -> 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?
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl<'a, 'tcx> Functions {
}
}

fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<hir::HirId> {
fn raw_ptr_arg(arg: &hir::Param, ty: &hir::Ty) -> Option<hir::HirId> {
if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) {
Some(id)
} else {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/map_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
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 {
Expand Down
5 changes: 4 additions & 1 deletion clippy_lints/src/map_unit_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,8 +1732,8 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/unnecessary_filter_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
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;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2056,7 +2056,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher {
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))
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Item = &'tcx Arg> {
(0..decl.inputs.len()).map(move |i| &body.arguments[i])
pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body) -> impl Iterator<Item = &'tcx Param> {
(0..decl.inputs.len()).map(move |i| &body.params[i])
}

/// Checks if a given expression is a match expression expanded from the `?`
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn get_spans(
replacements: &[(&'static str, &'static str)],
) -> Option<Vec<(Span, Cow<'static, str>)>> {
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),
)
Expand Down Expand Up @@ -80,6 +80,6 @@ impl<'a, 'tcx> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> {
}
}

fn get_binding_name(arg: &Arg) -> Option<Name> {
fn get_binding_name(arg: &Param) -> Option<Name> {
get_pat_name(&arg.pat)
}