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

[DRAFT] RFC: cfg(attr(...)) #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

[DRAFT] RFC: cfg(attr(...)) #13

wants to merge 1 commit into from

Conversation

Centril
Copy link
Owner

@Centril Centril commented Sep 25, 2018

Rendered

This is a draft version of an RFC for you to review, before a formal proposal is made for consideration.

@Nemo157
Copy link

Nemo157 commented Sep 26, 2018

Is there any way this could handle enhancements to attributes, rather than just their initial minimal version? For example the nightly #[doc(include = "foo.md")] feature (I feel like the #[doc] attribute has had other properties added to it in the past as well), or the #[cfg_attr] w/ list of attributes RFC.

@Centril
Copy link
Owner Author

Centril commented Sep 26, 2018

Note to self: One could in some special cases extend attr(..) and write something like attr(doc(include)). However, as attribute macros can be procedural macros written in Rust one must run the procedural macro behind doc to see if it would apply or not; however, since Rust is turing complete, such analysis is in general undecidable.

@joshtriplett
Copy link

You should mention that cfg(not(attr(...)), ...) also works.

Otherwise, LGTM; ship it!

@joshtriplett
Copy link

Oh, one other issue: you need to explicitly explain that this checks if the attribute in question is usable in the context in which it was used. For instance, must_use has worked on types for a long time; the ability to use it on functions arrived much later. cfg(attr(must_use), must_use) on a function needs to check if the attribute works on a function.

@Centril
Copy link
Owner Author

Centril commented Sep 26, 2018

Further note to self based on discussion with @Havvy: should attr(..) be restricted to built-in attributes to keep cfg stripping independent of resolution order and defer uses for built-in macros to accessible(::user::macro)? That might be a cleaner and more orthogonal solution and could also solve problems wrt. undecidability of things like attr(optimize(size)) since built-in attributes can be known to be context free instead of turing complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants