Skip to content

Commit 419d89e

Browse files
authored
[derive] Test derives on deprecated types (#1336)
Follows up on #1332 Makes progress on #553
1 parent dee5b3c commit 419d89e

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

zerocopy-derive/tests/deprecated.rs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2024 The Fuchsia Authors
2+
//
3+
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
4+
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
5+
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
6+
// This file may not be copied, modified, or distributed except according to
7+
// those terms.
8+
9+
// See comment in `include.rs` for why we disable the prelude.
10+
#![no_implicit_prelude]
11+
#![allow(warnings)]
12+
#![deny(deprecated)]
13+
14+
include!("include.rs");
15+
16+
// Make sure no deprecation warnings are generated from our derives (see #553).
17+
18+
#[macro_export]
19+
macro_rules! test {
20+
($name:ident => $ty:item => $($trait:ident),*) => {
21+
#[allow(non_snake_case)]
22+
mod $name {
23+
$(
24+
mod $trait {
25+
use super::super::*;
26+
27+
#[deprecated = "do not use"]
28+
#[derive(imp::$trait)]
29+
$ty
30+
31+
#[allow(deprecated)]
32+
fn _allow_deprecated() {
33+
util_assert_impl_all!($name: imp::$trait);
34+
}
35+
}
36+
)*
37+
}
38+
};
39+
}
40+
41+
// NOTE: `FromBytes` is tested separately in `enum_from_bytes.rs` since it
42+
// requires 256-variant enums which are extremely verbose; such enums are
43+
// already in that file.
44+
test!(Enum => #[repr(u8)] enum Enum { A, } => TryFromBytes, FromZeros, KnownLayout, Immutable, IntoBytes, Unaligned);
45+
46+
test!(Struct => #[repr(C)] struct Struct; => TryFromBytes, FromZeros, FromBytes, KnownLayout, Immutable, IntoBytes, Unaligned);
47+
48+
test!(Union => #[repr(C)] union Union{ a: (), } => TryFromBytes, FromZeros, FromBytes, KnownLayout, Immutable, IntoBytes, Unaligned);

zerocopy-derive/tests/enum_from_bytes.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// See comment in `include.rs` for why we disable the prelude.
1010
#![no_implicit_prelude]
1111
#![allow(warnings)]
12+
#![deny(deprecated)]
1213

1314
include!("include.rs");
1415

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

33+
// Make sure no deprecation warning is generated from our derive (see #553).
34+
#[deprecated = "do not use"]
3235
#[derive(imp::FromBytes)]
3336
#[repr(u8)]
3437
enum FooU8 {
@@ -290,7 +293,10 @@ enum FooU8 {
290293
Variant255,
291294
}
292295

293-
util_assert_impl_all!(FooU8: imp::FromBytes);
296+
#[allow(deprecated)]
297+
fn _allow_deprecated() {
298+
util_assert_impl_all!(FooU8: imp::FromBytes);
299+
}
294300

295301
#[derive(imp::FromBytes)]
296302
#[repr(i8)]

0 commit comments

Comments
 (0)