Skip to content

Commit

Permalink
Rename Since -> StableSince in preparation for a DeprecatedSince
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 30, 2023
1 parent 1dfb6b1 commit 1e5b2da
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 139,7 @@ pub enum StabilityLevel {
/// `#[stable]`
Stable {
/// Rust release which stabilized this feature.
since: Since,
since: StableSince,
/// Is this item allowed to be referred to on stable, despite being contained in unstable
/// modules?
allowed_through_unstable_modules: bool,
Expand All @@ -149,7 149,7 @@ pub enum StabilityLevel {
/// Rust release in which a feature is stabilized.
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
#[derive(HashStable_Generic)]
pub enum Since {
pub enum StableSince {
Version(RustcVersion),
/// Stabilized in the upcoming version, whatever number that is.
Current,
Expand Down Expand Up @@ -378,16 378,16 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit

let since = if let Some(since) = since {
if since.as_str() == VERSION_PLACEHOLDER {
Since::Current
StableSince::Current
} else if let Some(version) = parse_version(since) {
Since::Version(version)
StableSince::Version(version)
} else {
sess.emit_err(session_diagnostics::InvalidSince { span: attr.span });
Since::Err
StableSince::Err
}
} else {
sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
Since::Err
StableSince::Err
};

match feature {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 3,7 @@

use crate::errors;
use rustc_attr::{
self as attr, ConstStability, Since, Stability, StabilityLevel, Unstable, UnstableReason,
self as attr, ConstStability, Stability, StabilityLevel, StableSince, Unstable, UnstableReason,
VERSION_PLACEHOLDER,
};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
Expand Down Expand Up @@ -227,10 227,10 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
(&depr.as_ref().and_then(|(d, _)| d.since), &stab.level)
{
match stab_since {
Since::Current => {
StableSince::Current => {
self.tcx.sess.emit_err(errors::CannotStabilizeDeprecated { span, item_sp });
}
Since::Version(stab_since) => {
StableSince::Version(stab_since) => {
// Explicit version of iter::order::lt to handle parse errors properly
for (dep_v, stab_v) in iter::zip(
dep_since.as_str().split('.'),
Expand Down Expand Up @@ -260,7 260,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
}
}
}
Since::Err => {
StableSince::Err => {
// An error already reported. Assume the unparseable stabilization
// version is older than the deprecation version.
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 12,7 @@ use thin_vec::ThinVec;

use rustc_ast as ast;
use rustc_ast_pretty::pprust;
use rustc_attr::{ConstStability, Deprecation, Since, Stability, StabilityLevel};
use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel, StableSince};
use rustc_const_eval::const_eval::is_unstable_const_fn;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir as hir;
Expand Down Expand Up @@ -585,14 585,14 @@ impl Item {
})
}

pub(crate) fn stable_since(&self, tcx: TyCtxt<'_>) -> Option<Since> {
pub(crate) fn stable_since(&self, tcx: TyCtxt<'_>) -> Option<StableSince> {
match self.stability(tcx)?.level {
StabilityLevel::Stable { since, .. } => Some(since),
StabilityLevel::Unstable { .. } => None,
}
}

pub(crate) fn const_stable_since(&self, tcx: TyCtxt<'_>) -> Option<Since> {
pub(crate) fn const_stable_since(&self, tcx: TyCtxt<'_>) -> Option<StableSince> {
match self.const_stability(tcx)?.level {
StabilityLevel::Stable { since, .. } => Some(since),
StabilityLevel::Unstable { .. } => None,
Expand Down
22 changes: 11 additions & 11 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 48,7 @@ use std::str;
use std::string::ToString;

use askama::Template;
use rustc_attr::{ConstStability, Deprecation, Since, StabilityLevel};
use rustc_attr::{ConstStability, Deprecation, StabilityLevel, StableSince};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{DefId, DefIdSet};
Expand Down Expand Up @@ -912,10 912,10 @@ fn assoc_method(
/// consequence of the above rules.
fn render_stability_since_raw_with_extra(
w: &mut Buffer,
ver: Option<Since>,
ver: Option<StableSince>,
const_stability: Option<ConstStability>,
containing_ver: Option<Since>,
containing_const_ver: Option<Since>,
containing_ver: Option<StableSince>,
containing_const_ver: Option<StableSince>,
extra_class: &str,
) -> bool {
let stable_version = if ver != containing_ver && let Some(ver) = &ver {
Expand Down Expand Up @@ -977,21 977,21 @@ fn render_stability_since_raw_with_extra(
!stability.is_empty()
}

fn since_to_string(since: &Since) -> Option<String> {
fn since_to_string(since: &StableSince) -> Option<String> {
match since {
Since::Version(since) => Some(since.to_string()),
Since::Current => Some(RustcVersion::CURRENT.to_string()),
Since::Err => None,
StableSince::Version(since) => Some(since.to_string()),
StableSince::Current => Some(RustcVersion::CURRENT.to_string()),
StableSince::Err => None,
}
}

#[inline]
fn render_stability_since_raw(
w: &mut Buffer,
ver: Option<Since>,
ver: Option<StableSince>,
const_stability: Option<ConstStability>,
containing_ver: Option<Since>,
containing_const_ver: Option<Since>,
containing_ver: Option<StableSince>,
containing_const_ver: Option<StableSince>,
) -> bool {
render_stability_since_raw_with_extra(
w,
Expand Down
8 changes: 4 additions & 4 deletions src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 5,7 @@

use crate::msrvs::Msrv;
use hir::LangItem;
use rustc_attr::Since;
use rustc_attr::StableSince;
use rustc_const_eval::transform::check_consts::ConstCx;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
Expand Down Expand Up @@ -372,9 372,9 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: &Msrv) -> bool {
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.

let const_stab_rust_version = match since {
Since::Version(version) => version,
Since::Current => rustc_session::RustcVersion::CURRENT,
Since::Err => return false,
StableSince::Version(version) => version,
StableSince::Current => rustc_session::RustcVersion::CURRENT,
StableSince::Err => return false,
};

msrv.meets(RustcVersion::new(
Expand Down

0 comments on commit 1e5b2da

Please sign in to comment.