Skip to content

Commit e8868af

Browse files
committedOct 30, 2023
Represent absence of 'since' attribute as a variant of DeprecatedSince
1 parent c523672 commit e8868af

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed
 

Diff for: ‎compiler/rustc_attr/src/builtin.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ pub fn eval_condition(
720720

721721
#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic)]
722722
pub struct Deprecation {
723-
pub since: Option<DeprecatedSince>,
723+
pub since: DeprecatedSince,
724724
/// The note to issue a reason.
725725
pub note: Option<Symbol>,
726726
/// A text snippet used to completely replace any use of the deprecated item in an expression.
@@ -738,8 +738,10 @@ pub enum DeprecatedSince {
738738
/// `feature(staged_api)` is off. Deprecation versions outside the standard
739739
/// library are allowed to be arbitrary strings, for better or worse.
740740
Symbol(Symbol),
741-
/// Failed to parse a deprecation version. An error has already been
742-
/// emitted.
741+
/// Deprecation version is unspecified but optional.
742+
Unspecified,
743+
/// Failed to parse a deprecation version, or the deprecation version is
744+
/// unspecified and required. An error has already been emitted.
743745
Err,
744746
}
745747

@@ -749,12 +751,12 @@ impl Deprecation {
749751
/// version).
750752
pub fn is_in_effect(&self) -> bool {
751753
match self.since {
752-
Some(DeprecatedSince::RustcVersion(since)) => since <= RustcVersion::CURRENT,
753-
Some(DeprecatedSince::Future) => false,
754+
DeprecatedSince::RustcVersion(since) => since <= RustcVersion::CURRENT,
755+
DeprecatedSince::Future => false,
754756
// The `since` field doesn't have semantic purpose without `#![staged_api]`.
755-
Some(DeprecatedSince::Symbol(_)) => true,
757+
DeprecatedSince::Symbol(_) => true,
756758
// Assume deprecation is in effect if "since" field is absent or invalid.
757-
None | Some(DeprecatedSince::Err) => true,
759+
DeprecatedSince::Unspecified | DeprecatedSince::Err => true,
758760
}
759761
}
760762
}
@@ -867,20 +869,20 @@ pub fn find_deprecation(
867869

868870
let since = if let Some(since) = since {
869871
if since.as_str() == "TBD" {
870-
Some(DeprecatedSince::Future)
872+
DeprecatedSince::Future
871873
} else if !is_rustc {
872-
Some(DeprecatedSince::Symbol(since))
874+
DeprecatedSince::Symbol(since)
873875
} else if let Some(version) = parse_version(since) {
874-
Some(DeprecatedSince::RustcVersion(version))
876+
DeprecatedSince::RustcVersion(version)
875877
} else {
876878
sess.emit_err(session_diagnostics::InvalidSince { span: attr.span });
877-
Some(DeprecatedSince::Err)
879+
DeprecatedSince::Err
878880
}
881+
} else if is_rustc {
882+
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
883+
DeprecatedSince::Err
879884
} else {
880-
if is_rustc {
881-
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
882-
}
883-
None
885+
DeprecatedSince::Unspecified
884886
};
885887

886888
if is_rustc && note.is_none() {

Diff for: ‎compiler/rustc_middle/src/middle/stability.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn deprecation_lint(is_in_effect: bool) -> &'static Lint {
147147

148148
fn deprecation_message(
149149
is_in_effect: bool,
150-
since: Option<DeprecatedSince>,
150+
since: DeprecatedSince,
151151
note: Option<Symbol>,
152152
kind: &str,
153153
path: &str,
@@ -156,13 +156,13 @@ fn deprecation_message(
156156
format!("use of deprecated {kind} `{path}`")
157157
} else {
158158
match since {
159-
Some(DeprecatedSince::RustcVersion(version)) => format!(
159+
DeprecatedSince::RustcVersion(version) => format!(
160160
"use of {kind} `{path}` that will be deprecated in future version {version}"
161161
),
162-
Some(DeprecatedSince::Future) => {
162+
DeprecatedSince::Future => {
163163
format!("use of {kind} `{path}` that will be deprecated in a future Rust version")
164164
}
165-
Some(DeprecatedSince::Symbol(_)) | Some(DeprecatedSince::Err) | None => {
165+
DeprecatedSince::Symbol(_) | DeprecatedSince::Unspecified | DeprecatedSince::Err => {
166166
unreachable!("this deprecation is always in effect; {since:?}")
167167
}
168168
}
@@ -347,7 +347,7 @@ impl<'tcx> TyCtxt<'tcx> {
347347
// With #![staged_api], we want to emit down the whole
348348
// hierarchy.
349349
let depr_attr = &depr_entry.attr;
350-
if !skip || matches!(depr_attr.since, Some(DeprecatedSince::RustcVersion(_))) {
350+
if !skip || matches!(depr_attr.since, DeprecatedSince::RustcVersion(_)) {
351351
// Calculating message for lint involves calling `self.def_path_str`.
352352
// Which by default to calculate visible path will invoke expensive `visible_parent_map` query.
353353
// So we skip message calculation altogether, if lint is allowed.

Diff for: ‎compiler/rustc_passes/src/stability.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
197197
}
198198

199199
if let Some((
200-
rustc_attr::Deprecation { since: Some(DeprecatedSince::RustcVersion(_)), .. },
200+
rustc_attr::Deprecation { since: DeprecatedSince::RustcVersion(_), .. },
201201
span,
202202
)) = &depr
203203
{
@@ -228,7 +228,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
228228
if let (
229229
&Some(DeprecatedSince::RustcVersion(dep_since)),
230230
&attr::Stable { since: stab_since, .. },
231-
) = (&depr.as_ref().and_then(|(d, _)| d.since), &stab.level)
231+
) = (&depr.as_ref().map(|(d, _)| d.since), &stab.level)
232232
{
233233
match stab_since {
234234
StableSince::Current => {

Diff for: ‎src/librustdoc/html/render/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -620,18 +620,18 @@ fn short_item_info(
620620
// We display deprecation messages for #[deprecated], but only display
621621
// the future-deprecation messages for rustc versions.
622622
let mut message = match since {
623-
Some(DeprecatedSince::RustcVersion(version)) => {
623+
DeprecatedSince::RustcVersion(version) => {
624624
if depr.is_in_effect() {
625625
format!("Deprecated since {version}")
626626
} else {
627627
format!("Deprecating in {version}")
628628
}
629629
}
630-
Some(DeprecatedSince::Future) => String::from("Deprecating in a future Rust version"),
631-
Some(DeprecatedSince::Symbol(since)) => {
630+
DeprecatedSince::Future => String::from("Deprecating in a future Rust version"),
631+
DeprecatedSince::Symbol(since) => {
632632
format!("Deprecated since {}", Escape(since.as_str()))
633633
}
634-
Some(DeprecatedSince::Err) | None => String::from("Deprecated"),
634+
DeprecatedSince::Unspecified | DeprecatedSince::Err => String::from("Deprecated"),
635635
};
636636

637637
if let Some(note) = note {

Diff for: ‎src/librustdoc/json/conversions.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ where
141141
pub(crate) fn from_deprecation(deprecation: rustc_attr::Deprecation) -> Deprecation {
142142
let rustc_attr::Deprecation { since, note, suggestion: _ } = deprecation;
143143
let since = match since {
144-
Some(DeprecatedSince::RustcVersion(version)) => Some(version.to_string()),
145-
Some(DeprecatedSince::Future) => Some("TBD".to_owned()),
146-
Some(DeprecatedSince::Symbol(since)) => Some(since.to_string()),
147-
Some(DeprecatedSince::Err) | None => None,
144+
DeprecatedSince::RustcVersion(version) => Some(version.to_string()),
145+
DeprecatedSince::Future => Some("TBD".to_owned()),
146+
DeprecatedSince::Symbol(since) => Some(since.to_string()),
147+
DeprecatedSince::Unspecified | DeprecatedSince::Err => None,
148148
};
149149
Deprecation { since, note: note.map(|s| s.to_string()) }
150150
}

0 commit comments

Comments
 (0)