Skip to content

Commit 6a47326

Browse files
committed
Migrated the rustc_passes lint for annotations without effect to the new diagnostic infrastructure
1 parent a926696 commit 6a47326

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

compiler/rustc_error_messages/locales/en-US/passes.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,6 @@ passes_link_ordinal = attribute should be applied to a foreign function or stati
268268
269269
passes_collapse_debuginfo = `collapse_debuginfo` attribute should be applied to macro definitions
270270
.label = not a macro definition
271+
272+
passes_deprecated_annotation_has_no_effect = this `#[deprecated]` annotation has no effect
273+
.suggestion = remove the unnecessary deprecation attribute

compiler/rustc_passes/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -658,3 +658,10 @@ pub struct CollapseDebuginfo {
658658
#[label]
659659
pub defn_span: Span,
660660
}
661+
662+
#[derive(LintDiagnostic)]
663+
#[diag(passes::deprecated_annotation_has_no_effect)]
664+
pub struct DeprecatedAnnotationHasNoEffect {
665+
#[suggestion(applicability = "machine-applicable", code = "")]
666+
pub span: Span,
667+
}

compiler/rustc_passes/src/stability.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! A pass that annotates every item and method with its stability level,
22
//! propagating default levels lexically from parent to children ast nodes.
33
4+
use crate::errors;
45
use rustc_attr::{
56
self as attr, rust_version_symbol, ConstStability, Stability, StabilityLevel, Unstable,
67
UnstableReason, VERSION_PLACEHOLDER,
@@ -122,16 +123,12 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
122123

123124
if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited {
124125
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
125-
self.tcx.struct_span_lint_hir(USELESS_DEPRECATED, hir_id, *span, |lint| {
126-
lint.build("this `#[deprecated]` annotation has no effect")
127-
.span_suggestion_short(
128-
*span,
129-
"remove the unnecessary deprecation attribute",
130-
"",
131-
rustc_errors::Applicability::MachineApplicable,
132-
)
133-
.emit();
134-
});
126+
self.tcx.emit_spanned_lint(
127+
USELESS_DEPRECATED,
128+
hir_id,
129+
*span,
130+
errors::DeprecatedAnnotationHasNoEffect { span: *span },
131+
);
135132
}
136133

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

0 commit comments

Comments
 (0)