Skip to content

Commit 93cec56

Browse files
committed
Fix the build with rustc-dep-of-std
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]
1 parent ca61220 commit 93cec56

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![cfg_attr(libc_deny_warnings, deny(warnings))]
2121
// Attributes needed when building as part of the standard library
2222
#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))]
23+
#![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))]
2324
// Enable extra lints:
2425
#![cfg_attr(feature = "extra_traits", deny(missing_debug_implementations))]
2526
#![deny(missing_copy_implementations, safe_packed_borrows)]

src/macros.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ macro_rules! s {
108108
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
109109
__item! {
110110
#[repr(C)]
111-
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
112-
#[derive(Copy, Clone)]
111+
#[cfg_attr(
112+
feature = "extra_traits",
113+
core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
114+
)]
115+
#[core::prelude::v1::derive(core::clone::Clone, core::marker::Copy)]
113116
#[allow(deprecated)]
114117
$(#[$attr])*
115118
pub struct $i { $($field)* }
@@ -127,8 +130,11 @@ macro_rules! s_paren {
127130
pub struct $i:ident ( $($field:tt)* );
128131
)*) => ($(
129132
__item! {
130-
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
131-
#[derive(Copy, Clone)]
133+
#[cfg_attr(
134+
feature = "extra_traits",
135+
core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
136+
)]
137+
#[core::prelude::v1::derive(core::clone::Clone, core::marker::Copy)]
132138
$(#[$attr])*
133139
pub struct $i ( $($field)* );
134140
}
@@ -149,7 +155,7 @@ macro_rules! s_no_extra_traits {
149155
(it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => (
150156
__item! {
151157
#[repr(C)]
152-
#[derive(Copy, Clone)]
158+
#[core::prelude::v1::derive(core::clone::Clone, core::marker::Copy)]
153159
$(#[$attr])*
154160
pub union $i { $($field)* }
155161
}
@@ -158,7 +164,7 @@ macro_rules! s_no_extra_traits {
158164
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
159165
__item! {
160166
#[repr(C)]
161-
#[derive(Copy, Clone)]
167+
#[core::prelude::v1::derive(core::clone::Clone, core::marker::Copy)]
162168
$(#[$attr])*
163169
pub struct $i { $($field)* }
164170
}
@@ -186,8 +192,11 @@ macro_rules! e {
186192
pub enum $i:ident { $($field:tt)* }
187193
)*) => ($(
188194
__item! {
189-
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
190-
#[derive(Copy, Clone)]
195+
#[cfg_attr(
196+
feature = "extra_traits",
197+
core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
198+
)]
199+
#[core::prelude::v1::derive(core::clone::Clone, core::marker::Copy)]
191200
$(#[$attr])*
192201
pub enum $i { $($field)* }
193202
}

0 commit comments

Comments
 (0)