about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
diff options
context:
space:
mode:
authorGeorg Semmler <github@weiznich.de>2024-10-25 08:54:05 +0200
committerGeorg Semmler <github@weiznich.de>2024-12-18 07:10:55 +0100
commitad29947f02520878d6e60e6b26b3a55fae3b7982 (patch)
tree2c7ed2983927d6121cd4a53a429bb84dffdbbdf7 /compiler/rustc_passes/src
parentdd31713c53bbd22915ecb0d43043923730726f20 (diff)
downloadrust-ad29947f02520878d6e60e6b26b3a55fae3b7982.tar.gz
rust-ad29947f02520878d6e60e6b26b3a55fae3b7982.zip
Also warn against `#[diagnostic::do_not_recommend]` on plain impls
Diffstat (limited to 'compiler/rustc_passes/src')
-rw-r--r--compiler/rustc_passes/src/check_attr.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index 9879dfa9720..2310dd9dc72 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -115,7 +115,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
         for attr in attrs {
             match attr.path().as_slice() {
                 [sym::diagnostic, sym::do_not_recommend, ..] => {
-                    self.check_do_not_recommend(attr.span, hir_id, target, attr)
+                    self.check_do_not_recommend(attr.span, hir_id, target, attr, item)
                 }
                 [sym::diagnostic, sym::on_unimplemented, ..] => {
                     self.check_diagnostic_on_unimplemented(attr.span, hir_id, target)
@@ -354,8 +354,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
         hir_id: HirId,
         target: Target,
         attr: &Attribute,
+        item: Option<ItemLike<'_>>,
     ) {
-        if !matches!(target, Target::Impl) {
+        if !matches!(target, Target::Impl)
+            || matches!(
+                item,
+                Some(ItemLike::Item(hir::Item {  kind: hir::ItemKind::Impl(_impl),.. }))
+                    if _impl.of_trait.is_none()
+            )
+        {
             self.tcx.emit_node_span_lint(
                 UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
                 hir_id,