From ce10dd8bb19e54997fde82c07251a2c1bc3b154c Mon Sep 17 00:00:00 2001 From: Roland Fredenhagen Date: Tue, 18 Nov 2025 22:22:19 +0100 Subject: [PATCH 1/3] pin proc-macro2 for msrv --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 396bd55..8017b8c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -65,6 +65,7 @@ jobs: cargo update -p zeroize --precise 1.6.0 cargo update -p pretty_assertions --precise 1.4.0 cargo update -p glob --precise 0.3.2 + cargo update -p proc-macro2 --precise 1.0.80 - name: Build run: cargo build --workspace ${{ matrix.features }} @@ -126,6 +127,7 @@ jobs: run: | cargo update -p zeroize --precise 1.6.0 cargo update -p pretty_assertions --precise 1.4.0 + cargo update -p proc-macro2 --precise 1.0.80 - name: Build run: cargo build --target thumbv6m-none-eabi ${{ matrix.features }} -p ensure-no-std From e6673cea070b16b6b5e0e3f896e9d30b3a1daf4a Mon Sep 17 00:00:00 2001 From: Roland Fredenhagen Date: Tue, 18 Nov 2025 17:46:22 +0100 Subject: [PATCH 2/3] discriminant for C should fint in int/uint --- tests/discriminant.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/discriminant.rs b/tests/discriminant.rs index 673dfc0..be31ce3 100644 --- a/tests/discriminant.rs +++ b/tests/discriminant.rs @@ -504,7 +504,7 @@ fn repr_c_negative() { #[derive_where(PartialEq, PartialOrd)] #[repr(C)] enum Test { - A = -0x8000_0000_0000_0000_isize, + A = (-0x8000_0000_i32) as isize, B, #[allow(dead_code)] #[derive_where(incomparable)] @@ -533,7 +533,7 @@ fn repr_c_expr() { #[derive_where(PartialEq, PartialOrd)] #[repr(C)] enum Test { - A = isize::MAX - 2, + A = (u32::MAX - 2) as isize, B, #[allow(dead_code)] #[derive_where(incomparable)] From e94ab4b2716273030ab33d33e075ba74c2e55254 Mon Sep 17 00:00:00 2001 From: Roland Fredenhagen Date: Tue, 18 Nov 2025 17:39:12 +0100 Subject: [PATCH 3/3] generate code using fqt for bool --- src/item.rs | 8 ++- src/test/basic.rs | 8 +-- src/test/bound.rs | 4 +- src/test/discriminant.rs | 152 +++++++++++++++++++-------------------- src/test/enum_.rs | 18 ++--- src/test/incomparable.rs | 20 +++--- src/test/partial_ord.rs | 2 +- src/test/skip.rs | 4 +- src/trait_/common_ord.rs | 4 +- src/trait_/partial_eq.rs | 2 +- tests/hygiene.rs | 19 ++++- 11 files changed, 130 insertions(+), 111 deletions(-) diff --git a/src/item.rs b/src/item.rs index e94f82f..304e8da 100644 --- a/src/item.rs +++ b/src/item.rs @@ -3,8 +3,8 @@ use proc_macro2::Ident; #[cfg(not(feature = "nightly"))] use { - proc_macro2::{Span, TokenStream, TokenTree}, - quote::ToTokens, + proc_macro2::{Span, TokenStream}, + quote::{quote, ToTokens}, syn::{punctuated::Punctuated, spanned::Spanned, Attribute, Meta, Result, Token, Variant}, }; @@ -252,7 +252,9 @@ impl Representation { Representation::ISize => "isize", }; - TokenTree::from(Ident::new(ident, Span::call_site())).into() + let ident = Ident::new(ident, Span::call_site()); + + quote! {::core::primitive::#ident} } } diff --git a/src/test/basic.rs b/src/test/basic.rs index 6256922..1bb22ef 100644 --- a/src/test/basic.rs +++ b/src/test/basic.rs @@ -89,7 +89,7 @@ fn struct_() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { match (self, __other) { (Test { field: ref __field_field }, Test { field: ref __other_field_field }) => true && ::core::cmp::PartialEq::eq(__field_field, __other_field_field), @@ -192,7 +192,7 @@ fn tuple() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { match (self, __other) { (Test(ref __field_0), Test(ref __other_field_0)) => true && ::core::cmp::PartialEq::eq(__field_0, __other_field_0), @@ -229,7 +229,7 @@ fn enum_() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A { field: ref __field_field } => 0, Test::B { } => 1, @@ -374,7 +374,7 @@ fn enum_() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { match (self, __other) { (Test::A { field: ref __field_field }, Test::A { field: ref __other_field_field }) => diff --git a/src/test/bound.rs b/src/test/bound.rs index c9bcfb4..489d490 100644 --- a/src/test/bound.rs +++ b/src/test/bound.rs @@ -296,7 +296,7 @@ fn check_trait_bounds() -> Result<()> { where T: ::core::cmp::PartialEq { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { match (self, __other) { (Test(ref __field_0, ref __field_1), Test(ref __other_field_0, ref __other_field_1)) => true @@ -457,7 +457,7 @@ fn check_multiple_trait_bounds() -> Result<()> { U: ::core::cmp::PartialEq { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { match (self, __other) { (Test(ref __field_0, ref __field_1), Test(ref __other_field_0, ref __other_field_1)) => true diff --git a/src/test/discriminant.rs b/src/test/discriminant.rs index 6f4fa54..caf392e 100644 --- a/src/test/discriminant.rs +++ b/src/test/discriminant.rs @@ -14,7 +14,7 @@ fn default() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A => 0, Test::B => (0) + 1, @@ -62,7 +62,7 @@ fn default_clone() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - ::core::cmp::PartialOrd::partial_cmp(&(::core::clone::Clone::clone(self) as isize), &(::core::clone::Clone::clone(__other) as isize)) + ::core::cmp::PartialOrd::partial_cmp(&(::core::clone::Clone::clone(self) as ::core::primitive::isize), &(::core::clone::Clone::clone(__other) as ::core::primitive::isize)) }; test_derive( @@ -114,7 +114,7 @@ fn default_copy() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - ::core::cmp::PartialOrd::partial_cmp(&(*self as isize), &(*__other as isize)) + ::core::cmp::PartialOrd::partial_cmp(&(*self as ::core::primitive::isize), &(*__other as ::core::primitive::isize)) }; test_derive( @@ -157,7 +157,7 @@ fn default_reverse() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A => 2, Test::B => 1, @@ -205,7 +205,7 @@ fn default_mix() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A => 1, Test::B => 0, @@ -255,7 +255,7 @@ fn default_skip() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A => 0, Test::B => 3, @@ -307,7 +307,7 @@ fn default_expr() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A => isize::MAX - 2, Test::B => (isize::MAX - 2) + 1, @@ -355,7 +355,7 @@ fn repr_c() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A => 0, Test::B => (0) + 1, @@ -404,7 +404,7 @@ fn repr_c_without_discriminant() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A => 0, Test::B => 1, @@ -453,7 +453,7 @@ fn repr_c_clone() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - ::core::cmp::PartialOrd::partial_cmp(&(::core::clone::Clone::clone(self) as isize), &(::core::clone::Clone::clone(__other) as isize)) + ::core::cmp::PartialOrd::partial_cmp(&(::core::clone::Clone::clone(self) as ::core::primitive::isize), &(::core::clone::Clone::clone(__other) as ::core::primitive::isize)) }; test_derive( @@ -506,7 +506,7 @@ fn repr_c_clone_without_discriminant() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - ::core::cmp::PartialOrd::partial_cmp(&(::core::clone::Clone::clone(self) as isize), &(::core::clone::Clone::clone(__other) as isize)) + ::core::cmp::PartialOrd::partial_cmp(&(::core::clone::Clone::clone(self) as ::core::primitive::isize), &(::core::clone::Clone::clone(__other) as ::core::primitive::isize)) }; test_derive( @@ -559,7 +559,7 @@ fn repr_c_copy() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - ::core::cmp::PartialOrd::partial_cmp(&(*self as isize), &(*__other as isize)) + ::core::cmp::PartialOrd::partial_cmp(&(*self as ::core::primitive::isize), &(*__other as ::core::primitive::isize)) }; test_derive( @@ -603,7 +603,7 @@ fn repr_c_copy_without_discriminant() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - ::core::cmp::PartialOrd::partial_cmp(&(*self as isize), &(*__other as isize)) + ::core::cmp::PartialOrd::partial_cmp(&(*self as ::core::primitive::isize), &(*__other as ::core::primitive::isize)) }; test_derive( @@ -647,7 +647,7 @@ fn repr_c_reverse() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A => 2, Test::B => 1, @@ -696,7 +696,7 @@ fn repr_c_mix() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A => 1, Test::B => 0, @@ -747,7 +747,7 @@ fn repr_c_skip() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A => 0, Test::B => 3, @@ -800,11 +800,11 @@ fn repr_c_expr() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { - Test::A => isize::MAX - 2, - Test::B => (isize::MAX - 2) + 1, - Test::C => (isize::MAX - 2) + 2 + Test::A => ::core::primitive::isize::MAX - 2, + Test::B => (::core::primitive::isize::MAX - 2) + 1, + Test::C => (::core::primitive::isize::MAX - 2) + 2 } } @@ -816,7 +816,7 @@ fn repr_c_expr() -> Result<()> { #[derive_where(PartialOrd)] #[repr(C)] enum Test { - A = isize::MAX - 2, + A = ::core::primitive::isize::MAX - 2, B, #[derive_where(incomparable)] C, @@ -857,13 +857,13 @@ fn repr_c_with_value() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u8>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u8>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u8 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u8 { match __this { Test::A(ref __field_0) => 0, Test::B => (0) + 1, @@ -928,13 +928,13 @@ fn repr_c_with_value_reverse() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u8>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u8>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u8 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u8 { match __this { Test::A(ref __field_0) => 2, Test::B => 1, @@ -999,13 +999,13 @@ fn repr_c_with_value_mix() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u8>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u8>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u8 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u8 { match __this { Test::A(ref __field_0) => 1, Test::B => 0, @@ -1070,13 +1070,13 @@ fn repr_c_with_value_skip() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u8>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u8>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u8 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u8 { match __this { Test::A(ref __field_0) => 0, Test::B => 3, @@ -1143,17 +1143,17 @@ fn repr_c_with_value_expr() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u8>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u8>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u8 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u8 { match __this { - Test::A(ref __field_0) => isize::MAX - 2, - Test::B => (isize::MAX - 2) + 1, - Test::C => (isize::MAX - 2) + 2 + Test::A(ref __field_0) => ::core::primitive::isize::MAX - 2, + Test::B => (::core::primitive::isize::MAX - 2) + 1, + Test::C => (::core::primitive::isize::MAX - 2) + 2 } } @@ -1165,7 +1165,7 @@ fn repr_c_with_value_expr() -> Result<()> { #[derive_where(PartialOrd)] #[repr(C, u8)] enum Test { - A(std::marker::PhantomData) = isize::MAX - 2, + A(std::marker::PhantomData) = ::core::primitive::isize::MAX - 2, B, C, } @@ -1207,13 +1207,13 @@ fn repr() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u64>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u64>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u64 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u64 { match __this { Test::A => 0, Test::B => (0) + 1, @@ -1262,7 +1262,7 @@ fn repr_clone() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - ::core::cmp::PartialOrd::partial_cmp(&(::core::clone::Clone::clone(self) as u64), &(::core::clone::Clone::clone(__other) as u64)) + ::core::cmp::PartialOrd::partial_cmp(&(::core::clone::Clone::clone(self) as ::core::primitive::u64), &(::core::clone::Clone::clone(__other) as ::core::primitive::u64)) }; test_derive( @@ -1315,7 +1315,7 @@ fn repr_copy() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - ::core::cmp::PartialOrd::partial_cmp(&(*self as u64), &(*__other as u64)) + ::core::cmp::PartialOrd::partial_cmp(&(*self as ::core::primitive::u64), &(*__other as ::core::primitive::u64)) }; test_derive( @@ -1360,13 +1360,13 @@ fn repr_reverse() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u64>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u64>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u64 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u64 { match __this { Test::A => 2, Test::B => 1, @@ -1416,13 +1416,13 @@ fn repr_mix() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u64>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u64>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u64 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u64 { match __this { Test::A => 1, Test::B => 0, @@ -1474,13 +1474,13 @@ fn repr_skip() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u64>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u64>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u64 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u64 { match __this { Test::A => 0, Test::B => 3, @@ -1534,17 +1534,17 @@ fn repr_expr() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u64>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u64>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u64 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u64 { match __this { - Test::A => u64::MAX - 2, - Test::B => (u64::MAX - 2) + 1, - Test::C => (u64::MAX - 2) + 2 + Test::A => ::core::primitive::u64::MAX - 2, + Test::B => (::core::primitive::u64::MAX - 2) + 1, + Test::C => (::core::primitive::u64::MAX - 2) + 2 } } @@ -1556,7 +1556,7 @@ fn repr_expr() -> Result<()> { #[derive_where(PartialOrd)] #[repr(u64)] enum Test { - A = u64::MAX - 2, + A = ::core::primitive::u64::MAX - 2, B, #[derive_where(incomparable)] C, @@ -1597,13 +1597,13 @@ fn repr_with_value() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u8>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u8>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u8 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u8 { match __this { Test::A(ref __field_0) => 0, Test::B => (0) + 1, @@ -1668,13 +1668,13 @@ fn repr_with_value_reverse() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u8>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u8>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u8 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u8 { match __this { Test::A(ref __field_0) => 2, Test::B => 1, @@ -1739,13 +1739,13 @@ fn repr_with_value_mix() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u8>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u8>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u8 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u8 { match __this { Test::A(ref __field_0) => 1, Test::B => 0, @@ -1810,13 +1810,13 @@ fn repr_with_value_skip() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u8>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u8>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u8 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u8 { match __this { Test::A(ref __field_0) => 0, Test::B => 3, @@ -1883,13 +1883,13 @@ fn repr_with_value_expr() -> Result<()> { #[cfg(not(any(feature = "nightly", feature = "safe")))] let partial_ord = quote! { ::core::cmp::PartialOrd::partial_cmp( - &unsafe { *<*const _>::from(self).cast::() }, - &unsafe { *<*const _>::from(__other).cast::() }, + &unsafe { *<*const _>::from(self).cast::<::core::primitive::u8>() }, + &unsafe { *<*const _>::from(__other).cast::<::core::primitive::u8>() }, ) }; #[cfg(all(not(feature = "nightly"), feature = "safe"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> u8 { + const fn __discriminant(__this: &Test) -> ::core::primitive::u8 { match __this { Test::A(ref __field_0) => isize::MAX - 2, Test::B => (isize::MAX - 2) + 1, diff --git a/src/test/enum_.rs b/src/test/enum_.rs index c048af8..386e5b3 100644 --- a/src/test/enum_.rs +++ b/src/test/enum_.rs @@ -86,7 +86,7 @@ fn one_data() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { match (self, __other) { (Test::A(ref __field_0), Test::A(ref __other_field_0)) => true && ::core::cmp::PartialEq::eq(__field_0, __other_field_0), @@ -133,7 +133,7 @@ fn two_data() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A(ref __field_0) => 0, Test::B(ref __field_0) => 1 @@ -155,7 +155,7 @@ fn two_data() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { match (self, __other) { (Test::A(ref __field_0), Test::A(ref __other_field_0)) => @@ -217,7 +217,7 @@ fn unit() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A(ref __field_0) => 0, Test::B => 1 @@ -239,7 +239,7 @@ fn unit() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { match (self, __other) { (Test::A(ref __field_0), Test::A(ref __other_field_0)) => @@ -294,7 +294,7 @@ fn struct_unit() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A(ref __field_0) => 0, Test::B { } => 1 @@ -316,7 +316,7 @@ fn struct_unit() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { match (self, __other) { (Test::A(ref __field_0), Test::A(ref __other_field_0)) => @@ -371,7 +371,7 @@ fn tuple_unit() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A(ref __field_0) => 0, Test::B() => 1 @@ -393,7 +393,7 @@ fn tuple_unit() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { match (self, __other) { (Test::A(ref __field_0), Test::A(ref __other_field_0)) => diff --git a/src/test/incomparable.rs b/src/test/incomparable.rs index d306d29..f4a0a62 100644 --- a/src/test/incomparable.rs +++ b/src/test/incomparable.rs @@ -23,7 +23,7 @@ fn variants() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { match (self, __other) { (Test::C(ref __field_0), Test::C(ref __other_field_0)) => true && ::core::cmp::PartialEq::eq(__field_0, __other_field_0), @@ -58,7 +58,7 @@ fn variants() -> Result<()> { _ => ::core::option::Option::Some(::core::cmp::Ordering::Equal), } } else { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A => 0, Test::B(ref __field_0) => 1, @@ -91,7 +91,7 @@ fn enum_empty_and_empty_incomparable_variants() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { if ::core::matches!(self, Test::A) { return false; @@ -133,7 +133,7 @@ fn enum_empty_and_non_empty_incomparable_variants() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { match (self , __other) { (Test::A (..) , ..) => false, @@ -177,7 +177,7 @@ fn enum_empty_and_multiple_incomparable_variants() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { match (self, __other) { (Test::A | Test::C(..), ..) => false, @@ -222,7 +222,7 @@ fn enum_skipped_and_incomparable_variant() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { if ::core::matches!(self, Test::A) { return false; @@ -264,7 +264,7 @@ fn enum_non_empty_and_incomparable_variant() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { match (self, __other) { (Test::B(ref __field_0), Test::B(ref __other_field_0)) => @@ -316,7 +316,7 @@ fn enum_incomparable_and_skipped_variant() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { if ::core::mem::discriminant(self) == ::core::mem::discriminant(__other) { if ::core::matches!(self, Test::A(..)) { return false; @@ -355,7 +355,7 @@ fn items() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { false } } @@ -379,7 +379,7 @@ fn items() -> Result<()> { #[automatically_derived] impl ::core::cmp::PartialEq for Test { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { false } } diff --git a/src/test/partial_ord.rs b/src/test/partial_ord.rs index 3c32808..4b5ece4 100644 --- a/src/test/partial_ord.rs +++ b/src/test/partial_ord.rs @@ -73,7 +73,7 @@ fn enum_() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let partial_ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A { field: ref __field_field } => 0, Test::B { } => 1, diff --git a/src/test/skip.rs b/src/test/skip.rs index 9d2e534..8528ba0 100644 --- a/src/test/skip.rs +++ b/src/test/skip.rs @@ -106,7 +106,7 @@ fn variants_empty() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A(ref __field_0) => 0, Test::B(ref __field_0) => 1 @@ -156,7 +156,7 @@ fn variants_partly_empty() -> Result<()> { }; #[cfg(not(feature = "nightly"))] let ord = quote! { - const fn __discriminant(__this: &Test) -> isize { + const fn __discriminant(__this: &Test) -> ::core::primitive::isize { match __this { Test::A(ref __field_0) => 0, Test::B(ref __field_0, ref __field_1) => 1 diff --git a/src/trait_/common_ord.rs b/src/trait_/common_ord.rs index f13bdf7..6a999e7 100644 --- a/src/trait_/common_ord.rs +++ b/src/trait_/common_ord.rs @@ -147,12 +147,12 @@ pub fn build_ord_signature( Discriminant::Unit => { if derive_where.contains(Trait::Copy) { quote! { - #path::#method(&(*self as isize), &(*__other as isize)) + #path::#method(&(*self as ::core::primitive::isize), &(*__other as ::core::primitive::isize)) } } else if derive_where.contains(Trait::Clone) { let clone = DeriveTrait::Clone.path(); quote! { - #path::#method(&(#clone::clone(self) as isize), &(#clone::clone(__other) as isize)) + #path::#method(&(#clone::clone(self) as ::core::primitive::isize), &(#clone::clone(__other) as ::core::primitive::isize)) } } else { build_discriminant_order( diff --git a/src/trait_/partial_eq.rs b/src/trait_/partial_eq.rs index 241d230..733f219 100644 --- a/src/trait_/partial_eq.rs +++ b/src/trait_/partial_eq.rs @@ -104,7 +104,7 @@ impl TraitImpl for PartialEq { quote! { #[inline] - fn eq(&self, __other: &Self) -> bool { + fn eq(&self, __other: &Self) -> ::core::primitive::bool { #body } } diff --git a/tests/hygiene.rs b/tests/hygiene.rs index bde728f..3cc42e3 100644 --- a/tests/hygiene.rs +++ b/tests/hygiene.rs @@ -15,6 +15,12 @@ use self::util::{ AssertPartialOrd, Wrapper, }; +#[allow(non_camel_case_types, unused)] +struct bool; + +#[allow(non_camel_case_types, unused)] +struct isize; + trait Clone { fn clone(&self) -> Self; } @@ -85,7 +91,7 @@ where impl PartialOrd for T {} #[test] -fn test() { +fn test_struct() { #[derive_where(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] struct Test(Wrapper); @@ -131,3 +137,14 @@ fn test() { assert!(test_1 > Test(41.into())); assert!(test_1 < test_ge); } + +#[test] +fn test_enum() { + #[derive_where(Ord, PartialOrd, PartialEq, Eq)] + enum Test { + A, + B, + C, + D(Wrapper), + }; +}