Represent absence of 'since' attribute as a variant of DeprecatedSince
This commit is contained in:
parent
c52367276d
commit
e8868af75b
5 changed files with 32 additions and 30 deletions
|
@ -720,7 +720,7 @@ pub fn eval_condition(
|
||||||
|
|
||||||
#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic)]
|
#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic)]
|
||||||
pub struct Deprecation {
|
pub struct Deprecation {
|
||||||
pub since: Option<DeprecatedSince>,
|
pub since: DeprecatedSince,
|
||||||
/// The note to issue a reason.
|
/// The note to issue a reason.
|
||||||
pub note: Option<Symbol>,
|
pub note: Option<Symbol>,
|
||||||
/// A text snippet used to completely replace any use of the deprecated item in an expression.
|
/// 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
|
/// `feature(staged_api)` is off. Deprecation versions outside the standard
|
||||||
/// library are allowed to be arbitrary strings, for better or worse.
|
/// library are allowed to be arbitrary strings, for better or worse.
|
||||||
Symbol(Symbol),
|
Symbol(Symbol),
|
||||||
/// Failed to parse a deprecation version. An error has already been
|
/// Deprecation version is unspecified but optional.
|
||||||
/// emitted.
|
Unspecified,
|
||||||
|
/// Failed to parse a deprecation version, or the deprecation version is
|
||||||
|
/// unspecified and required. An error has already been emitted.
|
||||||
Err,
|
Err,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,12 +751,12 @@ impl Deprecation {
|
||||||
/// version).
|
/// version).
|
||||||
pub fn is_in_effect(&self) -> bool {
|
pub fn is_in_effect(&self) -> bool {
|
||||||
match self.since {
|
match self.since {
|
||||||
Some(DeprecatedSince::RustcVersion(since)) => since <= RustcVersion::CURRENT,
|
DeprecatedSince::RustcVersion(since) => since <= RustcVersion::CURRENT,
|
||||||
Some(DeprecatedSince::Future) => false,
|
DeprecatedSince::Future => false,
|
||||||
// The `since` field doesn't have semantic purpose without `#![staged_api]`.
|
// 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.
|
// 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 {
|
let since = if let Some(since) = since {
|
||||||
if since.as_str() == "TBD" {
|
if since.as_str() == "TBD" {
|
||||||
Some(DeprecatedSince::Future)
|
DeprecatedSince::Future
|
||||||
} else if !is_rustc {
|
} else if !is_rustc {
|
||||||
Some(DeprecatedSince::Symbol(since))
|
DeprecatedSince::Symbol(since)
|
||||||
} else if let Some(version) = parse_version(since) {
|
} else if let Some(version) = parse_version(since) {
|
||||||
Some(DeprecatedSince::RustcVersion(version))
|
DeprecatedSince::RustcVersion(version)
|
||||||
} else {
|
} else {
|
||||||
sess.emit_err(session_diagnostics::InvalidSince { span: attr.span });
|
sess.emit_err(session_diagnostics::InvalidSince { span: attr.span });
|
||||||
Some(DeprecatedSince::Err)
|
DeprecatedSince::Err
|
||||||
}
|
}
|
||||||
} else {
|
} else if is_rustc {
|
||||||
if is_rustc {
|
|
||||||
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
|
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
|
||||||
}
|
DeprecatedSince::Err
|
||||||
None
|
} else {
|
||||||
|
DeprecatedSince::Unspecified
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_rustc && note.is_none() {
|
if is_rustc && note.is_none() {
|
||||||
|
|
|
@ -147,7 +147,7 @@ fn deprecation_lint(is_in_effect: bool) -> &'static Lint {
|
||||||
|
|
||||||
fn deprecation_message(
|
fn deprecation_message(
|
||||||
is_in_effect: bool,
|
is_in_effect: bool,
|
||||||
since: Option<DeprecatedSince>,
|
since: DeprecatedSince,
|
||||||
note: Option<Symbol>,
|
note: Option<Symbol>,
|
||||||
kind: &str,
|
kind: &str,
|
||||||
path: &str,
|
path: &str,
|
||||||
|
@ -156,13 +156,13 @@ fn deprecation_message(
|
||||||
format!("use of deprecated {kind} `{path}`")
|
format!("use of deprecated {kind} `{path}`")
|
||||||
} else {
|
} else {
|
||||||
match since {
|
match since {
|
||||||
Some(DeprecatedSince::RustcVersion(version)) => format!(
|
DeprecatedSince::RustcVersion(version) => format!(
|
||||||
"use of {kind} `{path}` that will be deprecated in future version {version}"
|
"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")
|
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:?}")
|
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
|
// With #![staged_api], we want to emit down the whole
|
||||||
// hierarchy.
|
// hierarchy.
|
||||||
let depr_attr = &depr_entry.attr;
|
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`.
|
// 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.
|
||||||
|
|
|
@ -197,7 +197,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((
|
if let Some((
|
||||||
rustc_attr::Deprecation { since: Some(DeprecatedSince::RustcVersion(_)), .. },
|
rustc_attr::Deprecation { since: DeprecatedSince::RustcVersion(_), .. },
|
||||||
span,
|
span,
|
||||||
)) = &depr
|
)) = &depr
|
||||||
{
|
{
|
||||||
|
@ -228,7 +228,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||||
if let (
|
if let (
|
||||||
&Some(DeprecatedSince::RustcVersion(dep_since)),
|
&Some(DeprecatedSince::RustcVersion(dep_since)),
|
||||||
&attr::Stable { since: stab_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 {
|
match stab_since {
|
||||||
StableSince::Current => {
|
StableSince::Current => {
|
||||||
|
|
|
@ -620,18 +620,18 @@ 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 = match since {
|
let mut message = match since {
|
||||||
Some(DeprecatedSince::RustcVersion(version)) => {
|
DeprecatedSince::RustcVersion(version) => {
|
||||||
if depr.is_in_effect() {
|
if depr.is_in_effect() {
|
||||||
format!("Deprecated since {version}")
|
format!("Deprecated since {version}")
|
||||||
} else {
|
} else {
|
||||||
format!("Deprecating in {version}")
|
format!("Deprecating in {version}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(DeprecatedSince::Future) => String::from("Deprecating in a future Rust version"),
|
DeprecatedSince::Future => String::from("Deprecating in a future Rust version"),
|
||||||
Some(DeprecatedSince::Symbol(since)) => {
|
DeprecatedSince::Symbol(since) => {
|
||||||
format!("Deprecated since {}", Escape(since.as_str()))
|
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 {
|
if let Some(note) = note {
|
||||||
|
|
|
@ -141,10 +141,10 @@ where
|
||||||
pub(crate) fn from_deprecation(deprecation: rustc_attr::Deprecation) -> Deprecation {
|
pub(crate) fn from_deprecation(deprecation: rustc_attr::Deprecation) -> Deprecation {
|
||||||
let rustc_attr::Deprecation { since, note, suggestion: _ } = deprecation;
|
let rustc_attr::Deprecation { since, note, suggestion: _ } = deprecation;
|
||||||
let since = match since {
|
let since = match since {
|
||||||
Some(DeprecatedSince::RustcVersion(version)) => Some(version.to_string()),
|
DeprecatedSince::RustcVersion(version) => Some(version.to_string()),
|
||||||
Some(DeprecatedSince::Future) => Some("TBD".to_owned()),
|
DeprecatedSince::Future => Some("TBD".to_owned()),
|
||||||
Some(DeprecatedSince::Symbol(since)) => Some(since.to_string()),
|
DeprecatedSince::Symbol(since) => Some(since.to_string()),
|
||||||
Some(DeprecatedSince::Err) | None => None,
|
DeprecatedSince::Unspecified | DeprecatedSince::Err => None,
|
||||||
};
|
};
|
||||||
Deprecation { since, note: note.map(|s| s.to_string()) }
|
Deprecation { since, note: note.map(|s| s.to_string()) }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue