diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2023-06-11 06:08:44 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2023-06-11 06:08:44 +0000 |
| commit | 1e36f7e9ae2a99139cf383193141e1429a20faf1 (patch) | |
| tree | a053ba391d57c2e98f870c1d80cf89fef3f7ee58 /compiler/rustc_lint/src/noop_method_call.rs | |
| parent | 970058e16b307e1cff01e2ddb084d2e8d14ea8be (diff) | |
| download | rust-1e36f7e9ae2a99139cf383193141e1429a20faf1.tar.gz rust-1e36f7e9ae2a99139cf383193141e1429a20faf1.zip | |
`suspicious_double_ref_op`: don't lint on `.borrow()`
Diffstat (limited to 'compiler/rustc_lint/src/noop_method_call.rs')
| -rw-r--r-- | compiler/rustc_lint/src/noop_method_call.rs | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index d054966459d..04bb34983af 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -76,22 +76,22 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { // We only care about method calls corresponding to the `Clone`, `Deref` and `Borrow` // traits and ignore any other method call. - let did = match cx.typeck_results().type_dependent_def(expr.hir_id) { - // Verify we are dealing with a method/associated function. - Some((DefKind::AssocFn, did)) => match cx.tcx.trait_of_item(did) { - // Check that we're dealing with a trait method for one of the traits we care about. - Some(trait_id) - if matches!( - cx.tcx.get_diagnostic_name(trait_id), - Some(sym::Borrow | sym::Clone | sym::Deref) - ) => - { - did - } - _ => return, - }, - _ => return, + + let Some((DefKind::AssocFn, did)) = + cx.typeck_results().type_dependent_def(expr.hir_id) + else { + return; + }; + + let Some(trait_id) = cx.tcx.trait_of_item(did) else { return }; + + if !matches!( + cx.tcx.get_diagnostic_name(trait_id), + Some(sym::Borrow | sym::Clone | sym::Deref) + ) { + return; }; + let substs = cx .tcx .normalize_erasing_regions(cx.param_env, cx.typeck_results().node_substs(expr.hir_id)); @@ -129,6 +129,9 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { NoopMethodCallDiag { method: call.ident.name, receiver_ty, label: span }, ); } else { + if op == "borrow" { + return; + } cx.emit_spanned_lint( SUSPICIOUS_DOUBLE_REF_OP, span, |
