Turn 'useless #[deprecated]' error into a lint.
This commit is contained in:
parent
706bc33651
commit
6f1992a7d6
2 changed files with 38 additions and 11 deletions
|
@ -2705,6 +2705,32 @@ declare_lint! {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare_lint! {
|
||||||
|
/// The `useless_deprecated` lint detects deprecation attributes with no effect.
|
||||||
|
///
|
||||||
|
/// ### Example
|
||||||
|
///
|
||||||
|
/// ```rust,compile_fail
|
||||||
|
/// struct X;
|
||||||
|
///
|
||||||
|
/// #[deprecated = "message"]
|
||||||
|
/// impl Default for X {
|
||||||
|
/// fn default() -> Self {
|
||||||
|
/// X
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// {{produces}}
|
||||||
|
///
|
||||||
|
/// ### Explanation
|
||||||
|
///
|
||||||
|
/// Deprecation attributes have no effect on trait implementations.
|
||||||
|
pub USELESS_DEPRECATED,
|
||||||
|
Deny,
|
||||||
|
"detects deprecation attributes with no effect",
|
||||||
|
}
|
||||||
|
|
||||||
declare_tool_lint! {
|
declare_tool_lint! {
|
||||||
pub rustc::INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
|
pub rustc::INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
|
||||||
Deny,
|
Deny,
|
||||||
|
@ -2792,6 +2818,7 @@ declare_lint_pass! {
|
||||||
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
|
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
|
||||||
UNINHABITED_STATIC,
|
UNINHABITED_STATIC,
|
||||||
FUNCTION_ITEM_REFERENCES,
|
FUNCTION_ITEM_REFERENCES,
|
||||||
|
USELESS_DEPRECATED,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ use rustc_middle::middle::privacy::AccessLevels;
|
||||||
use rustc_middle::middle::stability::{DeprecationEntry, Index};
|
use rustc_middle::middle::stability::{DeprecationEntry, Index};
|
||||||
use rustc_middle::ty::{self, query::Providers, TyCtxt};
|
use rustc_middle::ty::{self, query::Providers, TyCtxt};
|
||||||
use rustc_session::lint;
|
use rustc_session::lint;
|
||||||
use rustc_session::lint::builtin::INEFFECTIVE_UNSTABLE_TRAIT_IMPL;
|
use rustc_session::lint::builtin::{INEFFECTIVE_UNSTABLE_TRAIT_IMPL, USELESS_DEPRECATED};
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
|
@ -91,16 +91,16 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||||
is_deprecated = true;
|
is_deprecated = true;
|
||||||
|
|
||||||
if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited {
|
if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited {
|
||||||
self.tcx
|
self.tcx.struct_span_lint_hir(USELESS_DEPRECATED, hir_id, *span, |lint| {
|
||||||
.sess
|
lint.build("this `#[deprecated]' annotation has no effect")
|
||||||
.struct_span_err(*span, "this deprecation annotation is useless")
|
.span_suggestion(
|
||||||
.span_suggestion(
|
*span,
|
||||||
*span,
|
"try removing the deprecation attribute",
|
||||||
"try removing the deprecation attribute",
|
String::new(),
|
||||||
String::new(),
|
rustc_errors::Applicability::MachineApplicable,
|
||||||
rustc_errors::Applicability::MachineApplicable,
|
)
|
||||||
)
|
.emit()
|
||||||
.emit();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// `Deprecation` is just two pointers, no need to intern it
|
// `Deprecation` is just two pointers, no need to intern it
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue