Skip to content

RFC: #[cfg(accessible(..) / version(..))] #2523

New issue

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

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

Already on GitHub? # to your account

Merged
merged 50 commits into from
Sep 26, 2019

Conversation

Centril
Copy link
Contributor

@Centril Centril commented Aug 12, 2018

🖼️ Rendered

⏭ Tracking issue (#[cfg(version(..))]

⏭ Tracking issue (#[cfg(accessible(..))]

📝 Summary

Permit users to #[cfg(..)] on whether:

  • they have a certain minimum Rust version (#[cfg(version(1.27))]).
  • a certain external path is accessible (#[cfg(accessible(::std::mem::ManuallyDrop))]).

💖 Thanks

To @eddyb, @rpjohnst, @kennytm, @aturon, and @rkruppe for discussing the feature with me.
To @Mark-Simulacrum, @MajorBreakfast, @alexreg, @alercah, and @joshtriplett for reviewing the draft version of this RFC.

Centril added 26 commits August 10, 2018 15:09
@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the RFC. label Aug 12, 2018
@Centril Centril self-assigned this Aug 12, 2018
@Centril Centril changed the title RFC: #[cfg(accessible(..) / version(..) / nightly)] RFC: #[cfg(accessible(..) / version = ".." / nightly)] Aug 12, 2018
@Centril
Copy link
Contributor Author

Centril commented Aug 12, 2018

cc @MajorBreakfast re. use case for futures. :)

@ogoffart
Copy link

Another point is that things that are gated sill need to use valid rust grammar.

Let's assume that the version 1.42 adds support for throwing function, and using .if:

#[cfg(version(1.42))]
fn foo(x : bool) -> u32 throw(SomeError) {
    x.if { something() } else { 0 }
}

This won't compile in current rust, even after this rfc is implemented, because this is not valid grammar, and rustc still check the grammar of items even if they are going to be removed by attribute macro or cfg attribute.

I suppose it would not make sense to relax the parsing rules of items that are disabled by #[cfg]

So one must wrap the item inside a macro such as cfg-if!{...} but which would not expand the items for the disabled configuration. Something like this should work: #[cfg($cfg)] identity!{ $($body)* }.

Btw, I've made a crate with a macro if_rust_version with macro_rules that allows conditional like that depending on the rust version: https://github.com/ogoffart/if_rust_version

@rfcbot rfcbot added the finished-final-comment-period The final comment period is finished for this RFC. label Sep 22, 2019
@rfcbot
Copy link
Collaborator

rfcbot commented Sep 22, 2019

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@rfcbot rfcbot removed the final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. label Sep 22, 2019
@Centril Centril merged commit 7afbf18 into rust-lang:master Sep 26, 2019
@Centril
Copy link
Contributor Author

Centril commented Sep 26, 2019

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-cfg Conditional compilation related proposals & ideas A-paths Path related proposals & ideas A-versioning Versioning related proposals & ideas disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this RFC. T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.