summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/middle/stability.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_middle/src/middle/stability.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_middle/src/middle/stability.rs')
-rw-r--r--compiler/rustc_middle/src/middle/stability.rs81
1 files changed, 24 insertions, 57 deletions
diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs
index 908ab8b61..f7a55fa95 100644
--- a/compiler/rustc_middle/src/middle/stability.rs
+++ b/compiler/rustc_middle/src/middle/stability.rs
@@ -5,7 +5,9 @@ pub use self::StabilityLevel::*;
use crate::ty::{self, TyCtxt};
use rustc_ast::NodeId;
-use rustc_attr::{self as attr, ConstStability, DefaultBodyStability, Deprecation, Stability};
+use rustc_attr::{
+ self as attr, ConstStability, DefaultBodyStability, DeprecatedSince, Deprecation, Stability,
+};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Applicability, Diagnostic};
use rustc_feature::GateIssue;
@@ -123,44 +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 {
- let is_since_rustc_version = depr.is_since_rustc_version;
- let since = depr.since.as_ref().map(Symbol::as_str);
-
- fn parse_version(ver: &str) -> Vec<u32> {
- // We ignore non-integer components of the version (e.g., "nightly").
- ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect()
- }
-
- if !is_since_rustc_version {
- // The `since` field doesn't have semantic purpose without `#![staged_api]`.
- return true;
- }
-
- if let Some(since) = since {
- if since == "TBD" {
- return false;
- }
-
- if let Some(rustc) = option_env!("CFG_RELEASE") {
- let since: Vec<u32> = parse_version(&since);
- let rustc: Vec<u32> = parse_version(rustc);
- // We simply treat invalid `since` attributes as relating to a previous
- // Rust version, thus always displaying the warning.
- if since.len() != 3 {
- return true;
- }
- return since <= rustc;
- }
- };
-
- // Assume deprecation is in effect if "since" field is missing
- // or if we can't determine the current Rust version.
- true
-}
-
pub fn deprecation_suggestion(
diag: &mut Diagnostic,
kind: &str,
@@ -183,7 +147,7 @@ fn deprecation_lint(is_in_effect: bool) -> &'static Lint {
fn deprecation_message(
is_in_effect: bool,
- since: Option<Symbol>,
+ since: DeprecatedSince,
note: Option<Symbol>,
kind: &str,
path: &str,
@@ -191,17 +155,18 @@ fn deprecation_message(
let message = if is_in_effect {
format!("use of deprecated {kind} `{path}`")
} else {
- let since = since.as_ref().map(Symbol::as_str);
-
- if since == Some("TBD") {
- format!("use of {kind} `{path}` that will be deprecated in a future Rust version")
- } else {
- format!(
- "use of {} `{}` that will be deprecated in future version {}",
- kind,
- path,
- since.unwrap()
- )
+ match since {
+ DeprecatedSince::RustcVersion(version) => format!(
+ "use of {kind} `{path}` that will be deprecated in future version {version}"
+ ),
+ DeprecatedSince::Future => {
+ format!("use of {kind} `{path}` that will be deprecated in a future Rust version")
+ }
+ DeprecatedSince::NonStandard(_)
+ | DeprecatedSince::Unspecified
+ | DeprecatedSince::Err => {
+ unreachable!("this deprecation is always in effect; {since:?}")
+ }
}
};
@@ -216,7 +181,7 @@ pub fn deprecation_message_and_lint(
kind: &str,
path: &str,
) -> (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_lint(is_in_effect),
@@ -384,11 +349,11 @@ impl<'tcx> TyCtxt<'tcx> {
// With #![staged_api], we want to emit down the whole
// hierarchy.
let depr_attr = &depr_entry.attr;
- if !skip || depr_attr.is_since_rustc_version {
+ if !skip || depr_attr.is_since_rustc_version() {
// 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.
- 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);
if self.lint_level_at_node(lint, id).0 != Level::Allow {
let def_path = with_no_trimmed_paths!(self.def_path_str(def_id));
@@ -448,14 +413,16 @@ impl<'tcx> TyCtxt<'tcx> {
debug!("stability: skipping span={:?} since it is internal", span);
return EvalResult::Allow;
}
- if self.features().active(feature) {
+ if self.features().declared(feature) {
return EvalResult::Allow;
}
// If this item was previously part of a now-stabilized feature which is still
// active (i.e. the user hasn't removed the attribute for the stabilized feature
// yet) then allow use of this item.
- if let Some(implied_by) = implied_by && self.features().active(implied_by) {
+ if let Some(implied_by) = implied_by
+ && self.features().declared(implied_by)
+ {
return EvalResult::Allow;
}
@@ -532,7 +499,7 @@ impl<'tcx> TyCtxt<'tcx> {
debug!("body stability: skipping span={:?} since it is internal", span);
return EvalResult::Allow;
}
- if self.features().active(feature) {
+ if self.features().declared(feature) {
return EvalResult::Allow;
}