rust/tests/ui/attributes
Josh Triplett 6c04e0a7ae Rewrite macro_rules! parser to not use the MBE engine itself
The `macro_rules!` parser was written to match the series of rules using
the macros-by-example (MBE) engine and a hand-written equivalent of the
left-hand side of a MBE macro. This was complex to read, difficult to
extend, and produced confusing error messages. Because it was using the
MBE engine, any parse failure would be reported as if some macro was
being applied to the `macro_rules!` invocation itself; for instance,
errors would talk about "macro invocation", "macro arguments", and
"macro call", when they were actually about the macro *definition*.

And in practice, the `macro_rules!` parser only used the MBE engine to
extract the left-hand side and right-hand side of each rule as a token
tree, and then parsed the rest using a separate parser.

Rewrite it to parse the series of rules using a simple loop, instead.
This makes it more extensible in the future, and improves error
messages. For instance, omitting a semicolon between rules will result
in "expected `;`" and "unexpected token", rather than the confusing "no
rules expected this token in macro call".

This work was greatly aided by pair programming with Vincenzo Palazzo
and Eric Holk.
2025-06-26 15:20:42 -07:00
..
auxiliary allow macro_use as first segment 2025-06-02 16:30:21 +08:00
export tests: {Meta,Pointee}Sized in non-minicore tests 2025-06-16 23:04:33 +00:00
inline Adjust tests/ui/attr-usage-inline.rs 2024-12-17 19:57:42 +08:00
main-removed-2 Update tests to use new proc-macro header 2024-11-27 07:18:25 -08:00
no_link Move some tests out of tests/ui 2025-05-03 17:22:52 +02:00
positions Move more tests/ui tests 2025-05-12 16:35:09 +02:00
unsafe Do not visit whole crate to compute lints_that_dont_need_to_run. 2025-04-04 12:37:38 +00:00
used Move more tests/ui tests 2025-05-12 16:35:09 +02:00
z-crate-attr Rollup merge of #138632 - clubby789:stabilize-cfg-boolean-lit, r=davidtwco,Urgau,traviscross 2025-04-17 06:25:15 +02:00
arg-error-issue-121425.rs fix spans of arguments in diagnostic 2024-03-03 10:48:40 +08:00
arg-error-issue-121425.stderr add #[align] attribute 2025-06-18 12:37:08 +02:00
assoc-expr.rs Overhaul token collection. 2024-08-16 09:07:55 +10:00
attr-bad-crate-attr.rs compiletest: Require //~ annotations even if error-pattern is specified 2025-04-03 11:08:55 +03:00
attr-bad-crate-attr.stderr compiletest: Require //~ annotations even if error-pattern is specified 2025-04-03 11:08:55 +03:00
attr-before-view-item.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
attr-before-view-item2.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
attr-eq-token-tree.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
attr-eq-token-tree.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
attr-mix-new.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
attr-shebang.rs Adjust tests/ui/attr-shebang.rs 2024-12-17 19:22:21 +08:00
attr_unknown_custom_attr.rs cleaned up some tests 2025-06-08 11:25:09 +05:00
attr_unknown_custom_attr.stderr cleaned up some tests 2025-06-08 11:25:09 +05:00
attrs-on-params.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
attrs-on-params.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
attrs-with-no-formal-in-generics-1.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
attrs-with-no-formal-in-generics-1.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
attrs-with-no-formal-in-generics-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
attrs-with-no-formal-in-generics-2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
attrs-with-no-formal-in-generics-3.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
attrs-with-no-formal-in-generics-3.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
check-builtin-attr-ice.rs Fix attribute printing in an error. 2025-04-17 09:50:52 +10:00
check-builtin-attr-ice.stderr Fix attribute printing in an error. 2025-04-17 09:50:52 +10:00
check-cfg_attr-ice.rs tests: add regression test to make sure cfg_attr isn't considered unhandled 2024-08-06 06:12:10 +00:00
check-cfg_attr-ice.stderr Reword "crate not found" resolve message 2025-01-24 01:19:50 +00:00
class-attributes-1.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
class-attributes-2.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
collapse-debuginfo-invalid.rs Implement #[define_opaque] attribute for functions. 2025-03-11 12:05:02 +00:00
collapse-debuginfo-invalid.stderr Implement #[define_opaque] attribute for functions. 2025-03-11 12:05:02 +00:00
const-stability-on-macro.rs Update since stability attributes in tests 2023-10-23 13:04:47 -07:00
const-stability-on-macro.stderr Update since stability attributes in tests 2023-10-23 13:04:47 -07:00
crate-name-attr-validation.rs cleaned up some tests 2025-06-08 01:14:05 +05:00
crate-name-empty.rs Add a test with an empty crate name. 2025-03-25 16:14:27 +11:00
crate-name-empty.stderr Add a test with an empty crate name. 2025-03-25 16:14:27 +11:00
crate-name-macro-call.rs Reject macro calls inside of #![crate_name] 2025-02-15 16:47:30 +01:00
crate-name-macro-call.stderr Reject macro calls inside of #![crate_name] 2025-02-15 16:47:30 +01:00
crate-name-mismatch.rs cleaned up some tests 2025-06-08 11:25:09 +05:00
crate-name-mismatch.stderr cleaned up some tests 2025-06-08 11:25:09 +05:00
crate-type-delimited.rs Move #![crate_type] UI tests into attributes directory 2025-02-15 03:41:07 +01:00
crate-type-delimited.stderr Move #![crate_type] UI tests into attributes directory 2025-02-15 03:41:07 +01:00
crate-type-empty.rs Move #![crate_type] UI tests into attributes directory 2025-02-15 03:41:07 +01:00
crate-type-empty.stderr Move #![crate_type] UI tests into attributes directory 2025-02-15 03:41:07 +01:00
crate-type-macro-call.rs Move #![crate_type] UI tests into attributes directory 2025-02-15 03:41:07 +01:00
crate-type-macro-call.stderr Move #![crate_type] UI tests into attributes directory 2025-02-15 03:41:07 +01:00
crate-type-macro-empty.rs Rewrite macro_rules! parser to not use the MBE engine itself 2025-06-26 15:20:42 -07:00
crate-type-macro-empty.stderr Rewrite macro_rules! parser to not use the MBE engine itself 2025-06-26 15:20:42 -07:00
crate-type-macro-not-crate.rs fix #137589 2025-02-25 18:17:32 +01:00
crate-type-macro-not-crate.stderr fix #137589 2025-02-25 18:17:32 +01:00
crate-type-macro-not-found.rs fix #137589 2025-02-25 18:17:32 +01:00
crate-type-macro-not-found.stderr fix #137589 2025-02-25 18:17:32 +01:00
custom_attr_multisegment_error.rs cleaned up some tests 2025-06-08 11:25:09 +05:00
custom_attr_multisegment_error.stderr cleaned up some tests 2025-06-08 11:25:09 +05:00
decl_macro_ty_in_attr_macro.rs add test to reproduce #137662 (using ty decl macro fragment in an attr) and fix it 2025-02-28 09:43:46 +01:00
doc-attr.rs Update ui tests 2024-02-29 14:43:43 +01:00
doc-attr.stderr Update ui tests 2024-02-29 14:43:43 +01:00
doc-test-literal.rs Update ui tests 2024-02-29 14:43:43 +01:00
doc-test-literal.stderr Update ui tests 2024-02-29 14:43:43 +01:00
dont-dup-expr-attrs.rs Fix problem causing rusqlite compilation to OOM. 2025-04-02 06:21:18 +11:00
dump-preds.rs Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
dump-preds.stderr trait_sel: skip elaboration of sizedness supertrait 2025-06-16 23:04:36 +00:00
dump_def_parents.rs Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
dump_def_parents.stderr Filter empty lines, comments and delimiters from previous to last multiline span rendering 2024-12-12 23:36:27 +00:00
duplicated-attributes.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
duplicated-attributes.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
expected-word.rs expected word diagnostic test 2025-06-20 15:06:29 +02:00
expected-word.stderr expected word diagnostic test 2025-06-20 15:06:29 +02:00
extented-attribute-macro-error.rs Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
extented-attribute-macro-error.stderr Do not suggest using -Zmacro-backtrace for builtin macros 2025-03-14 19:50:03 +00:00
field-attributes-vis-unresolved.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
field-attributes-vis-unresolved.stderr Reword "crate not found" resolve message 2025-01-24 01:19:50 +00:00
illegal-macro-use.rs allow macro_use as first segment 2025-06-02 16:30:21 +08:00
illegal-macro-use.stderr allow macro_use as first segment 2025-06-02 16:30:21 +08:00
inner-attr-metavar.rs Fix a problem with metavars and inner attributes. 2025-04-02 06:21:18 +11:00
invalid-repr.rs add #[align] attribute 2025-06-18 12:37:08 +02:00
invalid-repr.stderr add #[align] attribute 2025-06-18 12:37:08 +02:00
invalid-reprs.rs check if merged attributes list is empty 2025-04-05 06:09:14 +09:00
invalid-reprs.stderr check if merged attributes list is empty 2025-04-05 06:09:14 +09:00
invalid_macro_export_argument.deny.stderr Replace infallible name_or_empty methods with fallible name methods. 2025-04-17 09:50:52 +10:00
invalid_macro_export_argument.rs Replace infallible name_or_empty methods with fallible name methods. 2025-04-17 09:50:52 +10:00
issue-40962.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-90873.rs UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
issue-90873.stderr Make parse error suggestions verbose and fix spans 2024-07-12 03:02:57 +00:00
issue-100631.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-100631.stderr Fix test output expectations 2025-02-24 14:31:19 +01:00
issue-105594-invalid-attr-validation.rs remove #[cmse_nonsecure_entry] 2024-09-21 13:05:21 +02:00
issue-105594-invalid-attr-validation.stderr remove #[cmse_nonsecure_entry] 2024-09-21 13:05:21 +02:00
issue-115264-expr-field.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
issue-115264-pat-field.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
item-attributes.rs Remove libc from rust_get_test_int uses 2024-04-17 09:18:14 -04:00
key-value-expansion-on-mac.rs Improve an error involving attribute values. 2023-12-12 15:54:25 +11:00
key-value-expansion-on-mac.stderr Improve an error involving attribute values. 2023-12-12 15:54:25 +11:00
key-value-expansion-scope-pass.rs resolve: Implement a lint for out-of-scope use of macro_rules 2024-06-24 17:12:08 +03:00
key-value-expansion-scope.rs Specify scope in out_of_scope_macro_calls lint 2025-02-19 18:29:00 +00:00
key-value-expansion-scope.stderr Reword message 2025-02-20 17:55:31 +00:00
key-value-expansion.rs Update tests. 2025-01-07 16:04:14 +01:00
key-value-expansion.stderr Improve an error involving attribute values. 2023-12-12 15:54:25 +11:00
key-value-non-ascii.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
key-value-non-ascii.stderr Show diff suggestion format on verbose replacement 2025-02-10 20:21:39 +00:00
linkage.rs Emit an error for invalid use of the linkage attribute 2024-08-17 15:03:20 +09:00
linkage.stderr Emit an error for invalid use of the linkage attribute 2024-08-17 15:03:20 +09:00
lint_on_root.rs fix 142891 2025-06-23 12:20:02 +02:00
lint_on_root.stderr fix 142891 2025-06-23 12:20:02 +02:00
log-backtrace.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
macro_export_on_decl_macro.rs check_attrs: Warn when #[macro_export] is used on macros 2.0 2023-08-07 21:14:28 +02:00
macro_export_on_decl_macro.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
main-removed-1.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
main-removed-1.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
malformed-fn-align.rs correct template for #[align] 2025-06-19 13:58:23 +02:00
malformed-fn-align.stderr correct template for #[align] 2025-06-19 13:58:23 +02:00
malformed-must_use.rs Port #[must_use] to new attribute parsing infrastructure 2025-06-22 14:51:58 +02:00
malformed-must_use.stderr Port #[must_use] to new attribute parsing infrastructure 2025-06-22 14:51:58 +02:00
may_dangle.rs Check that #[may_dangle] is properly applied 2024-08-18 20:32:00 +03:00
may_dangle.stderr Check that #[may_dangle] is properly applied 2024-08-18 20:32:00 +03:00
method-attributes.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
mixed_export_name_and_no_mangle.fixed Fix test output expectations 2025-02-24 14:31:19 +01:00
mixed_export_name_and_no_mangle.rs Fix test output expectations 2025-02-24 14:31:19 +01:00
mixed_export_name_and_no_mangle.stderr Fix test output expectations 2025-02-24 14:31:19 +01:00
multiple-invalid.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
multiple-invalid.stderr fix bugs in inline/force_inline and diagnostics of all attr parsers 2025-06-17 23:19:31 +02:00
no-mangle-closure.rs Skip no_mangle if the item has no name. 2023-03-28 18:05:12 +00:00
no-mangle-closure.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
no-sanitize.rs Replace infallible name_or_empty methods with fallible name methods. 2025-04-17 09:50:52 +10:00
no-sanitize.stderr Replace infallible name_or_empty methods with fallible name methods. 2025-04-17 09:50:52 +10:00
nonterminal-expansion.rs Remove NtExpr and NtLiteral. 2025-04-02 06:20:35 +11:00
nonterminal-expansion.stderr Remove NtExpr and NtLiteral. 2025-04-02 06:20:35 +11:00
obsolete-attr.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
obsolete-attr.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
optimize.rs misapplied optimize attribute throws a compilation error (#128488) 2024-10-20 08:34:15 -06:00
optimize.stderr misapplied optimize attribute throws a compilation error (#128488) 2024-10-20 08:34:15 -06:00
outer-mod-attr-applies-only-to-first.rs improves outer mod attribute test 2025-03-15 10:52:07 -06:00
repr-align-in-trait-issue-132391.rs Fix test output expectations 2025-02-24 14:31:19 +01:00
repr-align-in-trait-issue-132391.stderr Fix test output expectations 2025-02-24 14:31:19 +01:00
rustc_confusables.rs use consistent attr errors in all attribute parsers 2025-06-17 23:19:31 +02:00
rustc_confusables.stderr make error codes reflect reality better 2025-06-17 23:22:51 +02:00
rustc_confusables_std_cases.rs Add get_line confusable to Stdin::read_line() 2024-10-02 23:19:26 -05:00
rustc_confusables_std_cases.stderr Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
rustc_pub_transparent.rs New #[rustc_pub_transparent] attribute 2024-08-24 23:05:37 +03:00
rustc_pub_transparent.stderr New #[rustc_pub_transparent] attribute 2024-08-24 23:05:37 +03:00
rustc_skip_during_method_dispatch.rs Port #[rustc_skip_during_method_dispatch] to the new attribute system 2025-06-23 22:48:20 +03:00
rustc_skip_during_method_dispatch.stderr Port #[rustc_skip_during_method_dispatch] to the new attribute system 2025-06-23 22:48:20 +03:00
statement-attribute-validation.rs Add regression test for #117058 2023-10-24 08:21:52 +00:00
statement-attribute-validation.stderr Add regression test for #117058 2023-10-24 08:21:52 +00:00
suffixed-literal-meta.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
suffixed-literal-meta.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
tool_attributes.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
unknown-attr.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
unknown-attr.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
unnamed-field-attributes-dup.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
unnamed-field-attributes-vis.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
unnamed-field-attributes.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
unrestricted-attribute-tokens.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
unused-item-in-attr.rs Improve an error involving attribute values. 2023-12-12 15:54:25 +11:00
unused-item-in-attr.stderr Improve an error involving attribute values. 2023-12-12 15:54:25 +11:00
use-doc-alias-name.rs collect doc alias as tips during resolution 2025-05-21 00:47:36 +08:00
use-doc-alias-name.stderr collect doc alias as tips during resolution 2025-05-21 00:47:36 +08:00
use-extern-crate-named-macro-use.rs allow macro_use as first segment 2025-06-02 16:30:21 +08:00
used_with_archive.rs Make #[used] work when linking with ld64 2025-02-24 04:04:59 +01:00
used_with_archive.run.stdout Make #[used] work when linking with ld64 2025-02-24 04:04:59 +01:00
used_with_arg.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
used_with_arg.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
used_with_arg_no_mangle.rs [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
used_with_multi_args.rs UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
used_with_multi_args.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
validation-on-associated-items-issue-121537.rs fix attribute validation on associated items in traits 2024-02-24 08:14:38 -05:00
validation-on-associated-items-issue-121537.stderr fix attribute validation on associated items in traits 2024-02-24 08:14:38 -05:00
variant-attributes.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00