about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_lint/src')
-rw-r--r--compiler/rustc_lint/src/builtin.rs3
-rw-r--r--compiler/rustc_lint/src/lints.rs5
-rw-r--r--compiler/rustc_lint/src/noop_method_call.rs14
3 files changed, 12 insertions, 10 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs
index cf6e7f16f07..ba05622bf37 100644
--- a/compiler/rustc_lint/src/builtin.rs
+++ b/compiler/rustc_lint/src/builtin.rs
@@ -1529,9 +1529,10 @@ declare_lint_pass!(
 impl<'tcx> LateLintPass<'tcx> for UnusedBrokenConst {
     fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
         match it.kind {
-            hir::ItemKind::Const(_, body_id) => {
+            hir::ItemKind::Const(_, _, body_id) => {
                 let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id();
                 // trigger the query once for all constants since that will already report the errors
+                // FIXME(generic_const_items): Does this work properly with generic const items?
                 cx.tcx.ensure().const_eval_poly(def_id);
             }
             hir::ItemKind::Static(_, _, body_id) => {
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index 2f2a5a93347..405ef62cd1f 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -1231,8 +1231,9 @@ pub enum NonUpperCaseGlobalSub {
 #[note]
 pub struct NoopMethodCallDiag<'a> {
     pub method: Symbol,
-    pub receiver_ty: Ty<'a>,
-    #[label]
+    pub orig_ty: Ty<'a>,
+    pub trait_: Symbol,
+    #[suggestion(code = "", applicability = "machine-applicable")]
     pub label: Span,
 }
 
diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs
index 13f650c2008..bc0b9d6d818 100644
--- a/compiler/rustc_lint/src/noop_method_call.rs
+++ b/compiler/rustc_lint/src/noop_method_call.rs
@@ -18,7 +18,6 @@ declare_lint! {
     ///
     /// ```rust
     /// # #![allow(unused)]
-    /// #![warn(noop_method_call)]
     /// struct Foo;
     /// let foo = &Foo;
     /// let clone: &Foo = foo.clone();
@@ -34,7 +33,7 @@ declare_lint! {
     /// calling `clone` on a `&T` where `T` does not implement clone, actually doesn't do anything
     /// as references are copy. This lint detects these calls and warns the user about them.
     pub NOOP_METHOD_CALL,
-    Allow,
+    Warn,
     "detects the use of well-known noop methods"
 }
 
@@ -86,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;
         };
 
@@ -114,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 {