Skip to content

Give built-in macros stable addresses in the standard library #63056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/libcore/clone.rs
Original file line number Diff line number Diff line change
@@ -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.
//
32 changes: 32 additions & 0 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
@@ -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).
///
@@ -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.
//
@@ -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 {}

@@ -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.
8 changes: 8 additions & 0 deletions src/libcore/default.rs
Original file line number Diff line number Diff line change
@@ -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")]
15 changes: 15 additions & 0 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
@@ -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
Loading