Skip to content

Commit f6623e9

Browse files
committed
Separate type with colon in assert_fields!
1 parent a400255 commit f6623e9

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/assert_fields.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/// }
2121
///
2222
/// // Always have `val2` regardless of OS
23-
/// assert_fields!(Ty, val2);
23+
/// assert_fields!(Ty: val2);
2424
/// ```
2525
///
2626
/// This macro even works with `enum` variants:
@@ -36,7 +36,7 @@
3636
/// Ptr(*const u8),
3737
/// }
3838
///
39-
/// assert_fields!(Data::Val, id, bytes);
39+
/// assert_fields!(Data::Val: id, bytes);
4040
/// ```
4141
///
4242
/// The following example fails to compile because [`Range`] does not have a field named `middle`:
@@ -45,13 +45,13 @@
4545
/// # #[macro_use] extern crate static_assertions; fn main() {}
4646
/// use std::ops::Range;
4747
///
48-
/// assert_fields!(Range<u32>, middle);
48+
/// assert_fields!(Range<u32>: middle);
4949
/// ```
5050
///
5151
/// [`Range`]: https://doc.rust-lang.org/std/ops/struct.Range.html
5252
#[macro_export]
5353
macro_rules! assert_fields {
54-
($t:ident::$v:ident, $($f:ident),+) => {
54+
($t:ident::$v:ident: $($f:ident),+) => {
5555
#[allow(unknown_lints, unneeded_field_pattern)]
5656
const _: fn() = || {
5757
#[allow(dead_code, unreachable_patterns)]
@@ -63,7 +63,7 @@ macro_rules! assert_fields {
6363
}
6464
};
6565
};
66-
($t:path, $($f:ident),+) => {
66+
($t:path: $($f:ident),+) => {
6767
#[allow(unknown_lints, unneeded_field_pattern)]
6868
const _: fn() = || {
6969
$(let $t { $f: _, .. };)+

tests/fields.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@
44
#[macro_use]
55
extern crate static_assertions;
66

7-
mod m {
8-
pub struct _Struct<T: ?Sized> { pub nul: (), pub inner: T }
9-
}
10-
11-
use m::_Struct as _Reused;
12-
137
#[allow(dead_code)]
14-
enum _Thing {
8+
enum Foo {
159
A { x: u8, y: u8 },
1610
B(u8),
1711
}
1812

19-
assert_fields!(m::_Struct<str>, inner, nul);
13+
assert_fields!(Foo::A: x);
14+
assert_fields!(Foo::A: x, x);
15+
assert_fields!(Foo::A: x, y, x);
16+
17+
// TODO: Make tuple field access possible
18+
// assert_fields!(Foo::B, 0);
2019

21-
assert_fields!(_Reused<dyn Send>, inner);
20+
mod m {
21+
#[allow(dead_code)]
22+
pub struct Bar<T: ?Sized> { pub nul: (), pub inner: T }
23+
}
2224

23-
assert_fields!(_Thing::A, x);
24-
assert_fields!(_Thing::A, x, x);
25-
assert_fields!(_Thing::A, x, y, x);
25+
#[allow(dead_code)]
26+
use m::Bar as Baz;
2627

27-
// TODO: Make tuple field access possible
28-
// assert_fields!(_Thing::B, 0);
28+
assert_fields!(m::Bar<str>: inner, nul);
29+
assert_fields!(Baz<dyn Send>: inner, nul);

0 commit comments

Comments
 (0)