Skip to content

Commit 1e10fe9

Browse files
committed
Move deprecation_in_effect to inherent method on Deprecation
1 parent 8afb40b commit 1e10fe9

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

compiler/rustc_attr/src/builtin.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,22 @@ pub enum DeprecatedSince {
744744
Symbol(Symbol),
745745
}
746746

747+
impl Deprecation {
748+
/// Whether an item marked with #[deprecated(since = "X")] is currently
749+
/// deprecated (i.e., whether X is not greater than the current rustc
750+
/// version).
751+
pub fn is_in_effect(&self) -> bool {
752+
match self.since {
753+
Some(DeprecatedSince::RustcVersion(since)) => since <= RustcVersion::CURRENT,
754+
Some(DeprecatedSince::Future) => false,
755+
// The `since` field doesn't have semantic purpose without `#![staged_api]`.
756+
Some(DeprecatedSince::Symbol(_)) => true,
757+
// Assume deprecation is in effect if "since" field is missing.
758+
None => true,
759+
}
760+
}
761+
}
762+
747763
impl Display for DeprecatedSince {
748764
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
749765
match self {

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1818
use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE};
1919
use rustc_session::lint::{BuiltinLintDiagnostics, Level, Lint, LintBuffer};
2020
use rustc_session::parse::feature_err_issue;
21-
use rustc_session::{RustcVersion, Session};
21+
use rustc_session::Session;
2222
use rustc_span::symbol::{sym, Symbol};
2323
use rustc_span::Span;
2424
use std::num::NonZeroU32;
@@ -125,19 +125,6 @@ pub fn report_unstable(
125125
}
126126
}
127127

128-
/// Checks whether an item marked with `deprecated(since="X")` is currently
129-
/// deprecated (i.e., whether X is not greater than the current rustc version).
130-
pub fn deprecation_in_effect(depr: &Deprecation) -> bool {
131-
match depr.since {
132-
Some(DeprecatedSince::RustcVersion(since)) => since <= RustcVersion::CURRENT,
133-
Some(DeprecatedSince::Future) => false,
134-
// The `since` field doesn't have semantic purpose without `#![staged_api]`.
135-
Some(DeprecatedSince::Symbol(_)) => true,
136-
// Assume deprecation is in effect if "since" field is missing.
137-
None => true,
138-
}
139-
}
140-
141128
pub fn deprecation_suggestion(
142129
diag: &mut Diagnostic,
143130
kind: &str,
@@ -191,7 +178,7 @@ pub fn deprecation_message_and_lint(
191178
kind: &str,
192179
path: &str,
193180
) -> (String, &'static Lint) {
194-
let is_in_effect = deprecation_in_effect(depr);
181+
let is_in_effect = depr.is_in_effect();
195182
(
196183
deprecation_message(is_in_effect, depr.since, depr.note, kind, path),
197184
deprecation_lint(is_in_effect),
@@ -363,7 +350,7 @@ impl<'tcx> TyCtxt<'tcx> {
363350
// Calculating message for lint involves calling `self.def_path_str`.
364351
// Which by default to calculate visible path will invoke expensive `visible_parent_map` query.
365352
// So we skip message calculation altogether, if lint is allowed.
366-
let is_in_effect = deprecation_in_effect(depr_attr);
353+
let is_in_effect = depr_attr.is_in_effect();
367354
let lint = deprecation_lint(is_in_effect);
368355
if self.lint_level_at_node(lint, id).0 != Level::Allow {
369356
let def_path = with_no_trimmed_paths!(self.def_path_str(def_id));

src/librustdoc/html/render/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ use rustc_data_structures::captures::Captures;
5353
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5454
use rustc_hir::def_id::{DefId, DefIdSet};
5555
use rustc_hir::Mutability;
56-
use rustc_middle::middle::stability;
5756
use rustc_middle::ty::{self, TyCtxt};
5857
use rustc_session::RustcVersion;
5958
use rustc_span::{
@@ -621,7 +620,7 @@ fn short_item_info(
621620
// We display deprecation messages for #[deprecated], but only display
622621
// the future-deprecation messages for rustc versions.
623622
let mut message = if let Some(since) = since {
624-
if !stability::deprecation_in_effect(&depr) {
623+
if !depr.is_in_effect() {
625624
if let DeprecatedSince::Future = since {
626625
String::from("Deprecating in a future Rust version")
627626
} else {

src/librustdoc/html/render/print_item.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_hir as hir;
66
use rustc_hir::def::CtorKind;
77
use rustc_hir::def_id::DefId;
88
use rustc_index::IndexVec;
9-
use rustc_middle::middle::stability;
109
use rustc_middle::query::Key;
1110
use rustc_middle::ty::{self, TyCtxt};
1211
use rustc_span::hygiene::MacroKind;
@@ -591,11 +590,7 @@ fn extra_info_tags<'a, 'tcx: 'a>(
591590

592591
// The trailing space after each tag is to space it properly against the rest of the docs.
593592
if let Some(depr) = &item.deprecation(tcx) {
594-
let message = if stability::deprecation_in_effect(depr) {
595-
"Deprecated"
596-
} else {
597-
"Deprecation planned"
598-
};
593+
let message = if depr.is_in_effect() { "Deprecated" } else { "Deprecation planned" };
599594
write!(f, "{}", tag_html("deprecated", "", message))?;
600595
}
601596

0 commit comments

Comments
 (0)