-
Notifications
You must be signed in to change notification settings - Fork 500
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 support for enum and oneof field deprecated. #701
base: master
Are you sure you want to change the base?
Conversation
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 like this idea. We should support deprecated on all fields.
Please rebase the branch to enable CI
@@ -670,6 +679,10 @@ impl<'a> CodeGenerator<'a> { | |||
self.depth += 1; | |||
|
|||
for variant in variant_mappings.iter() { | |||
if variant.deprecated { | |||
self.push_indent(); | |||
self.buf.push_str("#[allow(deprecated)]\n"); |
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.
Why is the allow
statement now needed and not is previous 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.
This direct call will raise deprecated warning for every call of as_str_name
, so we need a #[allow(deprecated)]
for normal call.
For deprecated enum, direct call as_str_name
will still raise warning.
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.
That makes sense
prost-derive/src/lib.rs
Outdated
@@ -304,6 +305,7 @@ fn try_enumeration(input: TokenStream) -> Result<TokenStream, Error> { | |||
} | |||
} | |||
|
|||
#[allow(deprecated)] |
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.
Will this hide deprecation warnings in non deprecated fields?
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.
fix.
}; | ||
#[allow(deprecated)] | ||
let enum_ = deprecated_field::Test2::Outdated; |
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 would like to see an additional test: generate a proto with only deprecated fields and write that to file. This has two purposes:
- It adds a example of all
deprecated
statements to the PR - It actually tests that the
deprecated
flag is added to the fields.
The repo has examples for a test writing to file and asserting nothing changes: test_generate_no_empty_outputs
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.
Thanks for creating that test
52e80f4
to
42afd88
Compare
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.
CI is failing. I believe you can fix that by running this locally and committing the result: cargo test -p prost-build -p prost-derive -p prost-types --all-targets --no-default-features
@@ -670,6 +679,10 @@ impl<'a> CodeGenerator<'a> { | |||
self.depth += 1; | |||
|
|||
for variant in variant_mappings.iter() { | |||
if variant.deprecated { | |||
self.push_indent(); | |||
self.buf.push_str("#[allow(deprecated)]\n"); |
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.
That makes sense
let tempdir = tempfile::tempdir().unwrap(); | ||
|
||
Config::new() | ||
.service_generator(Box::new(gen)) |
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.
Is service_generator
needed for this test?
match discriminant { | ||
Some((_, expr)) => variants.push((ident, expr)), | ||
Some((_, expr)) => { | ||
let deprecated_attr = if attrs.contains(&parse_quote! { #[deprecated] }) { |
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 have experience with syn
, but this pattern is different from other uses.
In the existing code, the attrs
are matched with is_ident
. For example:
https://github.com/caspermeijn/prost/blob/87540c6bd00848a4f4591512e9b27e3dd5024398/prost-derive/src/lib.rs#L26-L29
What is the reason this works differently?
@@ -460,6 +467,7 @@ fn try_oneof(input: TokenStream) -> Result<TokenStream, Error> { | |||
}); | |||
|
|||
let expanded = quote! { | |||
#[allow(deprecated)] |
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.
Why is this not conditional, but the other allow
statements are?
}; | ||
#[allow(deprecated)] | ||
let enum_ = deprecated_field::Test2::Outdated; |
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.
Thanks for creating that test
I notice it's not support enum and oneof field deprecated.