Skip to content

Commit 8b8906b

Browse files
committed
Add method for checking if deprecation is a rustc version
1 parent dccf10e commit 8b8906b

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

compiler/rustc_attr/src/builtin.rs

+4
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,10 @@ impl Deprecation {
759759
DeprecatedSince::Unspecified | DeprecatedSince::Err => true,
760760
}
761761
}
762+
763+
pub fn is_since_rustc_version(&self) -> bool {
764+
matches!(self.since, DeprecatedSince::RustcVersion(_))
765+
}
762766
}
763767

764768
/// Finds the deprecation attribute. `None` if none exists.

compiler/rustc_middle/src/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl<'tcx> TyCtxt<'tcx> {
349349
// With #![staged_api], we want to emit down the whole
350350
// hierarchy.
351351
let depr_attr = &depr_entry.attr;
352-
if !skip || matches!(depr_attr.since, DeprecatedSince::RustcVersion(_)) {
352+
if !skip || depr_attr.is_since_rustc_version() {
353353
// Calculating message for lint involves calling `self.def_path_str`.
354354
// Which by default to calculate visible path will invoke expensive `visible_parent_map` query.
355355
// So we skip message calculation altogether, if lint is allowed.

compiler/rustc_passes/src/stability.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,8 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
196196
}
197197
}
198198

199-
if let Some((
200-
rustc_attr::Deprecation { since: DeprecatedSince::RustcVersion(_), .. },
201-
span,
202-
)) = &depr
203-
{
204-
if stab.is_none() {
205-
self.tcx.sess.emit_err(errors::DeprecatedAttribute { span: *span });
206-
}
199+
if let Some((depr, span)) = &depr && depr.is_since_rustc_version() && stab.is_none() {
200+
self.tcx.sess.emit_err(errors::DeprecatedAttribute { span: *span });
207201
}
208202

209203
if let Some((body_stab, _span)) = body_stab {

0 commit comments

Comments
 (0)