Adapt seq macro to not derail rustfmt

This commit is contained in:
David Tolnay 2022-01-20 19:25:06 -08:00
parent 21c1ab6c50
commit 343c060fc1
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
4 changed files with 43 additions and 48 deletions

View File

@ -67,25 +67,20 @@ macro_rules! hashmap {
}
macro_rules! seq_impl {
(seq $first:expr,) => {
seq_impl!(seq $first)
};
($first:expr,) => {
seq_impl!($first)
};
(seq $first:expr) => {
(.. $first:expr $(,)?) => {
$first.into_iter()
};
($first:expr) => {
(.. $first:expr, $($elem:tt)*) => {
$first.into_iter().chain(seq!($($elem)*))
};
($first:expr $(,)?) => {
Some($first).into_iter()
};
(seq $first:expr , $( $elem: tt)*) => {
$first.into_iter().chain(seq!( $($elem)* ))
};
($first:expr , $($elem: tt)*) => {
Some($first).into_iter().chain(seq!( $($elem)* ))
($first:expr, $($elem:tt)*) => {
Some($first).into_iter().chain(seq!($($elem)*))
}
}
macro_rules! seq {
($($tt: tt)*) => {
seq_impl!($($tt)*).collect::<Vec<_>>()

View File

@ -1552,7 +1552,7 @@ fn test_net_ipv4addr_compact() {
net::Ipv4Addr::from(*b"1234").compact(),
&seq![
Token::Tuple { len: 4 },
seq b"1234".iter().map(|&b| Token::U8(b)),
..b"1234".iter().map(|&b| Token::U8(b)),
Token::TupleEnd
],
);
@ -1564,7 +1564,7 @@ fn test_net_ipv6addr_compact() {
net::Ipv6Addr::from(*b"1234567890123456").compact(),
&seq![
Token::Tuple { len: 4 },
seq b"1234567890123456".iter().map(|&b| Token::U8(b)),
..b"1234567890123456".iter().map(|&b| Token::U8(b)),
Token::TupleEnd
],
);
@ -1575,10 +1575,12 @@ fn test_net_ipaddr_compact() {
test(
net::IpAddr::from(*b"1234").compact(),
&seq![
Token::NewtypeVariant { name: "IpAddr", variant: "V4" },
Token::NewtypeVariant {
name: "IpAddr",
variant: "V4"
},
Token::Tuple { len: 4 },
seq b"1234".iter().map(|&b| Token::U8(b)),
..b"1234".iter().map(|&b| Token::U8(b)),
Token::TupleEnd
],
);
@ -1589,14 +1591,14 @@ fn test_net_socketaddr_compact() {
test(
net::SocketAddr::from((*b"1234567890123456", 1234)).compact(),
&seq![
Token::NewtypeVariant { name: "SocketAddr", variant: "V6" },
Token::NewtypeVariant {
name: "SocketAddr",
variant: "V6"
},
Token::Tuple { len: 2 },
Token::Tuple { len: 16 },
seq b"1234567890123456".iter().map(|&b| Token::U8(b)),
..b"1234567890123456".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
Token::U16(1234),
Token::TupleEnd
],
@ -1604,14 +1606,14 @@ fn test_net_socketaddr_compact() {
test(
net::SocketAddr::from((*b"1234", 1234)).compact(),
&seq![
Token::NewtypeVariant { name: "SocketAddr", variant: "V4" },
Token::NewtypeVariant {
name: "SocketAddr",
variant: "V4"
},
Token::Tuple { len: 2 },
Token::Tuple { len: 4 },
seq b"1234".iter().map(|&b| Token::U8(b)),
..b"1234".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
Token::U16(1234),
Token::TupleEnd
],
@ -1620,11 +1622,9 @@ fn test_net_socketaddr_compact() {
net::SocketAddrV4::new(net::Ipv4Addr::from(*b"1234"), 1234).compact(),
&seq![
Token::Tuple { len: 2 },
Token::Tuple { len: 4 },
seq b"1234".iter().map(|&b| Token::U8(b)),
..b"1234".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
Token::U16(1234),
Token::TupleEnd
],
@ -1633,11 +1633,9 @@ fn test_net_socketaddr_compact() {
net::SocketAddrV6::new(net::Ipv6Addr::from(*b"1234567890123456"), 1234, 0, 0).compact(),
&seq![
Token::Tuple { len: 2 },
Token::Tuple { len: 16 },
seq b"1234567890123456".iter().map(|&b| Token::U8(b)),
..b"1234567890123456".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
Token::U16(1234),
Token::TupleEnd
],

View File

@ -11,10 +11,12 @@ fn ip_addr_roundtrip() {
assert_tokens(
&net::IpAddr::from(*b"1234").compact(),
&seq![
Token::NewtypeVariant { name: "IpAddr", variant: "V4" },
Token::NewtypeVariant {
name: "IpAddr",
variant: "V4"
},
Token::Tuple { len: 4 },
seq b"1234".iter().map(|&b| Token::U8(b)),
..b"1234".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
],
);
@ -25,14 +27,14 @@ fn socket_addr_roundtrip() {
assert_tokens(
&net::SocketAddr::from((*b"1234567890123456", 1234)).compact(),
&seq![
Token::NewtypeVariant { name: "SocketAddr", variant: "V6" },
Token::NewtypeVariant {
name: "SocketAddr",
variant: "V6"
},
Token::Tuple { len: 2 },
Token::Tuple { len: 16 },
seq b"1234567890123456".iter().map(|&b| Token::U8(b)),
..b"1234567890123456".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
Token::U16(1234),
Token::TupleEnd,
],

View File

@ -549,14 +549,14 @@ declare_tests! {
test_net_ipv4addr_compact {
net::Ipv4Addr::from(*b"1234") => &seq![
Token::Tuple { len: 4 },
seq b"1234".iter().map(|&b| Token::U8(b)),
..b"1234".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
],
}
test_net_ipv6addr_compact {
net::Ipv6Addr::from(*b"1234567890123456") => &seq![
Token::Tuple { len: 16 },
seq b"1234567890123456".iter().map(|&b| Token::U8(b)),
..b"1234567890123456".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
],
}
@ -565,7 +565,7 @@ declare_tests! {
Token::NewtypeVariant { name: "IpAddr", variant: "V4" },
Token::Tuple { len: 4 },
seq b"1234".iter().map(|&b| Token::U8(b)),
..b"1234".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
],
}
@ -576,7 +576,7 @@ declare_tests! {
Token::Tuple { len: 2 },
Token::Tuple { len: 16 },
seq b"1234567890123456".iter().map(|&b| Token::U8(b)),
..b"1234567890123456".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
Token::U16(1234),
@ -586,7 +586,7 @@ declare_tests! {
Token::Tuple { len: 2 },
Token::Tuple { len: 4 },
seq b"1234".iter().map(|&b| Token::U8(b)),
..b"1234".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
Token::U16(1234),
@ -596,7 +596,7 @@ declare_tests! {
Token::Tuple { len: 2 },
Token::Tuple { len: 16 },
seq b"1234567890123456".iter().map(|&b| Token::U8(b)),
..b"1234567890123456".iter().map(|&b| Token::U8(b)),
Token::TupleEnd,
Token::U16(1234),