Skip to content

Commit

Permalink
Give built-in macros stable addresses in the standard library
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Aug 9, 2019
1 parent 534b423 commit cbcc7dd
Show file tree
Hide file tree
Showing 16 changed files with 364 additions and 164 deletions.
8 changes: 8 additions & 0 deletions src/libcore/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ pub trait Clone : Sized {
}
}

/// Derive macro generating an impl of the trait `Clone`.
#[cfg(not(bootstrap))]
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow_internal_unstable(core_intrinsics, derive_clone_copy)]
pub macro Clone($item:item) { /* compiler built-in */ }

// FIXME(aburka): these structs are used solely by #[derive] to
// assert that every component of a type implements Clone or Copy.
//
Expand Down
32 changes: 32 additions & 0 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ pub trait PartialEq<Rhs: ?Sized = Self> {
fn ne(&self, other: &Rhs) -> bool { !self.eq(other) }
}

/// Derive macro generating an impl of the trait `PartialEq`.
#[cfg(not(bootstrap))]
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow_internal_unstable(core_intrinsics)]
pub macro PartialEq($item:item) { /* compiler built-in */ }

/// Trait for equality comparisons which are [equivalence relations](
/// https://en.wikipedia.org/wiki/Equivalence_relation).
///
Expand Down Expand Up @@ -256,6 +264,14 @@ pub trait Eq: PartialEq<Self> {
fn assert_receiver_is_total_eq(&self) {}
}

/// Derive macro generating an impl of the trait `Eq`.
#[cfg(not(bootstrap))]
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow_internal_unstable(core_intrinsics, derive_eq)]
pub macro Eq($item:item) { /* compiler built-in */ }

// FIXME: this struct is used solely by #[derive] to
// assert that every component of a type implements Eq.
//
Expand Down Expand Up @@ -600,6 +616,14 @@ pub trait Ord: Eq + PartialOrd<Self> {
}
}

/// Derive macro generating an impl of the trait `Ord`.
#[cfg(not(bootstrap))]
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow_internal_unstable(core_intrinsics)]
pub macro Ord($item:item) { /* compiler built-in */ }

#[stable(feature = "rust1", since = "1.0.0")]
impl Eq for Ordering {}

Expand Down Expand Up @@ -842,6 +866,14 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
}
}

/// Derive macro generating an impl of the trait `PartialOrd`.
#[cfg(not(bootstrap))]
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow_internal_unstable(core_intrinsics)]
pub macro PartialOrd($item:item) { /* compiler built-in */ }

/// Compares and returns the minimum of two values.
///
/// Returns the first argument if the comparison determines them to be equal.
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ pub trait Default: Sized {
fn default() -> Self;
}

/// Derive macro generating an impl of the trait `Default`.
#[cfg(not(bootstrap))]
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow_internal_unstable(core_intrinsics)]
pub macro Default($item:item) { /* compiler built-in */ }

macro_rules! default_impl {
($t:ty, $v:expr, $doc:tt) => {
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
15 changes: 15 additions & 0 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,21 @@ pub trait Debug {
fn fmt(&self, f: &mut Formatter<'_>) -> Result;
}

// Separate module to reexport the macro `Debug` from prelude without the trait `Debug`.
#[cfg(not(bootstrap))]
pub(crate) mod macros {
/// Derive macro generating an impl of the trait `Debug`.
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow_internal_unstable(core_intrinsics)]
pub macro Debug($item:item) { /* compiler built-in */ }
}
#[cfg(not(bootstrap))]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[doc(inline)]
pub use macros::Debug;

/// Format trait for an empty format, `{}`.
///
/// `Display` is similar to [`Debug`][debug], but `Display` is for user-facing
Expand Down
15 changes: 15 additions & 0 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ pub trait Hash {
}
}

// Separate module to reexport the macro `Hash` from prelude without the trait `Hash`.
#[cfg(not(bootstrap))]
pub(crate) mod macros {
/// Derive macro generating an impl of the trait `Hash`.
#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow_internal_unstable(core_intrinsics)]
pub macro Hash($item:item) { /* compiler built-in */ }
}
#[cfg(not(bootstrap))]
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[doc(inline)]
pub use macros::Hash;

/// A trait for hashing an arbitrary stream of bytes.
///
/// Instances of `Hasher` usually represent state that is changed while hashing
Expand Down
Loading

0 comments on commit cbcc7dd

Please sign in to comment.