Files
rust/tests/ui/macros
Jonathan Brouwer b9f8e25f6e Rollup merge of #146961 - Jules-Bertholet:expr-cfg, r=JonathanBrouwer
Allow passing `expr` metavariable as `cfg` predicate

This PR allows expanding `expr` metavariables inside the configuration predicates of `cfg` and `cfg_attr` invocations.
For example, the following code will now compile:

```rust
macro_rules! mac {
    ($e:expr) => {
        #[cfg_attr($e, inline)]
        #[cfg($e)]
        fn func() {}

        #[cfg(not($e))]
        fn func() {
            panic!()
        }
    }
}

mac!(any(unix, feature = "foo"));
```

There is currently no `macro_rules` fragment specifier that can represent all valid `cfg` predicates. `meta` comes closest, but excludes `true` and `false`. By fixing that, this change makes it easier to write declarative macros that parse `cfg` or `cfg_attr` invocations, for example https://github.com/rust-lang/rust/pull/146281/.

@rustbot label T-lang needs-fcp A-attributes A-cfg A-macros
2026-03-21 00:42:47 +01:00
..
2025-11-27 14:13:58 -05:00
2025-11-27 14:13:58 -05:00
2026-03-20 18:48:38 -04:00
2026-03-20 18:48:38 -04:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2024-10-28 14:20:28 +11:00
2024-10-28 14:20:28 +11:00
2025-02-21 15:49:44 +11:00
2025-11-27 14:13:58 -05:00
2026-02-22 19:59:25 +01:00
2026-02-22 19:59:25 +01:00
2026-02-22 19:59:25 +01:00
2025-12-06 10:22:13 +01:00
2025-12-06 10:22:13 +01:00
2023-01-11 09:32:08 +00:00
2026-03-16 10:21:35 +00:00
2024-02-29 19:06:31 +08:00
2026-03-09 09:11:06 +00:00
2026-03-09 09:11:06 +00:00
2025-08-09 16:27:20 +05:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2024-03-03 16:30:48 -03:00
2024-03-03 16:30:48 -03:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2024-04-21 15:43:43 -03:00
2024-04-21 15:43:43 -03:00
2024-04-21 15:43:43 -03:00
2024-04-21 15:43:43 -03:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-04-20 15:06:17 -03:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2025-12-10 23:41:19 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2024-02-09 15:43:08 -03:00
2024-02-09 15:43:08 -03:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2025-08-14 18:18:42 +02:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2025-11-27 11:19:00 -05:00
2025-11-27 11:19:00 -05:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2025-12-03 16:38:24 +01:00
2025-12-03 16:38:24 +01:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2025-04-03 21:41:58 +00:00
2025-11-27 14:13:58 -05:00
2025-11-27 14:13:58 -05:00
2025-11-27 14:13:58 -05:00
2025-08-09 16:27:20 +05:00
2025-02-21 15:49:46 +11:00
2025-02-21 15:49:46 +11:00
2023-01-11 09:32:08 +00:00
2024-10-28 14:20:28 +11:00
2024-10-28 14:20:28 +11:00
2025-11-27 11:19:00 -05:00
2025-11-27 11:19:00 -05:00
2025-11-27 11:19:00 -05:00
2025-03-07 14:51:07 +11:00
2025-07-23 13:33:23 +02:00
2025-07-23 13:33:23 +02:00
2026-03-09 09:11:06 +00:00
2026-03-09 09:11:06 +00:00
2024-10-28 14:20:28 +11:00
2024-10-28 14:20:28 +11:00
2025-11-27 14:13:58 -05:00
2025-11-27 14:13:58 -05:00
2025-11-27 11:19:00 -05:00
2025-11-27 14:13:58 -05:00
2025-11-27 14:13:58 -05:00
2023-01-11 09:32:08 +00:00
2023-01-11 09:32:08 +00:00
2025-03-11 09:46:34 -07:00
2025-12-03 17:01:49 +01:00
2025-02-28 08:36:12 +11:00
2026-03-16 10:21:35 +00:00