Skip to content

Commit 8d9a24b

Browse files
Properly check arguments of #[rustc_must_implement_one_of]
1 parent 76bc7af commit 8d9a24b

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcMustImplementOneOfParser {
4949

5050
let mut errored = false;
5151
for argument in inputs {
52-
let Some(meta) = argument.meta_item() else {
52+
let Some(meta) = argument.meta_item_no_args() else {
5353
cx.adcx().expected_identifier(argument.span());
5454
return None;
5555
};

tests/ui/attributes/args-checked.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,12 @@ const fn g() {}
4343
//~^ ERROR malformed
4444
#[used(always(x, y, z))]
4545
//~^ ERROR malformed
46-
static H: u64 = 5;
46+
static H: u64 = 5;
47+
48+
#[rustc_must_implement_one_of(eq = 5, neq)]
49+
//~^ ERROR malformed
50+
#[rustc_must_implement_one_of(eq(x, y, z), neq)]
51+
//~^ ERROR malformed
52+
trait T {
53+
54+
}

tests/ui/attributes/args-checked.stderr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,24 @@ LL - #[used(always(x, y, z))]
188188
LL + #[used]
189189
|
190190

191+
error[E0539]: malformed `rustc_must_implement_one_of` attribute input
192+
--> $DIR/args-checked.rs:48:1
193+
|
194+
LL | #[rustc_must_implement_one_of(eq = 5, neq)]
195+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------^^^^^^^
196+
| | |
197+
| | expected a valid identifier here
198+
| help: must be of the form: `#[rustc_must_implement_one_of(function1, function2, ...)]`
199+
200+
error[E0539]: malformed `rustc_must_implement_one_of` attribute input
201+
--> $DIR/args-checked.rs:50:1
202+
|
203+
LL | #[rustc_must_implement_one_of(eq(x, y, z), neq)]
204+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^^^^
205+
| | |
206+
| | expected a valid identifier here
207+
| help: must be of the form: `#[rustc_must_implement_one_of(function1, function2, ...)]`
208+
191209
error: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]`
192210
--> $DIR/args-checked.rs:26:1
193211
|
@@ -207,7 +225,7 @@ LL | #[macro_export(local_inner_macros(x, y, z))]
207225
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
208226
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
209227

210-
error: aborting due to 14 previous errors
228+
error: aborting due to 16 previous errors
211229

212230
For more information about this error, try `rustc --explain E0539`.
213231
Future incompatibility report: Future breakage diagnostic:

0 commit comments

Comments
 (0)