From ddcb1833ff0d0c4d6bf26163f64e4ad1617e65ff Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 23 Oct 2023 23:06:52 -0700 Subject: [PATCH] Keep track of #[stable] attribute even if version cannot be parsed --- compiler/rustc_attr/src/builtin.rs | 18 +++++++++++------- compiler/rustc_passes/src/stability.rs | 4 ++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index d01eae383a4..7081e285d68 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -158,6 +158,8 @@ pub enum Since { Version(Version), /// Stabilized in the upcoming version, whatever number that is. Current, + /// Failed to parse a stabilization version. + Err, } impl StabilityLevel { @@ -381,22 +383,24 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit let since = if let Some(since) = since { if since.as_str() == VERSION_PLACEHOLDER { - Ok(Since::Current) + Since::Current } else if let Some(version) = parse_version(since.as_str(), false) { - Ok(Since::Version(version)) + Since::Version(version) } else { - Err(sess.emit_err(session_diagnostics::InvalidSince { span: attr.span })) + sess.emit_err(session_diagnostics::InvalidSince { span: attr.span }); + Since::Err } } 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) { - (Ok(feature), Ok(since)) => { + match feature { + Ok(feature) => { let level = StabilityLevel::Stable { since, allowed_through_unstable_modules: false }; Some((feature, level)) } - (Err(ErrorGuaranteed { .. }), _) | (_, Err(ErrorGuaranteed { .. })) => None, + Err(ErrorGuaranteed { .. }) => None, } } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index d19df83162c..41a240fa880 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -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. + } } }