diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-10-16 22:36:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-16 22:36:06 +0200 |
| commit | 0602d6484b32d8a74ebefa324651259f78fc5fda (patch) | |
| tree | f2897fad2022e56cd1b1c38a35155c5a21bec9bb | |
| parent | bdfc2627421f6393acc7fce493ba5dd56e947bb0 (diff) | |
| parent | ddd5e983d19b9cc08fd4e587a3b0a03b5e68e26c (diff) | |
| download | rust-0602d6484b32d8a74ebefa324651259f78fc5fda.tar.gz rust-0602d6484b32d8a74ebefa324651259f78fc5fda.zip | |
Rollup merge of #103109 - RalfJung:phantom-data-impl, r=thomcc
PhantomData: inline a macro that is used only once I suspect this macro used to have more uses, but right now it just obfuscates the code.
| -rw-r--r-- | library/core/src/marker.rs | 112 |
1 files changed, 53 insertions, 59 deletions
diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index d5ed52124e2..c43c4fff6ae 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -483,64 +483,6 @@ impl<T: ?Sized> !Sync for *const T {} #[stable(feature = "rust1", since = "1.0.0")] impl<T: ?Sized> !Sync for *mut T {} -macro_rules! impls { - ($t: ident) => { - #[stable(feature = "rust1", since = "1.0.0")] - impl<T: ?Sized> Hash for $t<T> { - #[inline] - fn hash<H: Hasher>(&self, _: &mut H) {} - } - - #[stable(feature = "rust1", since = "1.0.0")] - impl<T: ?Sized> cmp::PartialEq for $t<T> { - fn eq(&self, _other: &$t<T>) -> bool { - true - } - } - - #[stable(feature = "rust1", since = "1.0.0")] - impl<T: ?Sized> cmp::Eq for $t<T> {} - - #[stable(feature = "rust1", since = "1.0.0")] - impl<T: ?Sized> cmp::PartialOrd for $t<T> { - fn partial_cmp(&self, _other: &$t<T>) -> Option<cmp::Ordering> { - Option::Some(cmp::Ordering::Equal) - } - } - - #[stable(feature = "rust1", since = "1.0.0")] - impl<T: ?Sized> cmp::Ord for $t<T> { - fn cmp(&self, _other: &$t<T>) -> cmp::Ordering { - cmp::Ordering::Equal - } - } - - #[stable(feature = "rust1", since = "1.0.0")] - impl<T: ?Sized> Copy for $t<T> {} - - #[stable(feature = "rust1", since = "1.0.0")] - impl<T: ?Sized> Clone for $t<T> { - fn clone(&self) -> Self { - Self - } - } - - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] - impl<T: ?Sized> const Default for $t<T> { - fn default() -> Self { - Self - } - } - - #[unstable(feature = "structural_match", issue = "31434")] - impl<T: ?Sized> StructuralPartialEq for $t<T> {} - - #[unstable(feature = "structural_match", issue = "31434")] - impl<T: ?Sized> StructuralEq for $t<T> {} - }; -} - /// Zero-sized type used to mark things that "act like" they own a `T`. /// /// Adding a `PhantomData<T>` field to your type tells the compiler that your @@ -678,7 +620,59 @@ macro_rules! impls { #[stable(feature = "rust1", since = "1.0.0")] pub struct PhantomData<T: ?Sized>; -impls! { PhantomData } +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: ?Sized> Hash for PhantomData<T> { + #[inline] + fn hash<H: Hasher>(&self, _: &mut H) {} +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: ?Sized> cmp::PartialEq for PhantomData<T> { + fn eq(&self, _other: &PhantomData<T>) -> bool { + true + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: ?Sized> cmp::Eq for PhantomData<T> {} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: ?Sized> cmp::PartialOrd for PhantomData<T> { + fn partial_cmp(&self, _other: &PhantomData<T>) -> Option<cmp::Ordering> { + Option::Some(cmp::Ordering::Equal) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: ?Sized> cmp::Ord for PhantomData<T> { + fn cmp(&self, _other: &PhantomData<T>) -> cmp::Ordering { + cmp::Ordering::Equal + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: ?Sized> Copy for PhantomData<T> {} + +#[stable(feature = "rust1", since = "1.0.0")] +impl<T: ?Sized> Clone for PhantomData<T> { + fn clone(&self) -> Self { + Self + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] +impl<T: ?Sized> const Default for PhantomData<T> { + fn default() -> Self { + Self + } +} + +#[unstable(feature = "structural_match", issue = "31434")] +impl<T: ?Sized> StructuralPartialEq for PhantomData<T> {} + +#[unstable(feature = "structural_match", issue = "31434")] +impl<T: ?Sized> StructuralEq for PhantomData<T> {} mod impls { #[stable(feature = "rust1", since = "1.0.0")] |
