Skip to content

Commit f7403d8

Browse files
committed
Warn useless deprecation in check_attr.
1 parent bad798e commit f7403d8

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

compiler/rustc_hir/src/target.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub enum Target {
5151
ForeignFn,
5252
ForeignStatic,
5353
ForeignTy,
54-
GenericParam(GenericParamKind),
54+
GenericParam { kind: GenericParamKind, has_default: bool },
5555
MacroDef,
5656
Param,
5757
PatField,
@@ -93,7 +93,7 @@ impl Target {
9393
| Target::ForeignFn
9494
| Target::ForeignStatic
9595
| Target::ForeignTy
96-
| Target::GenericParam(_)
96+
| Target::GenericParam { .. }
9797
| Target::MacroDef
9898
| Target::Param
9999
| Target::PatField
@@ -169,11 +169,17 @@ impl Target {
169169

170170
pub fn from_generic_param(generic_param: &hir::GenericParam<'_>) -> Target {
171171
match generic_param.kind {
172-
hir::GenericParamKind::Type { .. } => Target::GenericParam(GenericParamKind::Type),
172+
hir::GenericParamKind::Type { default, .. } => Target::GenericParam {
173+
kind: GenericParamKind::Type,
174+
has_default: default.is_some(),
175+
},
173176
hir::GenericParamKind::Lifetime { .. } => {
174-
Target::GenericParam(GenericParamKind::Lifetime)
177+
Target::GenericParam { kind: GenericParamKind::Lifetime, has_default: false }
175178
}
176-
hir::GenericParamKind::Const { .. } => Target::GenericParam(GenericParamKind::Const),
179+
hir::GenericParamKind::Const { default, .. } => Target::GenericParam {
180+
kind: GenericParamKind::Const,
181+
has_default: default.is_some(),
182+
},
177183
}
178184
}
179185

@@ -211,7 +217,7 @@ impl Target {
211217
Target::ForeignFn => "foreign function",
212218
Target::ForeignStatic => "foreign static item",
213219
Target::ForeignTy => "foreign type",
214-
Target::GenericParam(kind) => match kind {
220+
Target::GenericParam { kind, has_default: _ } => match kind {
215221
GenericParamKind::Type => "type parameter",
216222
GenericParamKind::Lifetime => "lifetime parameter",
217223
GenericParamKind::Const => "const parameter",

compiler/rustc_passes/src/check_attr.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_session::config::CrateType;
3333
use rustc_session::lint;
3434
use rustc_session::lint::builtin::{
3535
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, INVALID_MACRO_EXPORT_ARGUMENTS,
36-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
36+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES, USELESS_DEPRECATED,
3737
};
3838
use rustc_session::parse::feature_err;
3939
use rustc_span::edition::Edition;
@@ -1001,7 +1001,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10011001
| Target::ForeignFn
10021002
| Target::ForeignStatic
10031003
| Target::ForeignTy
1004-
| Target::GenericParam(..)
1004+
| Target::GenericParam { .. }
10051005
| Target::MacroDef
10061006
| Target::PatField
10071007
| Target::ExprField => None,
@@ -2264,6 +2264,28 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22642264
errors::Deprecated,
22652265
);
22662266
}
2267+
Target::Impl { of_trait: true }
2268+
| Target::GenericParam { has_default: false, kind: _ } => {
2269+
self.tcx.emit_node_span_lint(
2270+
USELESS_DEPRECATED,
2271+
hir_id,
2272+
attr.span(),
2273+
errors::DeprecatedAnnotationHasNoEffect { span: attr.span() },
2274+
);
2275+
}
2276+
Target::AssocConst | Target::Method(..) | Target::AssocTy
2277+
if matches!(
2278+
self.tcx.def_kind(self.tcx.local_parent(hir_id.owner.def_id)),
2279+
DefKind::Impl { of_trait: true }
2280+
) =>
2281+
{
2282+
self.tcx.emit_node_span_lint(
2283+
USELESS_DEPRECATED,
2284+
hir_id,
2285+
attr.span(),
2286+
errors::DeprecatedAnnotationHasNoEffect { span: attr.span() },
2287+
);
2288+
}
22672289
_ => {}
22682290
}
22692291
}

compiler/rustc_passes/src/stability.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ use rustc_middle::query::Providers;
2727
use rustc_middle::ty::TyCtxt;
2828
use rustc_middle::ty::print::with_no_trimmed_paths;
2929
use rustc_session::lint;
30-
use rustc_session::lint::builtin::{
31-
DEPRECATED, INEFFECTIVE_UNSTABLE_TRAIT_IMPL, USELESS_DEPRECATED,
32-
};
30+
use rustc_session::lint::builtin::{DEPRECATED, INEFFECTIVE_UNSTABLE_TRAIT_IMPL};
3331
use rustc_span::{Span, Symbol, sym};
3432
use tracing::{debug, info};
3533

@@ -125,19 +123,9 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
125123
let const_stability_indirect = find_attr!(attrs, AttributeKind::ConstStabilityIndirect);
126124

127125
let mut is_deprecated = false;
128-
if let Some((depr, span)) = &depr {
126+
if let Some((depr, _)) = &depr {
129127
is_deprecated = true;
130128

131-
if matches!(kind, AnnotationKind::Prohibited | AnnotationKind::DeprecationProhibited) {
132-
let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
133-
self.tcx.emit_node_span_lint(
134-
USELESS_DEPRECATED,
135-
hir_id,
136-
*span,
137-
errors::DeprecatedAnnotationHasNoEffect { span: *span },
138-
);
139-
}
140-
141129
// `Deprecation` is just two pointers, no need to intern it
142130
let depr_entry = DeprecationEntry::local(*depr, def_id);
143131
self.index.depr_map.insert(def_id, depr_entry);

0 commit comments

Comments
 (0)