Skip to content

Commit

Permalink
[derive] Test derives on deprecated types (#1336)
Browse files Browse the repository at this point in the history
Follows up on #1332
Makes progress on #553
  • Loading branch information
joshlf authored May 21, 2024
1 parent dee5b3c commit 419d89e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
48 changes: 48 additions & 0 deletions zerocopy-derive/tests/deprecated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2024 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
#![deny(deprecated)]

include!("include.rs");

// Make sure no deprecation warnings are generated from our derives (see #553).

#[macro_export]
macro_rules! test {
($name:ident => $ty:item => $($trait:ident),*) => {
#[allow(non_snake_case)]
mod $name {
$(
mod $trait {
use super::super::*;

#[deprecated = "do not use"]
#[derive(imp::$trait)]
$ty

#[allow(deprecated)]
fn _allow_deprecated() {
util_assert_impl_all!($name: imp::$trait);
}
}
)*
}
};
}

// NOTE: `FromBytes` is tested separately in `enum_from_bytes.rs` since it
// requires 256-variant enums which are extremely verbose; such enums are
// already in that file.
test!(Enum => #[repr(u8)] enum Enum { A, } => TryFromBytes, FromZeros, KnownLayout, Immutable, IntoBytes, Unaligned);

test!(Struct => #[repr(C)] struct Struct; => TryFromBytes, FromZeros, FromBytes, KnownLayout, Immutable, IntoBytes, Unaligned);

test!(Union => #[repr(C)] union Union{ a: (), } => TryFromBytes, FromZeros, FromBytes, KnownLayout, Immutable, IntoBytes, Unaligned);
8 changes: 7 additions & 1 deletion zerocopy-derive/tests/enum_from_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
#![deny(deprecated)]

include!("include.rs");

Expand All @@ -29,6 +30,8 @@ include!("include.rs");
// `Variant128` has a discriminant of -128) since Rust won't automatically wrap
// a signed discriminant around without you explicitly telling it to.

// Make sure no deprecation warning is generated from our derive (see #553).
#[deprecated = "do not use"]
#[derive(imp::FromBytes)]
#[repr(u8)]
enum FooU8 {
Expand Down Expand Up @@ -290,7 +293,10 @@ enum FooU8 {
Variant255,
}

util_assert_impl_all!(FooU8: imp::FromBytes);
#[allow(deprecated)]
fn _allow_deprecated() {
util_assert_impl_all!(FooU8: imp::FromBytes);
}

#[derive(imp::FromBytes)]
#[repr(i8)]
Expand Down

0 comments on commit 419d89e

Please sign in to comment.