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

Add cfg for version based conditional compilation #14218

Closed
wants to merge 1 commit into from
Closed

Add cfg for version based conditional compilation #14218

wants to merge 1 commit into from

Conversation

kaseyc
Copy link
Contributor

@kaseyc kaseyc commented May 15, 2014

Fixes #3795

This PR implements a cfg that conditionally includes code based on the current version of the Rust compiler.
It uses the syntax proposed in #3795, namely #[cfg(rust_version="X")].
It accepts the operators <, <=, >, >=, != (just for completeness), and checks for equality if no operator is specified.

@@ -322,6 +359,24 @@ pub fn test_cfg<AM: AttrMetaMethods, It: Iterator<AM>>
contains(cfg, *mi)
})
}
ast::MetaNameValue(ref n, _)
if n.equiv(&("rust_version")) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is questionable to have this rust_version behaviour hardcoded into the cfg matcher here (since this matcher is fairly generic).

However, I'm not really sure of a better place for it to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out a better place to put it, as the contains function doesn't cut it due to the need to parse and compare the versions. I did my best to make it follow the same style as the not() special case in the matcher.

@alexcrichton
Copy link
Member

This is fairly large language change, and the scheme mentioned in #3795 I think was more of a suggestion. I think that something like this may need to go through the RFC process first so we can flesh out all the details.

I don't think just using a cfg attribute will work because it assumes that we're going to use the same syntax for forever, which is likely not true (we may add new syntactical constructs), in which case #[cfg] may not be sufficient (but perhaps it could be made to be sufficient!).

@kaseyc
Copy link
Contributor Author

kaseyc commented May 15, 2014

Ok. I'll close the PR for now and look into writing an RFC for this. Thanks.

@kaseyc kaseyc closed this May 15, 2014
@huonw
Copy link
Member

huonw commented May 15, 2014

(Thanks for working on this. ❤️ )

@kaseyc
Copy link
Contributor Author

kaseyc commented May 15, 2014

Not a problem 😄

@alexcrichton
Copy link
Member

Sorry for sounding a little curt, I'm excited to see progress on this issue! I'd love to get this taken care off, because I'm sure we can already start taking advantage of it!

I think that a solution like this may actually work out, it would likely involve some parser changes, however, and I'm curious what others' thoughts on this problem are (an RFC would certainly help gather comments).

As @huonw said, thanks for working on this, it is much appreciated!

@kaseyc
Copy link
Contributor Author

kaseyc commented May 15, 2014

I don't mind, and your points definitely made sense. I appreciate the feedback.

For something like this to work, there would need to be some way to exclude an item before it is checked/parsed, which would require some changes in how cfg's are implemented currently. And if changes are made, it would be a great time to try and addresss @huonw 's concerns about adding special casing into the matcher, as it is somewhat lacking in that department at the moment.

I can try to draw up an RFC, though I'm getting into finals season, so it could take a little time.

lnicola pushed a commit to lnicola/rust that referenced this pull request Mar 13, 2023
Deduplicate source roots that have overlapping include paths

Fixes flycheck not working for the rustc workspace when using `linkedProjects`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need a mechanism to write rust-version-specific code
3 participants