Skip to content

Commit

Permalink
Add method for checking if deprecation is a rustc version
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 31, 2023
1 parent dccf10e commit 8b8906b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8b8906b

Please sign in to comment.