Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3b184b6

Browse filesBrowse files
committed
Also warn against #[diagnostic::do_not_recommend] on plain impls
1 parent 56f25f7 commit 3b184b6
Copy full SHA for 3b184b6

File tree

Expand file treeCollapse file tree

4 files changed

+27
-4
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+27
-4
lines changed

‎compiler/rustc_passes/src/check_attr.rs

Copy file name to clipboardExpand all lines: compiler/rustc_passes/src/check_attr.rs
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
118118
for attr in attrs {
119119
match attr.path().as_slice() {
120120
[sym::diagnostic, sym::do_not_recommend, ..] => {
121-
self.check_do_not_recommend(attr.span, hir_id, target, attr)
121+
self.check_do_not_recommend(attr.span, hir_id, target, attr, item)
122122
}
123123
[sym::diagnostic, sym::on_unimplemented, ..] => {
124124
self.check_diagnostic_on_unimplemented(attr.span, hir_id, target)
@@ -356,8 +356,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
356356
hir_id: HirId,
357357
target: Target,
358358
attr: &Attribute,
359+
item: Option<ItemLike<'_>>,
359360
) {
360-
if !matches!(target, Target::Impl) {
361+
if !matches!(target, Target::Impl)
362+
|| matches!(
363+
item,
364+
Some(ItemLike::Item(hir::Item { kind: hir::ItemKind::Impl(_impl),.. }))
365+
if _impl.of_trait.is_none()
366+
)
367+
{
361368
self.tcx.emit_node_span_lint(
362369
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
363370
hir_id,

‎tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.current.stderr

Copy file name to clipboardExpand all lines: tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.current.stderr
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,11 @@ warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implement
4848
LL | #[diagnostic::do_not_recommend]
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5050

51-
warning: 8 warnings emitted
51+
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
52+
--> $DIR/incorrect-locations.rs:38:1
53+
|
54+
LL | #[diagnostic::do_not_recommend]
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
57+
warning: 9 warnings emitted
5258

‎tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.next.stderr

Copy file name to clipboardExpand all lines: tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.next.stderr
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,11 @@ warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implement
4848
LL | #[diagnostic::do_not_recommend]
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5050

51-
warning: 8 warnings emitted
51+
warning: `#[diagnostic::do_not_recommend]` can only be placed on trait implementations
52+
--> $DIR/incorrect-locations.rs:38:1
53+
|
54+
LL | #[diagnostic::do_not_recommend]
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
57+
warning: 9 warnings emitted
5258

‎tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.rs

Copy file name to clipboardExpand all lines: tests/ui/diagnostic_namespace/do_not_recommend/incorrect-locations.rs
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ type Type = ();
1919
//~^WARN `#[diagnostic::do_not_recommend]` can only be placed
2020
enum Enum {}
2121

22+
#[diagnostic::do_not_recommend]
23+
//~^WARN `#[diagnostic::do_not_recommend]` can only be placed
24+
impl Enum {}
25+
2226
#[diagnostic::do_not_recommend]
2327
//~^WARN `#[diagnostic::do_not_recommend]` can only be placed
2428
extern "C" {}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.