diff --git a/src/lib.rs b/src/lib.rs index c926c25183..e03495448e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -228,6 +228,13 @@ __INTERNAL_USE_ONLY_NIGHLTY_FEATURES_IN_TESTS, feature(layout_for_ptr, strict_provenance) )] + +// This is a hack to allow zerocopy-derive derives to work in this crate. They +// assume that zerocopy is linked as an extern crate, so they access items from +// it as `zerocopy::Xxx`. This makes that still work. +#[cfg(any(feature = "derive", test))] +extern crate self as zerocopy; + #[macro_use] mod macros; @@ -290,14 +297,6 @@ use { #[allow(unused_imports)] use crate::util::polyfills::NonNullExt as _; -// This is a hack to allow zerocopy-derive derives to work in this crate. They -// assume that zerocopy is linked as an extern crate, so they access items from -// it as `zerocopy::Xxx`. This makes that still work. -#[cfg(any(feature = "derive", test))] -mod zerocopy { - pub(crate) use crate::*; -} - #[rustversion::nightly] #[cfg(all(test, not(__INTERNAL_USE_ONLY_NIGHLTY_FEATURES_IN_TESTS)))] const _: () = { diff --git a/zerocopy-derive/src/lib.rs b/zerocopy-derive/src/lib.rs index 9bdc997472..2d7ec65427 100644 --- a/zerocopy-derive/src/lib.rs +++ b/zerocopy-derive/src/lib.rs @@ -549,7 +549,7 @@ fn impl_block( let field_types = data.field_types(); let field_type_bounds = require_trait_bound_on_field_types - .then(|| field_types.iter().map(|ty| parse_quote!(#ty: zerocopy::#trait_ident))) + .then(|| field_types.iter().map(|ty| parse_quote!(#ty: ::zerocopy::#trait_ident))) .into_iter() .flatten() .collect::>(); @@ -560,8 +560,8 @@ fn impl_block( let fields = field_types.iter(); let validator_macro = check.validator_macro_ident(); parse_quote!( - zerocopy::macro_util::HasPadding<#type_ident, {zerocopy::#validator_macro!(#type_ident, #(#fields),*)}>: - zerocopy::macro_util::ShouldBe + ::zerocopy::macro_util::HasPadding<#type_ident, {::zerocopy::#validator_macro!(#type_ident, #(#fields),*)}>: + ::zerocopy::macro_util::ShouldBe ) }); @@ -579,7 +579,7 @@ fn impl_block( // We currently only support deriving for sized types; this code will // fail to compile for unsized types. Some(quote!( - const LAYOUT: zerocopy::DstLayout = zerocopy::DstLayout::for_type::(); + const LAYOUT: ::zerocopy::DstLayout = ::zerocopy::DstLayout::for_type::(); // SAFETY: `.cast` preserves address and provenance. // @@ -620,7 +620,7 @@ fn impl_block( // TODO(#553): Add a test that generates a warning when // `#[allow(deprecated)]` isn't present. #[allow(deprecated)] - unsafe impl < #(#params),* > zerocopy::#trait_ident for #type_ident < #(#param_idents),* > + unsafe impl < #(#params),* > ::zerocopy::#trait_ident for #type_ident < #(#param_idents),* > where #(#bounds,)* {