Skip to content

Commit 0d1aefa

Browse files
committed
Warn useless deprecation in check_attr.
1 parent 87a27f9 commit 0d1aefa

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-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: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use rustc_session::lint;
3636
use rustc_session::lint::builtin::{
3737
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, INVALID_MACRO_EXPORT_ARGUMENTS,
3838
MALFORMED_DIAGNOSTIC_ATTRIBUTES, MISPLACED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
39+
USELESS_DEPRECATED,
3940
};
4041
use rustc_session::parse::feature_err;
4142
use rustc_span::edition::Edition;
@@ -1031,7 +1032,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10311032
| Target::ForeignFn
10321033
| Target::ForeignStatic
10331034
| Target::ForeignTy
1034-
| Target::GenericParam(..)
1035+
| Target::GenericParam { .. }
10351036
| Target::MacroDef
10361037
| Target::PatField
10371038
| Target::ExprField => None,
@@ -2298,7 +2299,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22982299
| Target::ForeignFn
22992300
| Target::ForeignStatic
23002301
| Target::ForeignTy
2301-
| Target::GenericParam(_)
2302+
| Target::GenericParam { .. }
23022303
| Target::MacroDef
23032304
| Target::Param
23042305
| Target::PatField
@@ -2352,6 +2353,28 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23522353
errors::Deprecated,
23532354
);
23542355
}
2356+
Target::Impl { of_trait: true }
2357+
| Target::GenericParam { has_default: false, kind: _ } => {
2358+
self.tcx.emit_node_span_lint(
2359+
USELESS_DEPRECATED,
2360+
hir_id,
2361+
attr.span(),
2362+
errors::DeprecatedAnnotationHasNoEffect { span: attr.span() },
2363+
);
2364+
}
2365+
Target::AssocConst | Target::Method(..) | Target::AssocTy
2366+
if matches!(
2367+
self.tcx.def_kind(self.tcx.local_parent(hir_id.owner.def_id)),
2368+
DefKind::Impl { of_trait: true }
2369+
) =>
2370+
{
2371+
self.tcx.emit_node_span_lint(
2372+
USELESS_DEPRECATED,
2373+
hir_id,
2374+
attr.span(),
2375+
errors::DeprecatedAnnotationHasNoEffect { span: attr.span() },
2376+
);
2377+
}
23552378
_ => {}
23562379
}
23572380
}

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)