mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-23 20:34:06 +00:00
Replace Arg
with Param
This commit is contained in:
parent
949b347f65
commit
2c282252a9
@ -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,
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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?
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
@ -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))
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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))
|
||||
|
@ -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<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 `?`
|
||||
|
@ -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),
|
||||
)
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user