mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Store 'since' attribute as parsed Version
This commit is contained in:
parent
151256bd4b
commit
f2ae7b55ae
@ -144,13 +144,22 @@ pub enum StabilityLevel {
|
|||||||
/// `#[stable]`
|
/// `#[stable]`
|
||||||
Stable {
|
Stable {
|
||||||
/// Rust release which stabilized this feature.
|
/// Rust release which stabilized this feature.
|
||||||
since: Symbol,
|
since: Since,
|
||||||
/// Is this item allowed to be referred to on stable, despite being contained in unstable
|
/// Is this item allowed to be referred to on stable, despite being contained in unstable
|
||||||
/// modules?
|
/// modules?
|
||||||
allowed_through_unstable_modules: bool,
|
allowed_through_unstable_modules: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Rust release in which a feature is stabilized.
|
||||||
|
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
|
||||||
|
#[derive(HashStable_Generic)]
|
||||||
|
pub enum Since {
|
||||||
|
Version(Version),
|
||||||
|
/// Stabilized in the upcoming version, whatever number that is.
|
||||||
|
Current,
|
||||||
|
}
|
||||||
|
|
||||||
impl StabilityLevel {
|
impl StabilityLevel {
|
||||||
pub fn is_unstable(&self) -> bool {
|
pub fn is_unstable(&self) -> bool {
|
||||||
matches!(self, StabilityLevel::Unstable { .. })
|
matches!(self, StabilityLevel::Unstable { .. })
|
||||||
@ -372,9 +381,9 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
|
|||||||
|
|
||||||
let since = if let Some(since) = since {
|
let since = if let Some(since) = since {
|
||||||
if since.as_str() == VERSION_PLACEHOLDER {
|
if since.as_str() == VERSION_PLACEHOLDER {
|
||||||
Ok(rust_version_symbol())
|
Ok(Since::Current)
|
||||||
} else if parse_version(since.as_str(), false).is_some() {
|
} else if let Some(version) = parse_version(since.as_str(), false) {
|
||||||
Ok(since)
|
Ok(Since::Version(version))
|
||||||
} else {
|
} else {
|
||||||
Err(sess.emit_err(session_diagnostics::InvalidSince { span: attr.span }))
|
Err(sess.emit_err(session_diagnostics::InvalidSince { span: attr.span }))
|
||||||
}
|
}
|
||||||
@ -556,11 +565,12 @@ fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &ParseSess, features: &F
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
struct Version {
|
#[derive(HashStable_Generic)]
|
||||||
major: u16,
|
pub struct Version {
|
||||||
minor: u16,
|
pub major: u16,
|
||||||
patch: u16,
|
pub minor: u16,
|
||||||
|
pub patch: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_version(s: &str, allow_appendix: bool) -> Option<Version> {
|
fn parse_version(s: &str, allow_appendix: bool) -> Option<Version> {
|
||||||
|
@ -402,11 +402,6 @@ passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]
|
|||||||
|
|
||||||
passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments
|
passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments
|
||||||
|
|
||||||
passes_invalid_stability =
|
|
||||||
invalid stability version found
|
|
||||||
.label = invalid stability version
|
|
||||||
.item = the stability attribute annotates this item
|
|
||||||
|
|
||||||
passes_lang_item_fn_with_target_feature =
|
passes_lang_item_fn_with_target_feature =
|
||||||
`{$name}` language item function is not allowed to have `#[target_feature]`
|
`{$name}` language item function is not allowed to have `#[target_feature]`
|
||||||
.label = `{$name}` language item function is not allowed to have `#[target_feature]`
|
.label = `{$name}` language item function is not allowed to have `#[target_feature]`
|
||||||
|
@ -1504,16 +1504,6 @@ pub struct UselessStability {
|
|||||||
pub item_sp: Span,
|
pub item_sp: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
|
||||||
#[diag(passes_invalid_stability)]
|
|
||||||
pub struct InvalidStability {
|
|
||||||
#[primary_span]
|
|
||||||
#[label]
|
|
||||||
pub span: Span,
|
|
||||||
#[label(passes_item)]
|
|
||||||
pub item_sp: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(passes_cannot_stabilize_deprecated)]
|
#[diag(passes_cannot_stabilize_deprecated)]
|
||||||
pub struct CannotStabilizeDeprecated {
|
pub struct CannotStabilizeDeprecated {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
use rustc_attr::{
|
use rustc_attr::{
|
||||||
self as attr, rust_version_symbol, ConstStability, Stability, StabilityLevel, Unstable,
|
self as attr, rust_version_symbol, ConstStability, Since, Stability, StabilityLevel, Unstable,
|
||||||
UnstableReason, VERSION_PLACEHOLDER,
|
UnstableReason, VERSION_PLACEHOLDER,
|
||||||
};
|
};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||||
@ -226,37 +226,39 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
|||||||
if let (&Some(dep_since), &attr::Stable { since: stab_since, .. }) =
|
if let (&Some(dep_since), &attr::Stable { since: stab_since, .. }) =
|
||||||
(&depr.as_ref().and_then(|(d, _)| d.since), &stab.level)
|
(&depr.as_ref().and_then(|(d, _)| d.since), &stab.level)
|
||||||
{
|
{
|
||||||
// Explicit version of iter::order::lt to handle parse errors properly
|
match stab_since {
|
||||||
for (dep_v, stab_v) in
|
Since::Current => {
|
||||||
iter::zip(dep_since.as_str().split('.'), stab_since.as_str().split('.'))
|
self.tcx.sess.emit_err(errors::CannotStabilizeDeprecated { span, item_sp });
|
||||||
{
|
}
|
||||||
match stab_v.parse::<u64>() {
|
Since::Version(stab_since) => {
|
||||||
Err(_) => {
|
// Explicit version of iter::order::lt to handle parse errors properly
|
||||||
self.tcx.sess.emit_err(errors::InvalidStability { span, item_sp });
|
for (dep_v, stab_v) in iter::zip(
|
||||||
break;
|
dep_since.as_str().split('.'),
|
||||||
}
|
[stab_since.major, stab_since.minor, stab_since.patch],
|
||||||
Ok(stab_vp) => match dep_v.parse::<u64>() {
|
) {
|
||||||
Ok(dep_vp) => match dep_vp.cmp(&stab_vp) {
|
match dep_v.parse::<u64>() {
|
||||||
Ordering::Less => {
|
Ok(dep_vp) => match dep_vp.cmp(&u64::from(stab_v)) {
|
||||||
self.tcx.sess.emit_err(errors::CannotStabilizeDeprecated {
|
Ordering::Less => {
|
||||||
span,
|
self.tcx.sess.emit_err(errors::CannotStabilizeDeprecated {
|
||||||
item_sp,
|
span,
|
||||||
});
|
item_sp,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Ordering::Equal => continue,
|
||||||
|
Ordering::Greater => break,
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
if dep_v != "TBD" {
|
||||||
|
self.tcx.sess.emit_err(errors::InvalidDeprecationVersion {
|
||||||
|
span,
|
||||||
|
item_sp,
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ordering::Equal => continue,
|
|
||||||
Ordering::Greater => break,
|
|
||||||
},
|
|
||||||
Err(_) => {
|
|
||||||
if dep_v != "TBD" {
|
|
||||||
self.tcx.sess.emit_err(errors::InvalidDeprecationVersion {
|
|
||||||
span,
|
|
||||||
item_sp,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user