Validate since
value in stable attribute
This commit is contained in:
parent
01b909174b
commit
82ed3f5e8b
3 changed files with 21 additions and 8 deletions
|
@ -58,6 +58,9 @@ attr_invalid_repr_hint_no_paren =
|
||||||
attr_invalid_repr_hint_no_value =
|
attr_invalid_repr_hint_no_value =
|
||||||
invalid representation hint: `{$name}` does not take a value
|
invalid representation hint: `{$name}` does not take a value
|
||||||
|
|
||||||
|
attr_invalid_since =
|
||||||
|
'since' must be a Rust version number, such as "1.31.0"
|
||||||
|
|
||||||
attr_missing_feature =
|
attr_missing_feature =
|
||||||
missing 'feature'
|
missing 'feature'
|
||||||
|
|
||||||
|
|
|
@ -362,12 +362,6 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(s) = since
|
|
||||||
&& s.as_str() == VERSION_PLACEHOLDER
|
|
||||||
{
|
|
||||||
since = Some(rust_version_symbol());
|
|
||||||
}
|
|
||||||
|
|
||||||
let feature = match feature {
|
let feature = match feature {
|
||||||
Some(feature) if rustc_lexer::is_ident(feature.as_str()) => Ok(feature),
|
Some(feature) if rustc_lexer::is_ident(feature.as_str()) => Ok(feature),
|
||||||
Some(_bad_feature) => {
|
Some(_bad_feature) => {
|
||||||
|
@ -376,8 +370,17 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
|
||||||
None => Err(sess.emit_err(session_diagnostics::MissingFeature { span: attr.span })),
|
None => Err(sess.emit_err(session_diagnostics::MissingFeature { span: attr.span })),
|
||||||
};
|
};
|
||||||
|
|
||||||
let since =
|
let since = if let Some(since) = since {
|
||||||
since.ok_or_else(|| sess.emit_err(session_diagnostics::MissingSince { span: attr.span }));
|
if since.as_str() == VERSION_PLACEHOLDER {
|
||||||
|
Ok(rust_version_symbol())
|
||||||
|
} else if parse_version(since.as_str(), false).is_some() {
|
||||||
|
Ok(since)
|
||||||
|
} else {
|
||||||
|
Err(sess.emit_err(session_diagnostics::InvalidSince { span: attr.span }))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(sess.emit_err(session_diagnostics::MissingSince { span: attr.span }))
|
||||||
|
};
|
||||||
|
|
||||||
match (feature, since) {
|
match (feature, since) {
|
||||||
(Ok(feature), Ok(since)) => {
|
(Ok(feature), Ok(since)) => {
|
||||||
|
|
|
@ -370,6 +370,13 @@ pub(crate) struct ExpectsFeatures {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(attr_invalid_since)]
|
||||||
|
pub(crate) struct InvalidSince {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(attr_soft_no_args)]
|
#[diag(attr_soft_no_args)]
|
||||||
pub(crate) struct SoftNoArgs {
|
pub(crate) struct SoftNoArgs {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue