Skip to content

Commit

Permalink
Fix noop_method_call detection for new diagnostic items
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho committed Sep 27, 2023
1 parent 92009f2 commit 127699e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/rustc_lint/src/noop_method_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {

let orig_ty = expr_ty.peel_refs();

if receiver_ty == expr_ty {
if receiver_ty == expr_ty
&& matches!(
name,
sym::noop_method_borrow | sym::noop_method_clone | sym::noop_method_deref
)
{
cx.emit_spanned_lint(
NOOP_METHOD_CALL,
span,
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/lint/noop-method-call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ fn non_generic(non_clone_type: &PlainType<u32>) {
non_clone_type.clone();
//~^ WARN call to `.clone()` on a reference in this situation does nothing
}

struct DiagnosticClone;
impl Clone for DiagnosticClone {
#[rustc_diagnostic_item = "other_clone"]
fn clone(&self) -> Self {
*self
}
}

fn with_other_diagnostic_item(x: &DiagnosticClone) {
x.clone();
}

0 comments on commit 127699e

Please sign in to comment.