Warn useless deprecation in check_attr.
This commit is contained in:
@@ -51,7 +51,7 @@ pub enum Target {
|
||||
ForeignFn,
|
||||
ForeignStatic,
|
||||
ForeignTy,
|
||||
GenericParam(GenericParamKind),
|
||||
GenericParam { kind: GenericParamKind, has_default: bool },
|
||||
MacroDef,
|
||||
Param,
|
||||
PatField,
|
||||
@@ -93,7 +93,7 @@ impl Target {
|
||||
| Target::ForeignFn
|
||||
| Target::ForeignStatic
|
||||
| Target::ForeignTy
|
||||
| Target::GenericParam(_)
|
||||
| Target::GenericParam { .. }
|
||||
| Target::MacroDef
|
||||
| Target::Param
|
||||
| Target::PatField
|
||||
@@ -169,11 +169,17 @@ impl Target {
|
||||
|
||||
pub fn from_generic_param(generic_param: &hir::GenericParam<'_>) -> Target {
|
||||
match generic_param.kind {
|
||||
hir::GenericParamKind::Type { .. } => Target::GenericParam(GenericParamKind::Type),
|
||||
hir::GenericParamKind::Type { default, .. } => Target::GenericParam {
|
||||
kind: GenericParamKind::Type,
|
||||
has_default: default.is_some(),
|
||||
},
|
||||
hir::GenericParamKind::Lifetime { .. } => {
|
||||
Target::GenericParam(GenericParamKind::Lifetime)
|
||||
Target::GenericParam { kind: GenericParamKind::Lifetime, has_default: false }
|
||||
}
|
||||
hir::GenericParamKind::Const { .. } => Target::GenericParam(GenericParamKind::Const),
|
||||
hir::GenericParamKind::Const { default, .. } => Target::GenericParam {
|
||||
kind: GenericParamKind::Const,
|
||||
has_default: default.is_some(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +217,7 @@ impl Target {
|
||||
Target::ForeignFn => "foreign function",
|
||||
Target::ForeignStatic => "foreign static item",
|
||||
Target::ForeignTy => "foreign type",
|
||||
Target::GenericParam(kind) => match kind {
|
||||
Target::GenericParam { kind, has_default: _ } => match kind {
|
||||
GenericParamKind::Type => "type parameter",
|
||||
GenericParamKind::Lifetime => "lifetime parameter",
|
||||
GenericParamKind::Const => "const parameter",
|
||||
|
||||
@@ -36,6 +36,7 @@ use rustc_session::lint;
|
||||
use rustc_session::lint::builtin::{
|
||||
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, INVALID_MACRO_EXPORT_ARGUMENTS,
|
||||
MALFORMED_DIAGNOSTIC_ATTRIBUTES, MISPLACED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
|
||||
USELESS_DEPRECATED,
|
||||
};
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::edition::Edition;
|
||||
@@ -1031,7 +1032,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||
| Target::ForeignFn
|
||||
| Target::ForeignStatic
|
||||
| Target::ForeignTy
|
||||
| Target::GenericParam(..)
|
||||
| Target::GenericParam { .. }
|
||||
| Target::MacroDef
|
||||
| Target::PatField
|
||||
| Target::ExprField => None,
|
||||
@@ -2298,7 +2299,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||
| Target::ForeignFn
|
||||
| Target::ForeignStatic
|
||||
| Target::ForeignTy
|
||||
| Target::GenericParam(_)
|
||||
| Target::GenericParam { .. }
|
||||
| Target::MacroDef
|
||||
| Target::Param
|
||||
| Target::PatField
|
||||
@@ -2352,6 +2353,28 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||
errors::Deprecated,
|
||||
);
|
||||
}
|
||||
Target::Impl { of_trait: true }
|
||||
| Target::GenericParam { has_default: false, kind: _ } => {
|
||||
self.tcx.emit_node_span_lint(
|
||||
USELESS_DEPRECATED,
|
||||
hir_id,
|
||||
attr.span(),
|
||||
errors::DeprecatedAnnotationHasNoEffect { span: attr.span() },
|
||||
);
|
||||
}
|
||||
Target::AssocConst | Target::Method(..) | Target::AssocTy
|
||||
if matches!(
|
||||
self.tcx.def_kind(self.tcx.local_parent(hir_id.owner.def_id)),
|
||||
DefKind::Impl { of_trait: true }
|
||||
) =>
|
||||
{
|
||||
self.tcx.emit_node_span_lint(
|
||||
USELESS_DEPRECATED,
|
||||
hir_id,
|
||||
attr.span(),
|
||||
errors::DeprecatedAnnotationHasNoEffect { span: attr.span() },
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,7 @@ use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_session::lint;
|
||||
use rustc_session::lint::builtin::{
|
||||
DEPRECATED, INEFFECTIVE_UNSTABLE_TRAIT_IMPL, USELESS_DEPRECATED,
|
||||
};
|
||||
use rustc_session::lint::builtin::{DEPRECATED, INEFFECTIVE_UNSTABLE_TRAIT_IMPL};
|
||||
use rustc_span::{Span, Symbol, sym};
|
||||
use tracing::{debug, info};
|
||||
|
||||
@@ -125,19 +123,9 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||
let const_stability_indirect = find_attr!(attrs, AttributeKind::ConstStabilityIndirect);
|
||||
|
||||
let mut is_deprecated = false;
|
||||
if let Some((depr, span)) = &depr {
|
||||
if let Some((depr, _)) = &depr {
|
||||
is_deprecated = true;
|
||||
|
||||
if matches!(kind, AnnotationKind::Prohibited | AnnotationKind::DeprecationProhibited) {
|
||||
let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
|
||||
self.tcx.emit_node_span_lint(
|
||||
USELESS_DEPRECATED,
|
||||
hir_id,
|
||||
*span,
|
||||
errors::DeprecatedAnnotationHasNoEffect { span: *span },
|
||||
);
|
||||
}
|
||||
|
||||
// `Deprecation` is just two pointers, no need to intern it
|
||||
let depr_entry = DeprecationEntry::local(*depr, def_id);
|
||||
self.index.depr_map.insert(def_id, depr_entry);
|
||||
|
||||
Reference in New Issue
Block a user