Skip to content

Commit 0d94167

Browse files
committed
Auto merge of #8198 - camsteffen:no-method-call-macro, r=flip1995
Remove method_call! macro This is possible now that `SymbolStr` is removed from rustc. changelog: none
2 parents 37e9985 + 2b5257e commit 0d94167

File tree

1 file changed

+16
-25
lines changed
  • clippy_lints/src/methods

1 file changed

+16
-25
lines changed

clippy_lints/src/methods/mod.rs

+16-25
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ use rustc_middle::lint::in_external_macro;
8080
use rustc_middle::ty::{self, TraitRef, Ty, TyS};
8181
use rustc_semver::RustcVersion;
8282
use rustc_session::{declare_tool_lint, impl_lint_pass};
83-
use rustc_span::symbol::Symbol;
8483
use rustc_span::{sym, Span};
8584
use rustc_typeck::hir_ty_to_ty;
8685

@@ -2002,24 +2001,16 @@ impl_lint_pass!(Methods => [
20022001
]);
20032002

20042003
/// Extracts a method call name, args, and `Span` of the method name.
2005-
fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(Symbol, &'tcx [hir::Expr<'tcx>], Span)> {
2004+
fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(&'tcx str, &'tcx [hir::Expr<'tcx>], Span)> {
20062005
if let ExprKind::MethodCall(path, span, args, _) = recv.kind {
20072006
if !args.iter().any(|e| e.span.from_expansion()) {
2008-
return Some((path.ident.name, args, span));
2007+
let name = path.ident.name.as_str();
2008+
return Some((name, args, span));
20092009
}
20102010
}
20112011
None
20122012
}
20132013

2014-
/// Same as `method_call` but the `Symbol` is dereferenced into a temporary `&str`
2015-
macro_rules! method_call {
2016-
($expr:expr) => {
2017-
method_call($expr)
2018-
.as_ref()
2019-
.map(|&(ref name, args, span)| (name.as_str(), args, span))
2020-
};
2021-
}
2022-
20232014
impl<'tcx> LateLintPass<'tcx> for Methods {
20242015
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
20252016
if expr.span.from_expansion() {
@@ -2222,7 +2213,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
22222213

22232214
#[allow(clippy::too_many_lines)]
22242215
fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Option<&RustcVersion>) {
2225-
if let Some((name, [recv, args @ ..], span)) = method_call!(expr) {
2216+
if let Some((name, [recv, args @ ..], span)) = method_call(expr) {
22262217
match (name, args) {
22272218
("add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub", [_arg]) => {
22282219
zst_offset::check(cx, expr, recv);
@@ -2238,7 +2229,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
22382229
("as_ref", []) => useless_asref::check(cx, expr, "as_ref", recv),
22392230
("assume_init", []) => uninit_assumed_init::check(cx, expr, recv),
22402231
("cloned", []) => cloned_instead_of_copied::check(cx, expr, recv, span, msrv),
2241-
("collect", []) => match method_call!(recv) {
2232+
("collect", []) => match method_call(recv) {
22422233
Some((name @ ("cloned" | "copied"), [recv2], _)) => {
22432234
iter_cloned_collect::check(cx, name, expr, recv2);
22442235
},
@@ -2252,14 +2243,14 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
22522243
},
22532244
_ => {},
22542245
},
2255-
("count", []) => match method_call!(recv) {
2246+
("count", []) => match method_call(recv) {
22562247
Some((name @ ("into_iter" | "iter" | "iter_mut"), [recv2], _)) => {
22572248
iter_count::check(cx, expr, recv2, name);
22582249
},
22592250
Some(("map", [_, arg], _)) => suspicious_map::check(cx, expr, recv, arg),
22602251
_ => {},
22612252
},
2262-
("expect", [_]) => match method_call!(recv) {
2253+
("expect", [_]) => match method_call(recv) {
22632254
Some(("ok", [recv], _)) => ok_expect::check(cx, expr, recv),
22642255
_ => expect_used::check(cx, expr, recv),
22652256
},
@@ -2276,13 +2267,13 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
22762267
flat_map_option::check(cx, expr, arg, span);
22772268
},
22782269
("flatten", []) => {
2279-
if let Some(("map", [recv, map_arg], _)) = method_call!(recv) {
2270+
if let Some(("map", [recv, map_arg], _)) = method_call(recv) {
22802271
map_flatten::check(cx, expr, recv, map_arg);
22812272
}
22822273
},
22832274
("fold", [init, acc]) => unnecessary_fold::check(cx, expr, init, acc, span),
22842275
("for_each", [_]) => {
2285-
if let Some(("inspect", [_, _], span2)) = method_call!(recv) {
2276+
if let Some(("inspect", [_, _], span2)) = method_call(recv) {
22862277
inspect_for_each::check(cx, expr, span2);
22872278
}
22882279
},
@@ -2291,7 +2282,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
22912282
("is_none", []) => check_is_some_is_none(cx, expr, recv, false),
22922283
("is_some", []) => check_is_some_is_none(cx, expr, recv, true),
22932284
("map", [m_arg]) => {
2294-
if let Some((name, [recv2, args @ ..], span2)) = method_call!(recv) {
2285+
if let Some((name, [recv2, args @ ..], span2)) = method_call(recv) {
22952286
match (name, args) {
22962287
("as_mut", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, true, msrv),
22972288
("as_ref", []) => option_as_ref_deref::check(cx, expr, recv2, m_arg, false, msrv),
@@ -2306,7 +2297,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
23062297
},
23072298
("map_or", [def, map]) => option_map_or_none::check(cx, expr, recv, def, map),
23082299
("next", []) => {
2309-
if let Some((name, [recv, args @ ..], _)) = method_call!(recv) {
2300+
if let Some((name, [recv, args @ ..], _)) = method_call(recv) {
23102301
match (name, args) {
23112302
("filter", [arg]) => filter_next::check(cx, expr, recv, arg),
23122303
("filter_map", [arg]) => filter_map_next::check(cx, expr, recv, arg, msrv),
@@ -2317,7 +2308,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
23172308
}
23182309
}
23192310
},
2320-
("nth", [n_arg]) => match method_call!(recv) {
2311+
("nth", [n_arg]) => match method_call(recv) {
23212312
Some(("bytes", [recv2], _)) => bytes_nth::check(cx, expr, recv2, n_arg),
23222313
Some(("iter", [recv2], _)) => iter_nth::check(cx, expr, recv2, recv, n_arg, false),
23232314
Some(("iter_mut", [recv2], _)) => iter_nth::check(cx, expr, recv2, recv, n_arg, true),
@@ -2349,12 +2340,12 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
23492340
("to_os_string" | "to_owned" | "to_path_buf" | "to_vec", []) => {
23502341
implicit_clone::check(cx, name, expr, recv, span);
23512342
},
2352-
("unwrap", []) => match method_call!(recv) {
2343+
("unwrap", []) => match method_call(recv) {
23532344
Some(("get", [recv, get_arg], _)) => get_unwrap::check(cx, expr, recv, get_arg, false),
23542345
Some(("get_mut", [recv, get_arg], _)) => get_unwrap::check(cx, expr, recv, get_arg, true),
23552346
_ => unwrap_used::check(cx, expr, recv),
23562347
},
2357-
("unwrap_or", [u_arg]) => match method_call!(recv) {
2348+
("unwrap_or", [u_arg]) => match method_call(recv) {
23582349
Some((arith @ ("checked_add" | "checked_sub" | "checked_mul"), [lhs, rhs], _)) => {
23592350
manual_saturating_arithmetic::check(cx, expr, lhs, rhs, u_arg, &arith["checked_".len()..]);
23602351
},
@@ -2363,7 +2354,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
23632354
},
23642355
_ => {},
23652356
},
2366-
("unwrap_or_else", [u_arg]) => match method_call!(recv) {
2357+
("unwrap_or_else", [u_arg]) => match method_call(recv) {
23672358
Some(("map", [recv, map_arg], _)) if map_unwrap_or::check(cx, expr, recv, map_arg, u_arg, msrv) => {},
23682359
_ => {
23692360
unwrap_or_else_default::check(cx, expr, recv, u_arg);
@@ -2376,7 +2367,7 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
23762367
}
23772368

23782369
fn check_is_some_is_none(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, is_some: bool) {
2379-
if let Some((name @ ("find" | "position" | "rposition"), [f_recv, arg], span)) = method_call!(recv) {
2370+
if let Some((name @ ("find" | "position" | "rposition"), [f_recv, arg], span)) = method_call(recv) {
23802371
search_is_some::check(cx, expr, name, is_some, f_recv, arg, recv, span);
23812372
}
23822373
}

0 commit comments

Comments
 (0)