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

#[deprecated] decorator is missing on enum access functions #985

Open
Orycterope opened this issue Feb 21, 2024 · 0 comments
Open

#[deprecated] decorator is missing on enum access functions #985

Orycterope opened this issue Feb 21, 2024 · 0 comments

Comments

@Orycterope
Copy link

Orycterope commented Feb 21, 2024

If you declare a message with a deprecated enum field, like so:

message Shirt {
	Color deprecated_color = 1 [deprecated = true];
}

enum Color {
    BLUE = 0;
    RED = 1;
    GREEN = 2;
}

You don't get a deprecation warning if you try to use the deprecated_color access functions:

    // This produces a deprecation warning:
    shirt.deprecated_color = Color::Blue as _;

    // But this does not:
    shirt.set_deprecated_color(Color::Blue);

I've made a reproducer for this bug here: https://github.com/Orycterope/prost_deprecation_reproducer

It looks like this is because the generated structure correctly marks the field as deprecated but not the access functions generated by #[prost(enumeration = "Color", tag = "1")].

To see the actual function generated by the macro I had to use cargo expand:

cargo expand -p prost_reproducer_app --color always items | less -r
...
    #[allow(dead_code)]
    impl Shirt {
        ///Returns the enum value of `deprecated_color`, or the default if the field is set to an invalid enum value.
        pub fn deprecated_color(&self) -> Color {
            ::core::convert::TryFrom::try_from(self.deprecated_color)
                .unwrap_or(Color::default())
        }
        ///Sets `deprecated_color` to the provided enum value.
        pub fn set_deprecated_color(&mut self, value: Color) {
            self.deprecated_color = value as i32;
        }
    }

We can see that the functions have no #[deprecated] decorator attached to them. However, they do access deprecated_color internally, which should raise a warning. I don't know why rustc silences it (just because it's a macro ? Couldn't find anything about this behavior), but it does.

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

No branches or pull requests

1 participant