mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Do not consider method call receiver as an argument in AST.
This commit is contained in:
parent
f719599c0f
commit
cf3f71d2a2
@ -61,9 +61,8 @@ impl EarlyLintPass for DoubleParens {
|
||||
}
|
||||
}
|
||||
},
|
||||
ExprKind::MethodCall(_, ref params, _) => {
|
||||
if params.len() == 2 {
|
||||
let param = ¶ms[1];
|
||||
ExprKind::MethodCall(_, _, ref params, _) => {
|
||||
if let [ref param] = params[..] {
|
||||
if let ExprKind::Paren(_) = param.kind {
|
||||
span_lint(cx, DOUBLE_PARENS, param.span, msg);
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ declare_lint_pass!(OptionEnvUnwrap => [OPTION_ENV_UNWRAP]);
|
||||
impl EarlyLintPass for OptionEnvUnwrap {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(path_segment, args, _) = &expr.kind;
|
||||
if let ExprKind::MethodCall(path_segment, receiver, _, _) = &expr.kind;
|
||||
if matches!(path_segment.ident.name, sym::expect | sym::unwrap);
|
||||
if let ExprKind::Call(caller, _) = &args[0].kind;
|
||||
if let ExprKind::Call(caller, _) = &receiver.kind;
|
||||
if is_direct_expn_of(caller.span, "option_env").is_some();
|
||||
then {
|
||||
span_lint_and_help(
|
||||
|
@ -109,12 +109,12 @@ impl EarlyLintPass for Precedence {
|
||||
let mut arg = operand;
|
||||
|
||||
let mut all_odd = true;
|
||||
while let ExprKind::MethodCall(path_segment, args, _) = &arg.kind {
|
||||
while let ExprKind::MethodCall(path_segment, receiver, _, _) = &arg.kind {
|
||||
let path_segment_str = path_segment.ident.name.as_str();
|
||||
all_odd &= ALLOWED_ODD_FUNCTIONS
|
||||
.iter()
|
||||
.any(|odd_function| **odd_function == *path_segment_str);
|
||||
arg = args.first().expect("A method always has a receiver.");
|
||||
arg = receiver;
|
||||
}
|
||||
|
||||
if_chain! {
|
||||
|
@ -595,7 +595,7 @@ fn ident_difference_expr_with_base_location(
|
||||
| (Unary(_, _), Unary(_, _))
|
||||
| (Binary(_, _, _), Binary(_, _, _))
|
||||
| (Tup(_), Tup(_))
|
||||
| (MethodCall(_, _, _), MethodCall(_, _, _))
|
||||
| (MethodCall(_, _, _, _), MethodCall(_, _, _, _))
|
||||
| (Call(_, _), Call(_, _))
|
||||
| (ConstBlock(_), ConstBlock(_))
|
||||
| (Array(_), Array(_))
|
||||
|
@ -30,11 +30,10 @@ declare_clippy_lint! {
|
||||
declare_lint_pass!(UnusedRounding => [UNUSED_ROUNDING]);
|
||||
|
||||
fn is_useless_rounding(expr: &Expr) -> Option<(&str, String)> {
|
||||
if let ExprKind::MethodCall(name_ident, args, _) = &expr.kind
|
||||
if let ExprKind::MethodCall(name_ident, receiver, _, _) = &expr.kind
|
||||
&& let method_name = name_ident.ident.name.as_str()
|
||||
&& (method_name == "ceil" || method_name == "round" || method_name == "floor")
|
||||
&& !args.is_empty()
|
||||
&& let ExprKind::Lit(spanned) = &args[0].kind
|
||||
&& let ExprKind::Lit(spanned) = &receiver.kind
|
||||
&& let LitKind::Float(symbol, ty) = spanned.kind {
|
||||
let f = symbol.as_str().parse::<f64>().unwrap();
|
||||
let f_str = symbol.to_string() + if let LitFloatType::Suffixed(ty) = ty {
|
||||
|
@ -147,7 +147,9 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
|
||||
(Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
|
||||
(Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),
|
||||
(Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
|
||||
(MethodCall(lc, la, _), MethodCall(rc, ra, _)) => eq_path_seg(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
|
||||
(MethodCall(lc, ls, la, _), MethodCall(rc, rs, ra, _)) => {
|
||||
eq_path_seg(lc, rc) && eq_expr(ls, rs) && over(la, ra, |l, r| eq_expr(l, r))
|
||||
},
|
||||
(Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr),
|
||||
(Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r),
|
||||
(Lit(l), Lit(r)) => l.kind == r.kind,
|
||||
|
Loading…
Reference in New Issue
Block a user