Skip to content

Commit 7f0224e

Browse files
GuillaumeGomezlqd
authored andcommitted
Add ui test to ensure attributes generated from macros are kept as expected
1 parent ae5108a commit 7f0224e

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/test/ui/attr-from-macro.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// aux-build:attr-from-macro.rs
2+
// run-pass
3+
4+
extern crate attr_from_macro;
5+
6+
attr_from_macro::creator! {
7+
struct Foo;
8+
enum Bar;
9+
enum FooBar;
10+
}
11+
12+
fn main() {
13+
// Checking the `repr(u32)` on the enum.
14+
assert_eq!(4, std::mem::size_of::<Bar>());
15+
// Checking the `repr(u16)` on the enum.
16+
assert_eq!(2, std::mem::size_of::<FooBar>());
17+
18+
// Checking the Debug impl on the types.
19+
eprintln!("{:?} {:?} {:?}", Foo, Bar::A, FooBar::A);
20+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#[macro_export]
2+
macro_rules! creator {
3+
(struct $name1:ident; enum $name2:ident; enum $name3:ident;) => {
4+
#[derive(Debug)]
5+
pub struct $name1;
6+
7+
#[derive(Debug)]
8+
#[repr(u32)]
9+
pub enum $name2 { A }
10+
11+
#[derive(Debug)]
12+
#[repr(u16)]
13+
pub enum $name3 { A }
14+
}
15+
}

0 commit comments

Comments
 (0)