Skip to content

Commit f748e9e

Browse files
committed
Warn useless deprecation in check_attr.
1 parent 6635005 commit f748e9e

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
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 & 1 deletion
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;
@@ -1020,7 +1021,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10201021
| Target::ForeignFn
10211022
| Target::ForeignStatic
10221023
| Target::ForeignTy
1023-
| Target::GenericParam(..)
1024+
| Target::GenericParam { .. }
10241025
| Target::MacroDef
10251026
| Target::PatField
10261027
| Target::ExprField => None,
@@ -2283,6 +2284,28 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22832284
errors::Deprecated,
22842285
);
22852286
}
2287+
Target::Impl { of_trait: true }
2288+
| Target::GenericParam { has_default: false, kind: _ } => {
2289+
self.tcx.emit_node_span_lint(
2290+
USELESS_DEPRECATED,
2291+
hir_id,
2292+
attr.span(),
2293+
errors::DeprecatedAnnotationHasNoEffect { span: attr.span() },
2294+
);
2295+
}
2296+
Target::AssocConst | Target::Method(..) | Target::AssocTy
2297+
if matches!(
2298+
self.tcx.def_kind(self.tcx.local_parent(hir_id.owner.def_id)),
2299+
DefKind::Impl { of_trait: true }
2300+
) =>
2301+
{
2302+
self.tcx.emit_node_span_lint(
2303+
USELESS_DEPRECATED,
2304+
hir_id,
2305+
attr.span(),
2306+
errors::DeprecatedAnnotationHasNoEffect { span: attr.span() },
2307+
);
2308+
}
22862309
_ => {}
22872310
}
22882311
}

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)