-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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]
does nothing if placed on an impl item.
#39935
Comments
This is unfortunately a limitation of stability today, it just doesn't work at all with trait impls. (we run into this all the time in libstd as well) |
Unfortunately due to rust-lang/rust#39935 placing the annotation on the `impl`s of `Encodable`/`Decodable` for the various items have no effect whatsoever, so we need to place it on some type that chrono actually uses internally. The only *type* that I can find that only exists for rustc-serialize only is the `TsSeconds` struct. So, marking TsSeconds deprecated causes Chrono's internal uses of `TsSeconds` to emit deprecation warnings, both in our builds and for packages that specify Chrono as a dependency with the `rustc-serialize` feature active. This means that the current commit will cause a `warning: use of deprecated item: RustcSerialize will be removed before chrono 1.0, use Serde instead` to appear in `cargo build` output. Unfortunately I don't think that it's possible for downstream crates to disable the warning the warning in any way other than actually switching to Serde or using an older chrono. That's the reason for all the `#[allow(deprecated)]` through the code, it means that the warning appears almost exactly once, instead of dozens of times.
Unfortunately due to rust-lang/rust#39935 placing the annotation on the `impl`s of `Encodable`/`Decodable` for the various items have no effect whatsoever, so we need to place it on some type that chrono actually uses internally. The only *type* that I can find that only exists for rustc-serialize only is the `TsSeconds` struct. So, marking TsSeconds deprecated causes Chrono's internal uses of `TsSeconds` to emit deprecation warnings, both in our builds and for packages that specify Chrono as a dependency with the `rustc-serialize` feature active. This means that the current commit will cause a `warning: use of deprecated item: RustcSerialize will be removed before chrono 1.0, use Serde instead` to appear in `cargo build` output. Unfortunately I don't think that it's possible for downstream crates to disable the warning the warning in any way other than actually switching to Serde or using an older chrono. That's the reason for all the `#[allow(deprecated)]` through the code, it means that the warning appears almost exactly once, instead of dozens of times.
Unfortunately due to rust-lang/rust#39935 placing the annotation on the `impl`s of `Encodable`/`Decodable` for the various items have no effect whatsoever, so we need to place it on some type that chrono actually uses internally. The only *type* that I can find that only exists for rustc-serialize only is the `TsSeconds` struct. So, marking TsSeconds deprecated causes Chrono's internal uses of `TsSeconds` to emit deprecation warnings, both in our builds and for packages that specify Chrono as a dependency with the `rustc-serialize` feature active. This means that the current commit will cause a `warning: use of deprecated item: RustcSerialize will be removed before chrono 1.0, use Serde instead` to appear in `cargo build` output. Unfortunately I don't think that it's possible for downstream crates to disable the warning the warning in any way other than actually switching to Serde or using an older chrono. That's the reason for all the `#[allow(deprecated)]` through the code, it means that the warning appears almost exactly once, instead of dozens of times.
Unfortunately due to rust-lang/rust#39935 placing the annotation on the `impl`s of `Encodable`/`Decodable` for the various items have no effect whatsoever, so we need to place it on some type that chrono actually uses internally. The only *type* that I can find that only exists for rustc-serialize only is the `TsSeconds` struct. So, marking TsSeconds deprecated causes Chrono's internal uses of `TsSeconds` to emit deprecation warnings, both in our builds and for packages that specify Chrono as a dependency with the `rustc-serialize` feature active. This means that the current commit will cause a `warning: use of deprecated item: RustcSerialize will be removed before chrono 1.0, use Serde instead` to appear in `cargo build` output. Unfortunately I don't think that it's possible for downstream crates to disable the warning the warning in any way other than actually switching to Serde or using an older chrono. That's the reason for all the `#[allow(deprecated)]` through the code, it means that the warning appears almost exactly once, instead of dozens of times.
@alexcrichton Do we want to support stability on trait impls or not? I remember this being discussed elsewhere but I don't remember the conclusion. |
It'd be nice yeah! At this point everyone just assumes it doesn't work, so there's likely lots of misannotated impls or unintended fallout from a "bugfix" change like this, but it'd be good to implement if possible! |
I still think we should at least make this a compiler error until we can make it work. I disagree with the "everyone assumes it doesn't work" take, I think folks do assume it works, and never verify if their users are receiving a warning or not. |
A warning would be a gentler option. I agree that it's not good to let people put the deprecation attribute on and assume it will work. |
I'm surprised this hasn't received more attention. It seems like a rather common occurrence that a library will have a type that implements a trait and you want to remove it but there is no way to direct users away from using the impl Trait. For instance, I have a type that implements |
#78626 turned this into a compile error. |
Unfortunately, deprecation annotations on trait `ìmpl` blocks are ignored by the compiler (see <rust-lang/rust#39935>).
Unfortunately, deprecation annotations on trait `ìmpl` blocks are ignored by the compiler (see <rust-lang/rust#39935>).
Unfortunately, deprecation annotations on trait `ìmpl` blocks are ignored by the compiler (see <rust-lang/rust#39935>).
Given the current stable release:
Then I am at least told that the deprecation is not going to work:
error: could not compile |
Given the following two crates:
I would expect the second crate to see a deprecation warning on the use of
Foo.into_bar()
. Instead, both crates compile successfully with no errors. I think that allowing deprecations on impls is a useful option to provide to authors (one that I was looking to do, and found this while seeing if it would work). However, if we do not wish to provide that ability to library authors, placing the#[deprecated]
attribute on an impl should result in a compiler error.The text was updated successfully, but these errors were encountered: