diff --git a/zerocopy-derive/src/lib.rs b/zerocopy-derive/src/lib.rs index f1a7f389a59..2d2515613a5 100644 --- a/zerocopy-derive/src/lib.rs +++ b/zerocopy-derive/src/lib.rs @@ -1205,8 +1205,6 @@ fn impl_block( }); quote! { - // TODO(#553): Add a test that generates a warning when - // `#[allow(deprecated)]` isn't present. #[allow(deprecated)] unsafe impl < #(#params),* > #trait_path for #type_ident < #(#param_idents),* > where diff --git a/zerocopy-derive/tests/ui-nightly/absence_of_deprecated_warning.rs b/zerocopy-derive/tests/ui-nightly/absence_of_deprecated_warning.rs new file mode 100644 index 00000000000..e267e687726 --- /dev/null +++ b/zerocopy-derive/tests/ui-nightly/absence_of_deprecated_warning.rs @@ -0,0 +1,24 @@ +//! See: https://github.com/google/zerocopy/issues/553 +//! zerocopy must still allow derives of deprecated types. +//! This test has a hand-written impl of a deprecated type, and should result in a compilation +//! error. If zerocopy does not tack an allow(deprecated) annotation onto its impls, then this +//! test will fail because more than one compile error will be generated. +#![deny(deprecated)] + +extern crate zerocopy; + +use zerocopy::IntoBytes; + +#[deprecated = "Do not use"] +#[derive(IntoBytes)] +#[repr(C)] +struct OldHeader { + field_a: usize, + collection: [u8; 8], +} + +trait T {} + +impl T for OldHeader {} + +fn main() {} diff --git a/zerocopy-derive/tests/ui-nightly/absence_of_deprecated_warning.stderr b/zerocopy-derive/tests/ui-nightly/absence_of_deprecated_warning.stderr new file mode 100644 index 00000000000..b1ec0a2680a --- /dev/null +++ b/zerocopy-derive/tests/ui-nightly/absence_of_deprecated_warning.stderr @@ -0,0 +1,11 @@ +error: use of deprecated struct `OldHeader`: Do not use + --> tests/ui-nightly/absence_of_deprecated_warning.rs:22:12 + | +22 | impl T for OldHeader {} + | ^^^^^^^^^ + | +note: the lint level is defined here + --> tests/ui-nightly/absence_of_deprecated_warning.rs:6:9 + | +6 | #![deny(deprecated)] + | ^^^^^^^^^^