Skip to content

Stop using the old validate_attr logic for stability attributes #144358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions compiler/rustc_attr_parsing/src/attributes/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,15 @@ impl<S: Stage> AttributeParser<S> for StabilityParser {
template!(NameValueStr: "deprecation message"),
|this, cx, args| {
reject_outside_std!(cx);
this.allowed_through_unstable_modules =
args.name_value().and_then(|i| i.value_as_str())
let Some(nv) = args.name_value() else {
cx.expected_name_value(cx.attr_span, None);
return;
};
let Some(value_str) = nv.value_as_str() else {
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
return;
};
this.allowed_through_unstable_modules = Some(value_str);
},
),
];
Expand Down Expand Up @@ -247,7 +254,12 @@ pub(crate) fn parse_stability<S: Stage>(
let mut feature = None;
let mut since = None;

for param in args.list()?.mixed() {
let ArgParser::List(list) = args else {
cx.expected_list(cx.attr_span);
return None;
};

for param in list.mixed() {
let param_span = param.span();
let Some(param) = param.meta_item() else {
cx.emit_err(session_diagnostics::UnsupportedLiteral {
Expand Down Expand Up @@ -322,7 +334,13 @@ pub(crate) fn parse_unstability<S: Stage>(
let mut is_soft = false;
let mut implied_by = None;
let mut old_name = None;
for param in args.list()?.mixed() {

let ArgParser::List(list) = args else {
cx.expected_list(cx.attr_span);
return None;
};

for param in list.mixed() {
let Some(param) = param.meta_item() else {
cx.emit_err(session_diagnostics::UnsupportedLiteral {
span: param.span(),
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_parse/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ pub fn check_builtin_meta_item(
| sym::rustc_do_not_implement_via_object
| sym::rustc_coinductive
| sym::const_trait
| sym::stable
| sym::unstable
| sym::rustc_allowed_through_unstable_modules
| sym::rustc_specialization_trait
| sym::rustc_unsafe_specialization_marker
| sym::rustc_allow_incoherent_impl
Expand Down
32 changes: 22 additions & 10 deletions tests/ui/stability-attribute/stability-attribute-sanity-4.stderr
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
error: malformed `unstable` attribute input
error[E0539]: malformed `unstable` attribute input
--> $DIR/stability-attribute-sanity-4.rs:8:5
|
LL | #[unstable]
| ^^^^^^^^^^^ help: must be of the form: `#[unstable(feature = "name", reason = "...", issue = "N")]`
| ^^^^^^^^^^^
| |
| expected this to be a list
| help: must be of the form: `#[unstable(feature = "name", reason = "...", issue = "N")]`

error: malformed `unstable` attribute input
error[E0539]: malformed `unstable` attribute input
--> $DIR/stability-attribute-sanity-4.rs:11:5
|
LL | #[unstable = "b"]
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[unstable(feature = "name", reason = "...", issue = "N")]`
| ^^^^^^^^^^^^^^^^^
| |
| expected this to be a list
| help: must be of the form: `#[unstable(feature = "name", reason = "...", issue = "N")]`

error: malformed `stable` attribute input
error[E0539]: malformed `stable` attribute input
--> $DIR/stability-attribute-sanity-4.rs:14:5
|
LL | #[stable]
| ^^^^^^^^^ help: must be of the form: `#[stable(feature = "name", since = "version")]`
| ^^^^^^^^^
| |
| expected this to be a list
| help: must be of the form: `#[stable(feature = "name", since = "version")]`

error: malformed `stable` attribute input
error[E0539]: malformed `stable` attribute input
--> $DIR/stability-attribute-sanity-4.rs:17:5
|
LL | #[stable = "a"]
| ^^^^^^^^^^^^^^^ help: must be of the form: `#[stable(feature = "name", since = "version")]`
| ^^^^^^^^^^^^^^^
| |
| expected this to be a list
| help: must be of the form: `#[stable(feature = "name", since = "version")]`

error[E0542]: missing 'since'
--> $DIR/stability-attribute-sanity-4.rs:21:5
Expand All @@ -42,5 +54,5 @@ LL | #[deprecated = "a"]

error: aborting due to 7 previous errors

Some errors have detailed explanations: E0542, E0543.
For more information about an error, try `rustc --explain E0542`.
Some errors have detailed explanations: E0539, E0542, E0543.
For more information about an error, try `rustc --explain E0539`.
Loading