Skip to content

Commit 46c8c6c

Browse files
committed
Fix zerocopy build errors
1 parent f793d84 commit 46c8c6c

File tree

7 files changed

+162
-23
lines changed

7 files changed

+162
-23
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
target
2-
Cargo.lock

Cargo.lock

Lines changed: 146 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ arbitrary1 = { package = "arbitrary", version = "1.0.2", optional = true }
1515
bytemuck1 = { package = "bytemuck", version = "1.7.2", optional = true }
1616
num-traits02 = { package = "num-traits", version = "0.2.14", default-features = false, features = ["i128"], optional = true }
1717
serde1 = { package = "serde", version = "1.0.124", default-features = false, optional = true }
18-
zerocopy06 = { package = "zerocopy", version = "0.6", optional = true }
18+
zerocopy = { version = "0.8.14", features = ["derive"], optional = true }
1919

2020
[features]
2121
std = ["alloc"]

macro/src/generate.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,10 @@ fn generate_item(item: &BoundedInteger, tokens: &mut TokenStream) {
4646
let repr = &item.repr;
4747
let crate_path = &item.crate_path;
4848

49-
if item.zerocopy06 {
50-
let zerocopy = quote!(#crate_path::__private::zerocopy06);
49+
if item.zerocopy {
50+
let zerocopy = quote!(#crate_path::__private::zerocopy);
5151

52-
// Zerocopy is not hygienic: https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=84476
53-
tokens.extend(quote! {
54-
use ::core::marker::Sized;
55-
use #zerocopy as zerocopy;
56-
});
57-
58-
tokens.extend(quote!(#[derive(#zerocopy::AsBytes)]));
52+
tokens.extend(quote!(#[derive(#zerocopy::IntoBytes)]));
5953
if let ReprSize::Fixed(ReprSizeFixed::Fixed8) = item.repr.size {
6054
tokens.extend(quote!(#[derive(#zerocopy::Unaligned)]));
6155
}

macro/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct BoundedInteger {
6464
bytemuck1: bool,
6565
serde1: bool,
6666
std: bool,
67-
zerocopy06: bool,
67+
zerocopy: bool,
6868
step_trait: bool,
6969

7070
// The item itself
@@ -86,7 +86,7 @@ impl Parse for BoundedInteger {
8686
let bytemuck1 = input.parse::<LitBool>()?.value;
8787
let serde1 = input.parse::<LitBool>()?.value;
8888
let std = input.parse::<LitBool>()?.value;
89-
let zerocopy06 = input.parse::<LitBool>()?.value;
89+
let zerocopy = input.parse::<LitBool>()?.value;
9090
let step_trait = input.parse::<LitBool>()?.value;
9191

9292
let mut attrs = input.call(Attribute::parse_outer)?;
@@ -163,7 +163,7 @@ impl Parse for BoundedInteger {
163163
bytemuck1,
164164
serde1,
165165
std,
166-
zerocopy06,
166+
zerocopy,
167167
step_trait,
168168
attrs,
169169
repr,

src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
//! [`SaturatingSub`] for all const-generic bounded integers.
6363
//! - `serde1`: Implement [`Serialize`] and [`Deserialize`] for the bounded integers, making sure all
6464
//! values will never be out of bounds. This has a deprecated alias `serde`.
65-
//! - `zerocopy06`: Implement [`AsBytes`] for all bounded integers, and [`Unaligned`] for
66-
//! macro-generated ones.
65+
//! - `zerocopy`: Implement [`IntoBytes`] for all bounded integers,
66+
//! and [`Unaligned`] for suitable macro-generated ones.
6767
//! - `step_trait`: Implement the [`Step`] trait which allows the bounded integers to be easily used
6868
//! in ranges. This will require you to use nightly and place `#![feature(step_trait)]` in your
6969
//! crate root if you use the macro.
@@ -90,8 +90,8 @@
9090
//! [`SaturatingSub`]: https://docs.rs/num-traits/0.2/num_traits/ops/saturating/trait.SaturatingSub.html
9191
//! [`Serialize`]: https://docs.rs/serde/1/serde/trait.Serialize.html
9292
//! [`Deserialize`]: https://docs.rs/serde/1/serde/trait.Deserialize.html
93-
//! [`AsBytes`]: https://docs.rs/zerocopy/0.6/zerocopy/trait.AsBytes.html
94-
//! [`Unaligned`]: https://docs.rs/zerocopy/0.6/zerocopy/trait.Unaligned.html
93+
//! [`IntoBytes`]: https://docs.rs/zerocopy/0.8/zerocopy/trait.IntoBytes.html
94+
//! [`Unaligned`]: https://docs.rs/zerocopy/0.8/zerocopy/trait.Unaligned.html
9595
//! [`Step`]: https://doc.rust-lang.org/nightly/core/iter/trait.Step.html
9696
//! [`Error`]: https://doc.rust-lang.org/stable/std/error/trait.Error.html
9797
//! [`ParseError`]: https://docs.rs/bounded-integer/*/bounded_integer/struct.ParseError.html
@@ -126,8 +126,8 @@ pub mod __private {
126126
#[cfg(feature = "serde1")]
127127
pub use ::serde1;
128128

129-
#[cfg(feature = "zerocopy06")]
130-
pub use ::zerocopy06;
129+
#[cfg(feature = "zerocopy")]
130+
pub use ::zerocopy;
131131

132132
pub use bounded_integer_macro::bounded_integer as proc_macro;
133133

@@ -238,7 +238,7 @@ block! {
238238
let bytemuck1: ident = cfg_bool!(feature = "bytemuck1");
239239
let serde1: ident = cfg_bool!(feature = "serde1");
240240
let std: ident = cfg_bool!(feature = "std");
241-
let zerocopy06: ident = cfg_bool!(feature = "zerocopy06");
241+
let zerocopy: ident = cfg_bool!(feature = "zerocopy");
242242
let step_trait: ident = cfg_bool!(feature = "step_trait");
243243
let d: tt = dollar!();
244244

@@ -247,7 +247,7 @@ block! {
247247
macro_rules! __bounded_integer_inner2 {
248248
($d($d tt:tt)*) => {
249249
$crate::__private::proc_macro! {
250-
[$crate] $alloc $arbitrary1 $bytemuck1 $serde1 $std $zerocopy06 $step_trait $d($d tt)*
250+
[$crate] $alloc $arbitrary1 $bytemuck1 $serde1 $std $zerocopy $step_trait $d($d tt)*
251251
}
252252
};
253253
}

src/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ macro_rules! define_bounded_integers {
175175
#[cfg_attr(doc_cfg, doc(cfg(feature = "types")))]
176176
#[repr(transparent)]
177177
#[derive(Debug, Hash, Clone, Copy, Eq, Ord)]
178-
#[cfg_attr(feature = "zerocopy06", derive(zerocopy06::AsBytes))]
178+
#[cfg_attr(feature = "zerocopy", derive(zerocopy::IntoBytes))]
179179
pub struct Bounded<const MIN: Inner, const MAX: Inner>(Inner);
180180

181181
impl<const MIN: Inner, const MAX: Inner> Bounded<MIN, MAX> {

0 commit comments

Comments
 (0)