Skip to content

Commit 6f1992a

Browse files
committed
Turn 'useless #[deprecated]' error into a lint.
1 parent 706bc33 commit 6f1992a

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,32 @@ declare_lint! {
27052705
};
27062706
}
27072707

2708+
declare_lint! {
2709+
/// The `useless_deprecated` lint detects deprecation attributes with no effect.
2710+
///
2711+
/// ### Example
2712+
///
2713+
/// ```rust,compile_fail
2714+
/// struct X;
2715+
///
2716+
/// #[deprecated = "message"]
2717+
/// impl Default for X {
2718+
/// fn default() -> Self {
2719+
/// X
2720+
/// }
2721+
/// }
2722+
/// ```
2723+
///
2724+
/// {{produces}}
2725+
///
2726+
/// ### Explanation
2727+
///
2728+
/// Deprecation attributes have no effect on trait implementations.
2729+
pub USELESS_DEPRECATED,
2730+
Deny,
2731+
"detects deprecation attributes with no effect",
2732+
}
2733+
27082734
declare_tool_lint! {
27092735
pub rustc::INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
27102736
Deny,
@@ -2792,6 +2818,7 @@ declare_lint_pass! {
27922818
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
27932819
UNINHABITED_STATIC,
27942820
FUNCTION_ITEM_REFERENCES,
2821+
USELESS_DEPRECATED,
27952822
]
27962823
}
27972824

compiler/rustc_passes/src/stability.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::middle::privacy::AccessLevels;
1515
use rustc_middle::middle::stability::{DeprecationEntry, Index};
1616
use rustc_middle::ty::{self, query::Providers, TyCtxt};
1717
use rustc_session::lint;
18-
use rustc_session::lint::builtin::INEFFECTIVE_UNSTABLE_TRAIT_IMPL;
18+
use rustc_session::lint::builtin::{INEFFECTIVE_UNSTABLE_TRAIT_IMPL, USELESS_DEPRECATED};
1919
use rustc_session::parse::feature_err;
2020
use rustc_session::Session;
2121
use rustc_span::symbol::{sym, Symbol};
@@ -91,16 +91,16 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
9191
is_deprecated = true;
9292

9393
if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited {
94-
self.tcx
95-
.sess
96-
.struct_span_err(*span, "this deprecation annotation is useless")
97-
.span_suggestion(
98-
*span,
99-
"try removing the deprecation attribute",
100-
String::new(),
101-
rustc_errors::Applicability::MachineApplicable,
102-
)
103-
.emit();
94+
self.tcx.struct_span_lint_hir(USELESS_DEPRECATED, hir_id, *span, |lint| {
95+
lint.build("this `#[deprecated]' annotation has no effect")
96+
.span_suggestion(
97+
*span,
98+
"try removing the deprecation attribute",
99+
String::new(),
100+
rustc_errors::Applicability::MachineApplicable,
101+
)
102+
.emit()
103+
});
104104
}
105105

106106
// `Deprecation` is just two pointers, no need to intern it

0 commit comments

Comments
 (0)