Skip to content

Commit

Permalink
Fix the build with rustc-dep-of-std
Browse files Browse the repository at this point in the history
Since [1] we use derive macros rather than manually implementing `Clone`
and `Copy`. However, this caused the build in `std` to start failing
since the `core` prelude is not available. This provides the derive
macros as well as `derive` itself.

Resolve this by using complete paths. Additionally allow
`internal_features` to suppress the warning using `link_cfg`.

Link: #4038 [1]
  • Loading branch information
tgross35 committed Nov 28, 2024
1 parent ca61220 commit 93cec56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#![cfg_attr(libc_deny_warnings, deny(warnings))]
// Attributes needed when building as part of the standard library
#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))]
#![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))]
// Enable extra lints:
#![cfg_attr(feature = "extra_traits", deny(missing_debug_implementations))]
#![deny(missing_copy_implementations, safe_packed_borrows)]
Expand Down
25 changes: 17 additions & 8 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ macro_rules! s {
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
__item! {
#[repr(C)]
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Copy, Clone)]
#[cfg_attr(
feature = "extra_traits",
core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
)]
#[core::prelude::v1::derive(core::clone::Clone, core::marker::Copy)]
#[allow(deprecated)]
$(#[$attr])*
pub struct $i { $($field)* }
Expand All @@ -127,8 +130,11 @@ macro_rules! s_paren {
pub struct $i:ident ( $($field:tt)* );
)*) => ($(
__item! {
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Copy, Clone)]
#[cfg_attr(
feature = "extra_traits",
core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
)]
#[core::prelude::v1::derive(core::clone::Clone, core::marker::Copy)]
$(#[$attr])*
pub struct $i ( $($field)* );
}
Expand All @@ -149,7 +155,7 @@ macro_rules! s_no_extra_traits {
(it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
__item! {
#[repr(C)]
#[derive(Copy, Clone)]
#[core::prelude::v1::derive(core::clone::Clone, core::marker::Copy)]
$(#[$attr])*
pub union $i { $($field)* }
}
Expand All @@ -158,7 +164,7 @@ macro_rules! s_no_extra_traits {
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
__item! {
#[repr(C)]
#[derive(Copy, Clone)]
#[core::prelude::v1::derive(core::clone::Clone, core::marker::Copy)]
$(#[$attr])*
pub struct $i { $($field)* }
}
Expand Down Expand Up @@ -186,8 +192,11 @@ macro_rules! e {
pub enum $i:ident { $($field:tt)* }
)*) => ($(
__item! {
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
#[derive(Copy, Clone)]
#[cfg_attr(
feature = "extra_traits",
core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
)]
#[core::prelude::v1::derive(core::clone::Clone, core::marker::Copy)]
$(#[$attr])*
pub enum $i { $($field)* }
}
Expand Down

0 comments on commit 93cec56

Please sign in to comment.