diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2023-05-25 05:21:44 +0000 | 
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2023-07-23 09:58:31 +0000 | 
| commit | 626efab67f184658eb966d3a69c31d7f1deb47e4 (patch) | |
| tree | 4d704671fa975f0279c5fd45e258879209129d3c /compiler/rustc_lint/src | |
| parent | 33ec4e4bb0e332072b5dbd31f8f024dff4e3f44e (diff) | |
| download | rust-626efab67f184658eb966d3a69c31d7f1deb47e4.tar.gz rust-626efab67f184658eb966d3a69c31d7f1deb47e4.zip | |
fix
Diffstat (limited to 'compiler/rustc_lint/src')
| -rw-r--r-- | compiler/rustc_lint/src/lints.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/noop_method_call.rs | 11 | 
2 files changed, 8 insertions, 6 deletions
| diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 1dea758bb29..322a3b6583d 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1231,7 +1231,8 @@ pub enum NonUpperCaseGlobalSub { #[note] pub struct NoopMethodCallDiag<'a> { pub method: Symbol, - pub receiver_ty: Ty<'a>, + pub orig_ty: Ty<'a>, + pub trait_: Symbol, #[label] pub label: Span, } diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index 2817a665bb0..bc0b9d6d818 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -85,10 +85,9 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { 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) - ) { + let Some(trait_) = cx.tcx.get_diagnostic_name(trait_id) else { return }; + + if !matches!(trait_, sym::Borrow | sym::Clone | sym::Deref) { return; }; @@ -113,11 +112,13 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { let expr_span = expr.span; let span = expr_span.with_lo(receiver.span.hi()); + let orig_ty = expr_ty.peel_refs(); + if receiver_ty == expr_ty { cx.emit_spanned_lint( NOOP_METHOD_CALL, span, - NoopMethodCallDiag { method: call.ident.name, receiver_ty, label: span }, + NoopMethodCallDiag { method: call.ident.name, orig_ty, trait_, label: span }, ); } else { match name { | 
