Move deprecation_in_effect to inherent method on Deprecation
This commit is contained in:
parent
8afb40b3a8
commit
1e10fe9eb6
4 changed files with 21 additions and 24 deletions
compiler
src/librustdoc/html/render
|
@ -744,6 +744,22 @@ pub enum DeprecatedSince {
|
||||||
Symbol(Symbol),
|
Symbol(Symbol),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Deprecation {
|
||||||
|
/// Whether an item marked with #[deprecated(since = "X")] is currently
|
||||||
|
/// deprecated (i.e., whether X is not greater than the current rustc
|
||||||
|
/// version).
|
||||||
|
pub fn is_in_effect(&self) -> bool {
|
||||||
|
match self.since {
|
||||||
|
Some(DeprecatedSince::RustcVersion(since)) => since <= RustcVersion::CURRENT,
|
||||||
|
Some(DeprecatedSince::Future) => false,
|
||||||
|
// The `since` field doesn't have semantic purpose without `#![staged_api]`.
|
||||||
|
Some(DeprecatedSince::Symbol(_)) => true,
|
||||||
|
// Assume deprecation is in effect if "since" field is missing.
|
||||||
|
None => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for DeprecatedSince {
|
impl Display for DeprecatedSince {
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -18,7 +18,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||||
use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE};
|
use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE};
|
||||||
use rustc_session::lint::{BuiltinLintDiagnostics, Level, Lint, LintBuffer};
|
use rustc_session::lint::{BuiltinLintDiagnostics, Level, Lint, LintBuffer};
|
||||||
use rustc_session::parse::feature_err_issue;
|
use rustc_session::parse::feature_err_issue;
|
||||||
use rustc_session::{RustcVersion, Session};
|
use rustc_session::Session;
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
@ -125,19 +125,6 @@ pub fn report_unstable(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks whether an item marked with `deprecated(since="X")` is currently
|
|
||||||
/// deprecated (i.e., whether X is not greater than the current rustc version).
|
|
||||||
pub fn deprecation_in_effect(depr: &Deprecation) -> bool {
|
|
||||||
match depr.since {
|
|
||||||
Some(DeprecatedSince::RustcVersion(since)) => since <= RustcVersion::CURRENT,
|
|
||||||
Some(DeprecatedSince::Future) => false,
|
|
||||||
// The `since` field doesn't have semantic purpose without `#![staged_api]`.
|
|
||||||
Some(DeprecatedSince::Symbol(_)) => true,
|
|
||||||
// Assume deprecation is in effect if "since" field is missing.
|
|
||||||
None => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn deprecation_suggestion(
|
pub fn deprecation_suggestion(
|
||||||
diag: &mut Diagnostic,
|
diag: &mut Diagnostic,
|
||||||
kind: &str,
|
kind: &str,
|
||||||
|
@ -191,7 +178,7 @@ pub fn deprecation_message_and_lint(
|
||||||
kind: &str,
|
kind: &str,
|
||||||
path: &str,
|
path: &str,
|
||||||
) -> (String, &'static Lint) {
|
) -> (String, &'static Lint) {
|
||||||
let is_in_effect = deprecation_in_effect(depr);
|
let is_in_effect = depr.is_in_effect();
|
||||||
(
|
(
|
||||||
deprecation_message(is_in_effect, depr.since, depr.note, kind, path),
|
deprecation_message(is_in_effect, depr.since, depr.note, kind, path),
|
||||||
deprecation_lint(is_in_effect),
|
deprecation_lint(is_in_effect),
|
||||||
|
@ -363,7 +350,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
// Calculating message for lint involves calling `self.def_path_str`.
|
// Calculating message for lint involves calling `self.def_path_str`.
|
||||||
// Which by default to calculate visible path will invoke expensive `visible_parent_map` query.
|
// Which by default to calculate visible path will invoke expensive `visible_parent_map` query.
|
||||||
// So we skip message calculation altogether, if lint is allowed.
|
// So we skip message calculation altogether, if lint is allowed.
|
||||||
let is_in_effect = deprecation_in_effect(depr_attr);
|
let is_in_effect = depr_attr.is_in_effect();
|
||||||
let lint = deprecation_lint(is_in_effect);
|
let lint = deprecation_lint(is_in_effect);
|
||||||
if self.lint_level_at_node(lint, id).0 != Level::Allow {
|
if self.lint_level_at_node(lint, id).0 != Level::Allow {
|
||||||
let def_path = with_no_trimmed_paths!(self.def_path_str(def_id));
|
let def_path = with_no_trimmed_paths!(self.def_path_str(def_id));
|
||||||
|
|
|
@ -53,7 +53,6 @@ use rustc_data_structures::captures::Captures;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_hir::def_id::{DefId, DefIdSet};
|
use rustc_hir::def_id::{DefId, DefIdSet};
|
||||||
use rustc_hir::Mutability;
|
use rustc_hir::Mutability;
|
||||||
use rustc_middle::middle::stability;
|
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_session::RustcVersion;
|
use rustc_session::RustcVersion;
|
||||||
use rustc_span::{
|
use rustc_span::{
|
||||||
|
@ -621,7 +620,7 @@ fn short_item_info(
|
||||||
// We display deprecation messages for #[deprecated], but only display
|
// We display deprecation messages for #[deprecated], but only display
|
||||||
// the future-deprecation messages for rustc versions.
|
// the future-deprecation messages for rustc versions.
|
||||||
let mut message = if let Some(since) = since {
|
let mut message = if let Some(since) = since {
|
||||||
if !stability::deprecation_in_effect(&depr) {
|
if !depr.is_in_effect() {
|
||||||
if let DeprecatedSince::Future = since {
|
if let DeprecatedSince::Future = since {
|
||||||
String::from("Deprecating in a future Rust version")
|
String::from("Deprecating in a future Rust version")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,7 +6,6 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def::CtorKind;
|
use rustc_hir::def::CtorKind;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_index::IndexVec;
|
use rustc_index::IndexVec;
|
||||||
use rustc_middle::middle::stability;
|
|
||||||
use rustc_middle::query::Key;
|
use rustc_middle::query::Key;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
|
@ -591,11 +590,7 @@ fn extra_info_tags<'a, 'tcx: 'a>(
|
||||||
|
|
||||||
// The trailing space after each tag is to space it properly against the rest of the docs.
|
// The trailing space after each tag is to space it properly against the rest of the docs.
|
||||||
if let Some(depr) = &item.deprecation(tcx) {
|
if let Some(depr) = &item.deprecation(tcx) {
|
||||||
let message = if stability::deprecation_in_effect(depr) {
|
let message = if depr.is_in_effect() { "Deprecated" } else { "Deprecation planned" };
|
||||||
"Deprecated"
|
|
||||||
} else {
|
|
||||||
"Deprecation planned"
|
|
||||||
};
|
|
||||||
write!(f, "{}", tag_html("deprecated", "", message))?;
|
write!(f, "{}", tag_html("deprecated", "", message))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue