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 support for enum and oneof field deprecated. #701

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sonder-joker
Copy link

@sonder-joker sonder-joker commented Aug 12, 2022

I notice it's not support enum and oneof field deprecated.

Copy link
Collaborator

@caspermeijn caspermeijn left a 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");
Copy link
Collaborator

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?

Copy link
Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes sense

@@ -304,6 +305,7 @@ fn try_enumeration(input: TokenStream) -> Result<TokenStream, Error> {
}
}

#[allow(deprecated)]
Copy link
Collaborator

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?

Copy link
Author

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;
Copy link
Collaborator

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

Copy link
Collaborator

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

@sonder-joker sonder-joker force-pushed the master branch 2 times, most recently from 52e80f4 to 42afd88 Compare July 18, 2024 16:12
Copy link
Collaborator

@caspermeijn caspermeijn left a 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");
Copy link
Collaborator

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))
Copy link
Collaborator

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] }) {
Copy link
Collaborator

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)]
Copy link
Collaborator

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;
Copy link
Collaborator

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

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.

2 participants