Skip to content

Commit a38cbcf

Browse files
authored
Rollup merge of rust-lang#63056 - petrochenkov:macstd2, r=alexcrichton
Give built-in macros stable addresses in the standard library Continuation of rust-lang#62086. Derive macros corresponding to traits from libcore are now available through the same paths as those traits: - `Clone` - `{core,std}::clone::Clone` - `PartialEq` - `{core,std}::cmp::PartialEq` - `Eq` - `{core,std}::cmp::Eq` - `PartialOrd` - `{core,std}::cmp::PartialOrd` - `Ord` - `{core,std}::cmp::Ord` - `Default` - `{core,std}::default::Default` - `Debug` - `{core,std}::fmt::Debug` - `Hash` - `{core,std}::hash::Hash` - `Copy` - `{core,std}::marker::Copy` Fn-like built-in macros are now available through libcore and libstd's root module, by analogy with non-builtin macros defined by libcore and libstd: ```rust {core,std}::{ __rust_unstable_column, asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, format_args_nl, global_asm, include, include_bytes, include_str, line, log_syntax, module_path, option_env, stringify, trace_macros, } ``` Derive macros without a corresponding trait in libcore or libstd are still available only through prelude (also see rust-lang#62507). Attribute macros also keep being available only through prelude, mostly because they don't have an existing practice to follow. An advice from the library team on their eventual placement would be appreciated. ```rust RustcDecodable, RustcEncodable, bench, global_allocator, test, test_case, ``` r? @alexcrichton
2 parents be8bbb0 + cbcc7dd commit a38cbcf

16 files changed

+364
-164
lines changed

src/libcore/clone.rs

+8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ pub trait Clone : Sized {
133133
}
134134
}
135135

136+
/// Derive macro generating an impl of the trait `Clone`.
137+
#[cfg(not(bootstrap))]
138+
#[rustc_builtin_macro]
139+
#[rustc_macro_transparency = "semitransparent"]
140+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
141+
#[allow_internal_unstable(core_intrinsics, derive_clone_copy)]
142+
pub macro Clone($item:item) { /* compiler built-in */ }
143+
136144
// FIXME(aburka): these structs are used solely by #[derive] to
137145
// assert that every component of a type implements Clone or Copy.
138146
//

src/libcore/cmp.rs

+32
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ pub trait PartialEq<Rhs: ?Sized = Self> {
200200
fn ne(&self, other: &Rhs) -> bool { !self.eq(other) }
201201
}
202202

203+
/// Derive macro generating an impl of the trait `PartialEq`.
204+
#[cfg(not(bootstrap))]
205+
#[rustc_builtin_macro]
206+
#[rustc_macro_transparency = "semitransparent"]
207+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
208+
#[allow_internal_unstable(core_intrinsics)]
209+
pub macro PartialEq($item:item) { /* compiler built-in */ }
210+
203211
/// Trait for equality comparisons which are [equivalence relations](
204212
/// https://en.wikipedia.org/wiki/Equivalence_relation).
205213
///
@@ -256,6 +264,14 @@ pub trait Eq: PartialEq<Self> {
256264
fn assert_receiver_is_total_eq(&self) {}
257265
}
258266

267+
/// Derive macro generating an impl of the trait `Eq`.
268+
#[cfg(not(bootstrap))]
269+
#[rustc_builtin_macro]
270+
#[rustc_macro_transparency = "semitransparent"]
271+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
272+
#[allow_internal_unstable(core_intrinsics, derive_eq)]
273+
pub macro Eq($item:item) { /* compiler built-in */ }
274+
259275
// FIXME: this struct is used solely by #[derive] to
260276
// assert that every component of a type implements Eq.
261277
//
@@ -600,6 +616,14 @@ pub trait Ord: Eq + PartialOrd<Self> {
600616
}
601617
}
602618

619+
/// Derive macro generating an impl of the trait `Ord`.
620+
#[cfg(not(bootstrap))]
621+
#[rustc_builtin_macro]
622+
#[rustc_macro_transparency = "semitransparent"]
623+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
624+
#[allow_internal_unstable(core_intrinsics)]
625+
pub macro Ord($item:item) { /* compiler built-in */ }
626+
603627
#[stable(feature = "rust1", since = "1.0.0")]
604628
impl Eq for Ordering {}
605629

@@ -842,6 +866,14 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
842866
}
843867
}
844868

869+
/// Derive macro generating an impl of the trait `PartialOrd`.
870+
#[cfg(not(bootstrap))]
871+
#[rustc_builtin_macro]
872+
#[rustc_macro_transparency = "semitransparent"]
873+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
874+
#[allow_internal_unstable(core_intrinsics)]
875+
pub macro PartialOrd($item:item) { /* compiler built-in */ }
876+
845877
/// Compares and returns the minimum of two values.
846878
///
847879
/// Returns the first argument if the comparison determines them to be equal.

src/libcore/default.rs

+8
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ pub trait Default: Sized {
115115
fn default() -> Self;
116116
}
117117

118+
/// Derive macro generating an impl of the trait `Default`.
119+
#[cfg(not(bootstrap))]
120+
#[rustc_builtin_macro]
121+
#[rustc_macro_transparency = "semitransparent"]
122+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
123+
#[allow_internal_unstable(core_intrinsics)]
124+
pub macro Default($item:item) { /* compiler built-in */ }
125+
118126
macro_rules! default_impl {
119127
($t:ty, $v:expr, $doc:tt) => {
120128
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/fmt/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,21 @@ pub trait Debug {
545545
fn fmt(&self, f: &mut Formatter<'_>) -> Result;
546546
}
547547

548+
// Separate module to reexport the macro `Debug` from prelude without the trait `Debug`.
549+
#[cfg(not(bootstrap))]
550+
pub(crate) mod macros {
551+
/// Derive macro generating an impl of the trait `Debug`.
552+
#[rustc_builtin_macro]
553+
#[rustc_macro_transparency = "semitransparent"]
554+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
555+
#[allow_internal_unstable(core_intrinsics)]
556+
pub macro Debug($item:item) { /* compiler built-in */ }
557+
}
558+
#[cfg(not(bootstrap))]
559+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
560+
#[doc(inline)]
561+
pub use macros::Debug;
562+
548563
/// Format trait for an empty format, `{}`.
549564
///
550565
/// `Display` is similar to [`Debug`][debug], but `Display` is for user-facing

src/libcore/hash/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,21 @@ pub trait Hash {
198198
}
199199
}
200200

201+
// Separate module to reexport the macro `Hash` from prelude without the trait `Hash`.
202+
#[cfg(not(bootstrap))]
203+
pub(crate) mod macros {
204+
/// Derive macro generating an impl of the trait `Hash`.
205+
#[rustc_builtin_macro]
206+
#[rustc_macro_transparency = "semitransparent"]
207+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
208+
#[allow_internal_unstable(core_intrinsics)]
209+
pub macro Hash($item:item) { /* compiler built-in */ }
210+
}
211+
#[cfg(not(bootstrap))]
212+
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
213+
#[doc(inline)]
214+
pub use macros::Hash;
215+
201216
/// A trait for hashing an arbitrary stream of bytes.
202217
///
203218
/// Instances of `Hasher` usually represent state that is changed while hashing

0 commit comments

Comments
 (0)