rust/compiler/rustc_expand/src
Dylan DPC 9c310571a8
Rollup merge of #82682 - petrochenkov:cfgeval, r=Aaron1011
Implement built-in attribute macro `#[cfg_eval]` + some refactoring

This PR implements a built-in attribute macro `#[cfg_eval]` as it was suggested in https://github.com/rust-lang/rust/pull/79078 to avoid `#[derive()]` without arguments being abused as a way to configure input for other attributes.

The macro is used for eagerly expanding all `#[cfg]` and `#[cfg_attr]` attributes in its input ("fully configuring" the input).
The effect is identical to effect of `#[derive(Foo, Bar)]` which also fully configures its input before passing it to macros `Foo` and `Bar`, but unlike `#[derive]` `#[cfg_eval]` can be applied to any syntax nodes supporting macro attributes, not only certain items.

`cfg_eval` was the first name suggested in https://github.com/rust-lang/rust/pull/79078, but other alternatives are also possible, e.g. `cfg_expand`.

```rust
#[cfg_eval]
#[my_attr] // Receives `struct S {}` as input, the field is configured away by `#[cfg_eval]`
struct S {
    #[cfg(FALSE)]
    field: u8,
}
```

Tracking issue: https://github.com/rust-lang/rust/issues/82679
2021-03-08 13:13:23 +01:00
..
mbe Add SEMICOLON_IN_EXPRESSIONS_FROM_MACROS lint 2021-01-28 08:51:43 -05:00
mut_visit ast: Stop using Mod in Crate 2021-02-18 13:07:49 +03:00
parse ast: Keep expansion status for out-of-line module items 2021-02-18 13:07:49 +03:00
tokenstream mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
base.rs Rollup merge of #82682 - petrochenkov:cfgeval, r=Aaron1011 2021-03-08 13:13:23 +01:00
build.rs Properly handle attributes on statements 2020-11-26 17:08:35 -05:00
config.rs Move full configuration logic from rustc_expand to rustc_builtin_macros 2021-03-07 00:17:31 +03:00
expand.rs expand: Align some code with the PR fixing inner attributes on out-of-line modules 2021-03-05 01:33:43 +03:00
lib.rs expand: Introduce enum for module loading errors and make module loading speculative 2021-03-05 01:33:43 +03:00
mbe.rs Revert "Promote missing_fragment_specifier to hard error" 2020-12-22 09:33:16 -05:00
module.rs expand: Introduce enum for module loading errors and make module loading speculative 2021-03-05 01:33:43 +03:00
placeholders.rs expand: Remove obsolete ExpansionConfig::keep_macs 2021-02-14 19:43:54 +03:00
proc_macro_server.rs rustc_parse: Better spans for synthesized token streams 2021-01-07 17:48:13 +03:00
proc_macro.rs expand/resolve: Turn #[derive] into a regular macro attribute 2021-02-07 20:08:45 +03:00
tests.rs remove redundant closures (clippy::redundant_closure) 2021-01-03 13:34:24 +01:00