-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Conversation
@@ -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")) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 |
Ok. I'll close the PR for now and look into writing an RFC for this. Thanks. |
(Thanks for working on this. ❤️ ) |
Not a problem 😄 |
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! |
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. |
Deduplicate source roots that have overlapping include paths Fixes flycheck not working for the rustc workspace when using `linkedProjects`
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.