From 0e2337a5d683c04004226502d2243ceb89cf4c22 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sat, 31 Oct 2020 15:34:10 +0100 Subject: [PATCH] Deny #[deprecated] on trait impl blocks. They have no effect there, but were silently accepted. --- compiler/rustc_passes/src/stability.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index c9497f2a5b2..18d9e9f78d6 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -31,6 +31,8 @@ enum AnnotationKind { Required, // Annotation is useless, reject it Prohibited, + // Deprecation annotation is useless, reject it. (Stability attribute is still required.) + DeprecationProhibited, // Annotation itself is useless, but it can be propagated to children Container, } @@ -89,7 +91,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { if let Some(depr) = &depr { is_deprecated = true; - if kind == AnnotationKind::Prohibited { + if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited { self.tcx.sess.span_err(item_sp, "This deprecation annotation is useless"); } @@ -322,6 +324,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { } hir::ItemKind::Impl { of_trait: Some(_), .. } => { self.in_trait_impl = true; + kind = AnnotationKind::DeprecationProhibited; } hir::ItemKind::Struct(ref sd, _) => { if let Some(ctor_hir_id) = sd.ctor_hir_id() {