mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Use impl Tag for $T
syntax for impl_tag!
This commit is contained in:
parent
77c83c0965
commit
96905d568a
@ -23,7 +23,7 @@
|
||||
///
|
||||
/// impl_tag! {
|
||||
/// // 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
|
||||
/// SomeTag::A <=> 0,
|
||||
/// SomeTag::B <=> 1,
|
||||
@ -54,7 +54,7 @@
|
||||
/// struct Flags { a: bool, b: bool }
|
||||
///
|
||||
/// impl_tag! {
|
||||
/// for Flags;
|
||||
/// impl Tag for Flags;
|
||||
/// Flags { a: true, b: true } <=> 3,
|
||||
/// Flags { a: false, b: true } <=> 2,
|
||||
/// Flags { a: true, b: false } <=> 1,
|
||||
@ -73,7 +73,7 @@
|
||||
// struct Unit;
|
||||
//
|
||||
// impl_tag! {
|
||||
// for Unit;
|
||||
// impl Tag for Unit;
|
||||
// Unit <=> 0,
|
||||
// Unit <=> 1,
|
||||
// }
|
||||
@ -87,7 +87,7 @@
|
||||
// enum E { A, B };
|
||||
//
|
||||
// impl_tag! {
|
||||
// for E;
|
||||
// impl Tag for E;
|
||||
// E::A <=> 0,
|
||||
// E::B <=> 0,
|
||||
// }
|
||||
@ -104,14 +104,14 @@
|
||||
/// }
|
||||
///
|
||||
/// impl_tag! {
|
||||
/// for E;
|
||||
/// impl Tag for E;
|
||||
/// E::A <=> 0,
|
||||
/// }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! impl_tag {
|
||||
(
|
||||
for $Self:ty;
|
||||
impl Tag for $Self:ty;
|
||||
$(
|
||||
$($path:ident)::* $( { $( $fields:tt )* })? <=> $tag:literal,
|
||||
)*
|
||||
|
@ -4,22 +4,22 @@ fn bits_constant() {
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Unit;
|
||||
impl_tag! { for Unit; Unit <=> 0, }
|
||||
impl_tag! { impl Tag for Unit; Unit <=> 0, }
|
||||
assert_eq!(Unit::BITS, 0);
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Unit1;
|
||||
impl_tag! { for Unit1; Unit1 <=> 1, }
|
||||
impl_tag! { impl Tag for Unit1; Unit1 <=> 1, }
|
||||
assert_eq!(Unit1::BITS, 1);
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Unit2;
|
||||
impl_tag! { for Unit2; Unit2 <=> 0b10, }
|
||||
impl_tag! { impl Tag for Unit2; Unit2 <=> 0b10, }
|
||||
assert_eq!(Unit2::BITS, 2);
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Unit3;
|
||||
impl_tag! { for Unit3; Unit3 <=> 0b100, }
|
||||
impl_tag! { impl Tag for Unit3; Unit3 <=> 0b100, }
|
||||
assert_eq!(Unit3::BITS, 3);
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@ -28,6 +28,6 @@ fn bits_constant() {
|
||||
B,
|
||||
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);
|
||||
}
|
||||
|
@ -1627,7 +1627,7 @@ struct ParamTag {
|
||||
}
|
||||
|
||||
impl_tag! {
|
||||
for ParamTag;
|
||||
impl Tag for ParamTag;
|
||||
ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::NotConst } <=> 0,
|
||||
ParamTag { reveal: traits::Reveal::All, constness: hir::Constness::NotConst } <=> 1,
|
||||
ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::Const } <=> 2,
|
||||
|
Loading…
Reference in New Issue
Block a user