add #[allow(deprecated)] to derive implementations#2879
add #[allow(deprecated)] to derive implementations#2879dtolnay merged 1 commit intoserde-rs:masterfrom
#[allow(deprecated)] to derive implementations#2879Conversation
|
I just encountered the same issue and was wondering how that could be implemented. While I am perfectly fine with the given PR, I thought about a more generic way. Like: #[derive(Serialize, Deserialize)]
#[deprecated]
#[serde(allow = deprecated)]
struct bla {} |
|
@KarstenB that is definitely doable if that is the desired behavior. Personally I'm not sure I can think of a scenario where I do want to see these messages, so I'd at least be in favor of making the default not showing them, with some sort of option to turn them back on. (For some justification of this, in rust itself they hide deprecation messages in derives, so in my opinion this would put serde more inline with expected behavior.) |
in theory that check should work for serde automatically, but making that happen at the proc macro level causes lots of problems inside other diagnostics: #2847 (comment) |
|
@oli-obk is there anything you're waiting to see from me on this? From my perspective it is ready for review |
|
No... this is mostly me not wanting to add workarounds that are necessary because of other workarounds. w |
|
Considering the low cost to maintenance this PR adds, gonna merge it as is |
dtolnay
left a comment
There was a problem hiding this comment.
I don't like this workaround because it silently suppresses legitimate deprecations on parts of the generated impl that come from user-specified attributes. Example:
use serde::Deserializer;
use serde_derive::Deserialize;
#[derive(Deserialize)]
pub struct Struct {
#[serde(deserialize_with = "deprecated_with")]
pub field: i32,
}
#[deprecated]
fn deprecated_with<'de, D>(_deserializer: D) -> Result<i32, D::Error>
where
D: Deserializer<'de>,
{
unimplemented!()
}warning: use of deprecated function `deprecated_with`
--> src/main.rs:6:32
|
6 | #[serde(deserialize_with = "deprecated_with")]
| ^^^^^^^^^^^^^^^^^
|
= note: `#[warn(deprecated)]` on by defaultPlease put allow(deprecated) if and only if the input data structure has either #[deprecated] or #[allow(deprecated)].
Allow deprecated in the `Serialize`/`Deserialize` derive implementations. This allows you to deprecate structs, enums, struct fields, or enum variants and not get compiler warnings/errors about use of deprecated thing. We only do this if `#[deprecated]` or `#[allow(deprecated)]` exist on the root object or the variants of the root object (if it is an enum). Resolves serde-rs#2195
e4238d4 to
ae38b27
Compare
|
I finally got some time to look into this and made some adjustments based on @dtolnay's suggestions. Now we only add the |
|
Published in serde_derive 1.0.225. |
| /// Determine if an `#[allow(deprecated)]` should be added to the derived impl. | ||
| /// | ||
| /// This should happen if the derive input or a variant of the enum (if derive input is an enum) | ||
| /// has on of: |
Allow deprecated in the
Serialize/Deserializederive implementations. This allows you to deprecate structs, enums, struct fields, or enum variants and not get compiler warnings/errors about use of deprecated thing.Resolves #2195