Skip to content

Commit 4ca22fa

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`, and change to using global paths for all uses of `core`. Link: #4038 [1] (backport <#4158>) (cherry picked from commit d69ad56)
1 parent 0acb8d6 commit 4ca22fa

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/lib.rs

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

src/macros.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ macro_rules! prelude {
7070
mod prelude {
7171
// Exports from `core`
7272
#[allow(unused_imports)]
73-
pub(crate) use core::clone::Clone;
73+
pub(crate) use ::core::clone::Clone;
7474
#[allow(unused_imports)]
75-
pub(crate) use core::marker::{Copy, Send, Sync};
75+
pub(crate) use ::core::marker::{Copy, Send, Sync};
7676
#[allow(unused_imports)]
77-
pub(crate) use core::option::Option;
77+
pub(crate) use ::core::option::Option;
7878
#[allow(unused_imports)]
79-
pub(crate) use core::{fmt, hash, iter, mem};
79+
pub(crate) use ::core::{fmt, hash, iter, mem};
8080

8181
// Commonly used types defined in this crate
8282
#[allow(unused_imports)]
@@ -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)