# \[Pre-RFC\] Cfg Attribute Alias

**URL:** <https://internals.rust-lang.org/t/pre-rfc-cfg-attribute-alias/7404>\
**Category:** language design\
**Created:** [April 27, 2018, 12:14am UTC](https://internals.rust-lang.org/t/pre-rfc-cfg-attribute-alias/7404 "2018-04-27T00:14:23Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![nrxus](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nrxus/32/3946_2.png) [@nrxus](https://internals.rust-lang.org/u/nrxus)\
**Post date:** [April 30, 2018, 2:54pm UTC](https://internals.rust-lang.org/t/pre-rfc-cfg-attribute-alias/7404/16 "2018-04-30T14:54:06Z")

</div>

It would be nice to stay within the current syntax, although I imagine it wouldn’t be too hard to do a non-breaking change to allow this.

Since we would probably restrict aliases to only alias specific attributes then maybe something like this could work:

```rust
#![alias(foobar = cfg(any(foo, bar)))]
#![alias(Data = derive(Eq, PartialEq, Clone, Copy, Debug))]
#![alias(Serde = cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

//usage
#[cfg(foobar)] // foobar is a cfg alias so it can only be used within a cfg
fn only_called_when_foo_or_bar_are_on() {
  //...
}

#[derive(Data)] // Data is a derive Alias so it can only be used within a derive
struct Foo {
  //...
}

#[cfg_attr(Serde)] // Serde is a cfg_attr alias so it can only be used within a cfg_attr
struct CanSerialize {
  //...
}

```

Alternatively we could also alias the entire attribute and do:

```rust
#![alias(foobar = cfg(any(foo, bar)))]

#[foobar] // foobar aliases cfg(any(foo, bar)) so no need to re-wrap it a #[cfg(...)]
fn only_called_when_foo_or_bar_are_on() {
  //...
}

```

This last option however feels weird to me because now `foobar` looks like a custom attribute rather than a simple alias.

---

_[View the full topic](https://internals.rust-lang.org/t/pre-rfc-cfg-attribute-alias/7404)._
