about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2023-10-30 16:50:40 -0700
committerDavid Tolnay <dtolnay@gmail.com>2023-10-30 17:13:38 -0700
commit8b8906b2641ab2c7b852ac956b7388cb614e5391 (patch)
tree5e056ebf0bd406e177b069dd5df55010edf7d154
parentdccf10e98969c31f4a395a3555f781b8dd17b25d (diff)
downloadrust-8b8906b2641ab2c7b852ac956b7388cb614e5391.tar.gz
rust-8b8906b2641ab2c7b852ac956b7388cb614e5391.zip
Add method for checking if deprecation is a rustc version
-rw-r--r--compiler/rustc_attr/src/builtin.rs4
-rw-r--r--compiler/rustc_middle/src/middle/stability.rs2
-rw-r--r--compiler/rustc_passes/src/stability.rs10
3 files changed, 7 insertions, 9 deletions
diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs
index 33e9421eeb4..ad92d585510 100644
--- a/compiler/rustc_attr/src/builtin.rs
+++ b/compiler/rustc_attr/src/builtin.rs
@@ -759,6 +759,10 @@ impl Deprecation {
             DeprecatedSince::Unspecified | DeprecatedSince::Err => true,
         }
     }
+
+    pub fn is_since_rustc_version(&self) -> bool {
+        matches!(self.since, DeprecatedSince::RustcVersion(_))
+    }
 }
 
 /// Finds the deprecation attribute. `None` if none exists.
diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs
index afa624850ac..f7a55fa95b6 100644
--- a/compiler/rustc_middle/src/middle/stability.rs
+++ b/compiler/rustc_middle/src/middle/stability.rs
@@ -349,7 +349,7 @@ impl<'tcx> TyCtxt<'tcx> {
                 // With #![staged_api], we want to emit down the whole
                 // hierarchy.
                 let depr_attr = &depr_entry.attr;
-                if !skip || matches!(depr_attr.since, DeprecatedSince::RustcVersion(_)) {
+                if !skip || depr_attr.is_since_rustc_version() {
                     // Calculating message for lint involves calling `self.def_path_str`.
                     // Which by default to calculate visible path will invoke expensive `visible_parent_map` query.
                     // So we skip message calculation altogether, if lint is allowed.
diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs
index 6ef160f3b39..6a2498f3f99 100644
--- a/compiler/rustc_passes/src/stability.rs
+++ b/compiler/rustc_passes/src/stability.rs
@@ -196,14 +196,8 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
             }
         }
 
-        if let Some((
-            rustc_attr::Deprecation { since: DeprecatedSince::RustcVersion(_), .. },
-            span,
-        )) = &depr
-        {
-            if stab.is_none() {
-                self.tcx.sess.emit_err(errors::DeprecatedAttribute { span: *span });
-            }
+        if let Some((depr, span)) = &depr && depr.is_since_rustc_version() && stab.is_none() {
+            self.tcx.sess.emit_err(errors::DeprecatedAttribute { span: *span });
         }
 
         if let Some((body_stab, _span)) = body_stab {