Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: conditional attributes #12479

Closed
huonw opened this issue Feb 22, 2014 · 5 comments
Closed

RFC: conditional attributes #12479

huonw opened this issue Feb 22, 2014 · 5 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`)

Comments

@huonw
Copy link
Member

huonw commented Feb 22, 2014

Currently the only way to have attributes that apply conditionally is to duplicate the whole item (e.g. #[link()] extern metadata that change per platform, or wish to have dynamic/static linking toggled externally). It'd be nice to have be able to avoid this.

Proposal: add cfg_attr(predicate, attribute) that only applies attribute if predicate is satisfied. e.g.

#[cfg_attr(windows, link(name="mylib_win"))]
#[cfg_attr(not(windows), link(name="mylib"))]
extern {
     fn mylib_some_func();
     // ...
}

currently has to be

#[cfg(windows)]
#[link(name="mylib_win")]
extern {
     fn mylib_some_func();
     // ...
}

#[cfg(not(windows))]
#[link(name="mylib")]
extern {
     fn mylib_some_func();
     // ...
}
@sfackler
Copy link
Member

I assume that #[cfg_attr(foo, bar)] would be replaced with either #[bar] or nothing in the cfg pass?

@huonw
Copy link
Member Author

huonw commented Feb 22, 2014

Something like that.

@alexcrichton
Copy link
Member

One snag I can imagine is that sometimes predicates are more complicated than just cfg(windows). There's an issue on a more general cfg language which I think would fix it, but this does seem like a nice solution!

@huonw
Copy link
Member Author

huonw commented Feb 23, 2014

That issue seems to be #2119.

@huonw
Copy link
Member Author

huonw commented May 4, 2014

Needs to become a proper RFC...

@huonw huonw closed this as completed May 4, 2014
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this issue Mar 21, 2024
move `readonly_write_lock` to perf

[There haven't been any issues](https://github.com/rust-lang/rust-clippy/issues?q=is%3Aissue+readonly_write_lock) since its creation and it's a pretty useful lint I think, so I'd say it's worth giving it a try?

Did a lintcheck run on 300 crates with no results, but I guess `RwLock` is usually not something that's used much in libraries.

changelog: move [`readonly_write_lock`] to perf (now warn-by-default)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`)
Projects
None yet
Development

No branches or pull requests

3 participants