-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
WIP: Minver guard #5
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,7 @@ | |
//! | ||
//! <br> | ||
|
||
#[macro_use] extern crate lazy_static; | ||
extern crate proc_macro; | ||
|
||
mod attr; | ||
|
@@ -194,6 +195,11 @@ pub fn all(args: TokenStream, input: TokenStream) -> TokenStream { | |
cfg("all", args, input) | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn minver(args: TokenStream, input: TokenStream) -> TokenStream { | ||
cfg("minver", args, input) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, this would be only usable as a global |
||
} | ||
|
||
fn cfg(top: &str, args: TokenStream, input: TokenStream) -> TokenStream { | ||
match try_cfg(top, args, input) { | ||
Ok(tokens) => tokens, | ||
|
@@ -213,10 +219,10 @@ fn try_cfg(top: &str, args: TokenStream, input: TokenStream) -> Result<TokenStre | |
let expr: Expr = syn::parse2(full_args)?; | ||
let version = rustc::version()?; | ||
|
||
if expr.eval(version) { | ||
Ok(input) | ||
} else { | ||
Ok(TokenStream::new()) | ||
match expr.eval(version) { | ||
Ok(true) => Ok(input), | ||
Ok(false) => Ok(TokenStream::new()), | ||
Err(err) => unimplemented!(), | ||
} | ||
} | ||
|
||
|
@@ -233,9 +239,11 @@ pub fn attr(args: TokenStream, input: TokenStream) -> TokenStream { | |
fn try_attr(args: attr::Args, input: TokenStream) -> Result<TokenStream> { | ||
let version = rustc::version()?; | ||
|
||
if !args.condition.eval(version) { | ||
return Ok(input); | ||
} | ||
match args.condition.eval(version) { | ||
Ok(false) => return Ok(input), | ||
Err(err) => unimplemented!(), | ||
_ => (), | ||
}; | ||
|
||
match args.then { | ||
Then::Const(const_token) => { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 looks like you are planning to rely on invocation order and sharing data through a static in the proc macro's process. Be aware that the compiler makes no guarantee about what order macro invocations run in or whether different macro calls all run in the same process, so I don't plan to accept an implementation like this.
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 thought that might be a problem, but documentation seems to be thin. Is there a place to store stateful information like this? I assume so since I'm not sure how/where
clippy
would store warning state information, but maybe that's a plugin thing and not available to proc macros?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 don't know of an established place to store information across proc macro calls without putting it in the generated code. Clippy is not implemented as a proc macro.
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.
Well, if it does go into the generated code, how would a proc macro access it anyways? Maybe this isn't possible with a proc macro today?