mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Represent absence of 'since' attribute as a variant of DeprecatedSince
This commit is contained in:
parent
c52367276d
commit
e8868af75b
@ -720,7 +720,7 @@ pub fn eval_condition(
|
||||
|
||||
#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic)]
|
||||
pub struct Deprecation {
|
||||
pub since: Option<DeprecatedSince>,
|
||||
pub since: DeprecatedSince,
|
||||
/// The note to issue a reason.
|
||||
pub note: Option<Symbol>,
|
||||
/// A text snippet used to completely replace any use of the deprecated item in an expression.
|
||||
@ -738,8 +738,10 @@ pub enum DeprecatedSince {
|
||||
/// `feature(staged_api)` is off. Deprecation versions outside the standard
|
||||
/// library are allowed to be arbitrary strings, for better or worse.
|
||||
Symbol(Symbol),
|
||||
/// Failed to parse a deprecation version. An error has already been
|
||||
/// emitted.
|
||||
/// Deprecation version is unspecified but optional.
|
||||
Unspecified,
|
||||
/// Failed to parse a deprecation version, or the deprecation version is
|
||||
/// unspecified and required. An error has already been emitted.
|
||||
Err,
|
||||
}
|
||||
|
||||
@ -749,12 +751,12 @@ impl Deprecation {
|
||||
/// version).
|
||||
pub fn is_in_effect(&self) -> bool {
|
||||
match self.since {
|
||||
Some(DeprecatedSince::RustcVersion(since)) => since <= RustcVersion::CURRENT,
|
||||
Some(DeprecatedSince::Future) => false,
|
||||
DeprecatedSince::RustcVersion(since) => since <= RustcVersion::CURRENT,
|
||||
DeprecatedSince::Future => false,
|
||||
// The `since` field doesn't have semantic purpose without `#![staged_api]`.
|
||||
Some(DeprecatedSince::Symbol(_)) => true,
|
||||
DeprecatedSince::Symbol(_) => true,
|
||||
// Assume deprecation is in effect if "since" field is absent or invalid.
|
||||
None | Some(DeprecatedSince::Err) => true,
|
||||
DeprecatedSince::Unspecified | DeprecatedSince::Err => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -867,20 +869,20 @@ pub fn find_deprecation(
|
||||
|
||||
let since = if let Some(since) = since {
|
||||
if since.as_str() == "TBD" {
|
||||
Some(DeprecatedSince::Future)
|
||||
DeprecatedSince::Future
|
||||
} else if !is_rustc {
|
||||
Some(DeprecatedSince::Symbol(since))
|
||||
DeprecatedSince::Symbol(since)
|
||||
} else if let Some(version) = parse_version(since) {
|
||||
Some(DeprecatedSince::RustcVersion(version))
|
||||
DeprecatedSince::RustcVersion(version)
|
||||
} else {
|
||||
sess.emit_err(session_diagnostics::InvalidSince { span: attr.span });
|
||||
Some(DeprecatedSince::Err)
|
||||
DeprecatedSince::Err
|
||||
}
|
||||
} else if is_rustc {
|
||||
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
|
||||
DeprecatedSince::Err
|
||||
} else {
|
||||
if is_rustc {
|
||||
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
|
||||
}
|
||||
None
|
||||
DeprecatedSince::Unspecified
|
||||
};
|
||||
|
||||
if is_rustc && note.is_none() {
|
||||
|
@ -147,7 +147,7 @@ fn deprecation_lint(is_in_effect: bool) -> &'static Lint {
|
||||
|
||||
fn deprecation_message(
|
||||
is_in_effect: bool,
|
||||
since: Option<DeprecatedSince>,
|
||||
since: DeprecatedSince,
|
||||
note: Option<Symbol>,
|
||||
kind: &str,
|
||||
path: &str,
|
||||
@ -156,13 +156,13 @@ fn deprecation_message(
|
||||
format!("use of deprecated {kind} `{path}`")
|
||||
} else {
|
||||
match since {
|
||||
Some(DeprecatedSince::RustcVersion(version)) => format!(
|
||||
DeprecatedSince::RustcVersion(version) => format!(
|
||||
"use of {kind} `{path}` that will be deprecated in future version {version}"
|
||||
),
|
||||
Some(DeprecatedSince::Future) => {
|
||||
DeprecatedSince::Future => {
|
||||
format!("use of {kind} `{path}` that will be deprecated in a future Rust version")
|
||||
}
|
||||
Some(DeprecatedSince::Symbol(_)) | Some(DeprecatedSince::Err) | None => {
|
||||
DeprecatedSince::Symbol(_) | DeprecatedSince::Unspecified | DeprecatedSince::Err => {
|
||||
unreachable!("this deprecation is always in effect; {since:?}")
|
||||
}
|
||||
}
|
||||
@ -347,7 +347,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, Some(DeprecatedSince::RustcVersion(_))) {
|
||||
if !skip || matches!(depr_attr.since, DeprecatedSince::RustcVersion(_)) {
|
||||
// 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.
|
||||
|
@ -197,7 +197,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||
}
|
||||
|
||||
if let Some((
|
||||
rustc_attr::Deprecation { since: Some(DeprecatedSince::RustcVersion(_)), .. },
|
||||
rustc_attr::Deprecation { since: DeprecatedSince::RustcVersion(_), .. },
|
||||
span,
|
||||
)) = &depr
|
||||
{
|
||||
@ -228,7 +228,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||
if let (
|
||||
&Some(DeprecatedSince::RustcVersion(dep_since)),
|
||||
&attr::Stable { since: stab_since, .. },
|
||||
) = (&depr.as_ref().and_then(|(d, _)| d.since), &stab.level)
|
||||
) = (&depr.as_ref().map(|(d, _)| d.since), &stab.level)
|
||||
{
|
||||
match stab_since {
|
||||
StableSince::Current => {
|
||||
|
@ -620,18 +620,18 @@ fn short_item_info(
|
||||
// We display deprecation messages for #[deprecated], but only display
|
||||
// the future-deprecation messages for rustc versions.
|
||||
let mut message = match since {
|
||||
Some(DeprecatedSince::RustcVersion(version)) => {
|
||||
DeprecatedSince::RustcVersion(version) => {
|
||||
if depr.is_in_effect() {
|
||||
format!("Deprecated since {version}")
|
||||
} else {
|
||||
format!("Deprecating in {version}")
|
||||
}
|
||||
}
|
||||
Some(DeprecatedSince::Future) => String::from("Deprecating in a future Rust version"),
|
||||
Some(DeprecatedSince::Symbol(since)) => {
|
||||
DeprecatedSince::Future => String::from("Deprecating in a future Rust version"),
|
||||
DeprecatedSince::Symbol(since) => {
|
||||
format!("Deprecated since {}", Escape(since.as_str()))
|
||||
}
|
||||
Some(DeprecatedSince::Err) | None => String::from("Deprecated"),
|
||||
DeprecatedSince::Unspecified | DeprecatedSince::Err => String::from("Deprecated"),
|
||||
};
|
||||
|
||||
if let Some(note) = note {
|
||||
|
@ -141,10 +141,10 @@ where
|
||||
pub(crate) fn from_deprecation(deprecation: rustc_attr::Deprecation) -> Deprecation {
|
||||
let rustc_attr::Deprecation { since, note, suggestion: _ } = deprecation;
|
||||
let since = match since {
|
||||
Some(DeprecatedSince::RustcVersion(version)) => Some(version.to_string()),
|
||||
Some(DeprecatedSince::Future) => Some("TBD".to_owned()),
|
||||
Some(DeprecatedSince::Symbol(since)) => Some(since.to_string()),
|
||||
Some(DeprecatedSince::Err) | None => None,
|
||||
DeprecatedSince::RustcVersion(version) => Some(version.to_string()),
|
||||
DeprecatedSince::Future => Some("TBD".to_owned()),
|
||||
DeprecatedSince::Symbol(since) => Some(since.to_string()),
|
||||
DeprecatedSince::Unspecified | DeprecatedSince::Err => None,
|
||||
};
|
||||
Deprecation { since, note: note.map(|s| s.to_string()) }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user