Keep track of #[stable] attribute even if version cannot be parsed

This commit is contained in:
David Tolnay 2023-10-23 23:06:52 -07:00
parent f2ae7b55ae
commit ddcb1833ff
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 15 additions and 7 deletions

View File

@ -158,6 +158,8 @@ pub enum Since {
Version(Version), Version(Version),
/// Stabilized in the upcoming version, whatever number that is. /// Stabilized in the upcoming version, whatever number that is.
Current, Current,
/// Failed to parse a stabilization version.
Err,
} }
impl StabilityLevel { impl StabilityLevel {
@ -381,22 +383,24 @@ 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(Since::Current) Since::Current
} else if let Some(version) = parse_version(since.as_str(), false) { } else if let Some(version) = parse_version(since.as_str(), false) {
Ok(Since::Version(version)) Since::Version(version)
} else { } else {
Err(sess.emit_err(session_diagnostics::InvalidSince { span: attr.span })) sess.emit_err(session_diagnostics::InvalidSince { span: attr.span });
Since::Err
} }
} else { } else {
Err(sess.emit_err(session_diagnostics::MissingSince { span: attr.span })) sess.emit_err(session_diagnostics::MissingSince { span: attr.span });
Since::Err
}; };
match (feature, since) { match feature {
(Ok(feature), Ok(since)) => { Ok(feature) => {
let level = StabilityLevel::Stable { since, allowed_through_unstable_modules: false }; let level = StabilityLevel::Stable { since, allowed_through_unstable_modules: false };
Some((feature, level)) Some((feature, level))
} }
(Err(ErrorGuaranteed { .. }), _) | (_, Err(ErrorGuaranteed { .. })) => None, Err(ErrorGuaranteed { .. }) => None,
} }
} }

View File

@ -260,6 +260,10 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
} }
} }
} }
Since::Err => {
// An error already reported. Assume the unparseable stabilization
// version is older than the deprecation version.
}
} }
} }