Skip to content

Commit bdede1c

Browse files
authored
Rollup merge of #144358 - JonathanBrouwer:fix-stability-malformed, r=oli-obk
Stop using the old `validate_attr` logic for stability attributes I think this was accidentally missed when implementing the stability attributes? r? ```@oli-obk``` cc ```@jdonszelmann```
2 parents 7282814 + af06bb9 commit bdede1c

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,15 @@ impl<S: Stage> AttributeParser<S> for StabilityParser {
7474
template!(NameValueStr: "deprecation message"),
7575
|this, cx, args| {
7676
reject_outside_std!(cx);
77-
this.allowed_through_unstable_modules =
78-
args.name_value().and_then(|i| i.value_as_str())
77+
let Some(nv) = args.name_value() else {
78+
cx.expected_name_value(cx.attr_span, None);
79+
return;
80+
};
81+
let Some(value_str) = nv.value_as_str() else {
82+
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
83+
return;
84+
};
85+
this.allowed_through_unstable_modules = Some(value_str);
7986
},
8087
),
8188
];
@@ -247,7 +254,12 @@ pub(crate) fn parse_stability<S: Stage>(
247254
let mut feature = None;
248255
let mut since = None;
249256

250-
for param in args.list()?.mixed() {
257+
let ArgParser::List(list) = args else {
258+
cx.expected_list(cx.attr_span);
259+
return None;
260+
};
261+
262+
for param in list.mixed() {
251263
let param_span = param.span();
252264
let Some(param) = param.meta_item() else {
253265
cx.emit_err(session_diagnostics::UnsupportedLiteral {
@@ -322,7 +334,13 @@ pub(crate) fn parse_unstability<S: Stage>(
322334
let mut is_soft = false;
323335
let mut implied_by = None;
324336
let mut old_name = None;
325-
for param in args.list()?.mixed() {
337+
338+
let ArgParser::List(list) = args else {
339+
cx.expected_list(cx.attr_span);
340+
return None;
341+
};
342+
343+
for param in list.mixed() {
326344
let Some(param) = param.meta_item() else {
327345
cx.emit_err(session_diagnostics::UnsupportedLiteral {
328346
span: param.span(),

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ pub fn check_builtin_meta_item(
285285
| sym::rustc_do_not_implement_via_object
286286
| sym::rustc_coinductive
287287
| sym::const_trait
288+
| sym::stable
289+
| sym::unstable
290+
| sym::rustc_allowed_through_unstable_modules
288291
| sym::rustc_specialization_trait
289292
| sym::rustc_unsafe_specialization_marker
290293
| sym::rustc_allow_incoherent_impl

tests/ui/stability-attribute/stability-attribute-sanity-4.stderr

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
error: malformed `unstable` attribute input
1+
error[E0539]: malformed `unstable` attribute input
22
--> $DIR/stability-attribute-sanity-4.rs:8:5
33
|
44
LL | #[unstable]
5-
| ^^^^^^^^^^^ help: must be of the form: `#[unstable(feature = "name", reason = "...", issue = "N")]`
5+
| ^^^^^^^^^^^
6+
| |
7+
| expected this to be a list
8+
| help: must be of the form: `#[unstable(feature = "name", reason = "...", issue = "N")]`
69

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

13-
error: malformed `stable` attribute input
19+
error[E0539]: malformed `stable` attribute input
1420
--> $DIR/stability-attribute-sanity-4.rs:14:5
1521
|
1622
LL | #[stable]
17-
| ^^^^^^^^^ help: must be of the form: `#[stable(feature = "name", since = "version")]`
23+
| ^^^^^^^^^
24+
| |
25+
| expected this to be a list
26+
| help: must be of the form: `#[stable(feature = "name", since = "version")]`
1827

19-
error: malformed `stable` attribute input
28+
error[E0539]: malformed `stable` attribute input
2029
--> $DIR/stability-attribute-sanity-4.rs:17:5
2130
|
2231
LL | #[stable = "a"]
23-
| ^^^^^^^^^^^^^^^ help: must be of the form: `#[stable(feature = "name", since = "version")]`
32+
| ^^^^^^^^^^^^^^^
33+
| |
34+
| expected this to be a list
35+
| help: must be of the form: `#[stable(feature = "name", since = "version")]`
2436

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

4355
error: aborting due to 7 previous errors
4456

45-
Some errors have detailed explanations: E0542, E0543.
46-
For more information about an error, try `rustc --explain E0542`.
57+
Some errors have detailed explanations: E0539, E0542, E0543.
58+
For more information about an error, try `rustc --explain E0539`.

0 commit comments

Comments
 (0)