Use impl Tag for $T syntax for impl_tag!

This commit is contained in:
Maybe Waffle 2023-04-20 18:49:40 +00:00
parent 77c83c0965
commit 96905d568a
3 changed files with 12 additions and 12 deletions

View File

@ -23,7 +23,7 @@
/// ///
/// impl_tag! { /// impl_tag! {
/// // The type for which the `Tag` will be implemented /// // The type for which the `Tag` will be implemented
/// for SomeTag; /// impl Tag for SomeTag;
/// // You need to specify the `{value_of_the_type} <=> {tag}` relationship /// // You need to specify the `{value_of_the_type} <=> {tag}` relationship
/// SomeTag::A <=> 0, /// SomeTag::A <=> 0,
/// SomeTag::B <=> 1, /// SomeTag::B <=> 1,
@ -54,7 +54,7 @@
/// struct Flags { a: bool, b: bool } /// struct Flags { a: bool, b: bool }
/// ///
/// impl_tag! { /// impl_tag! {
/// for Flags; /// impl Tag for Flags;
/// Flags { a: true, b: true } <=> 3, /// Flags { a: true, b: true } <=> 3,
/// Flags { a: false, b: true } <=> 2, /// Flags { a: false, b: true } <=> 2,
/// Flags { a: true, b: false } <=> 1, /// Flags { a: true, b: false } <=> 1,
@ -73,7 +73,7 @@
// struct Unit; // struct Unit;
// //
// impl_tag! { // impl_tag! {
// for Unit; // impl Tag for Unit;
// Unit <=> 0, // Unit <=> 0,
// Unit <=> 1, // Unit <=> 1,
// } // }
@ -87,7 +87,7 @@
// enum E { A, B }; // enum E { A, B };
// //
// impl_tag! { // impl_tag! {
// for E; // impl Tag for E;
// E::A <=> 0, // E::A <=> 0,
// E::B <=> 0, // E::B <=> 0,
// } // }
@ -104,14 +104,14 @@
/// } /// }
/// ///
/// impl_tag! { /// impl_tag! {
/// for E; /// impl Tag for E;
/// E::A <=> 0, /// E::A <=> 0,
/// } /// }
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! impl_tag { macro_rules! impl_tag {
( (
for $Self:ty; impl Tag for $Self:ty;
$( $(
$($path:ident)::* $( { $( $fields:tt )* })? <=> $tag:literal, $($path:ident)::* $( { $( $fields:tt )* })? <=> $tag:literal,
)* )*

View File

@ -4,22 +4,22 @@ fn bits_constant() {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct Unit; struct Unit;
impl_tag! { for Unit; Unit <=> 0, } impl_tag! { impl Tag for Unit; Unit <=> 0, }
assert_eq!(Unit::BITS, 0); assert_eq!(Unit::BITS, 0);
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct Unit1; struct Unit1;
impl_tag! { for Unit1; Unit1 <=> 1, } impl_tag! { impl Tag for Unit1; Unit1 <=> 1, }
assert_eq!(Unit1::BITS, 1); assert_eq!(Unit1::BITS, 1);
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct Unit2; struct Unit2;
impl_tag! { for Unit2; Unit2 <=> 0b10, } impl_tag! { impl Tag for Unit2; Unit2 <=> 0b10, }
assert_eq!(Unit2::BITS, 2); assert_eq!(Unit2::BITS, 2);
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct Unit3; struct Unit3;
impl_tag! { for Unit3; Unit3 <=> 0b100, } impl_tag! { impl Tag for Unit3; Unit3 <=> 0b100, }
assert_eq!(Unit3::BITS, 3); assert_eq!(Unit3::BITS, 3);
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -28,6 +28,6 @@ enum Enum {
B, B,
C, C,
} }
impl_tag! { for Enum; Enum::A <=> 0b1, Enum::B <=> 0b1000, Enum::C <=> 0b10, } impl_tag! { impl Tag for Enum; Enum::A <=> 0b1, Enum::B <=> 0b1000, Enum::C <=> 0b10, }
assert_eq!(Enum::BITS, 4); assert_eq!(Enum::BITS, 4);
} }

View File

@ -1627,7 +1627,7 @@ struct ParamTag {
} }
impl_tag! { impl_tag! {
for ParamTag; impl Tag for ParamTag;
ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::NotConst } <=> 0, ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::NotConst } <=> 0,
ParamTag { reveal: traits::Reveal::All, constness: hir::Constness::NotConst } <=> 1, ParamTag { reveal: traits::Reveal::All, constness: hir::Constness::NotConst } <=> 1,
ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::Const } <=> 2, ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::Const } <=> 2,