Skip to content
/ rust Public
forked from rust-lang/rust

Commit 560b40d

Browse files
authored
Rollup merge of rust-lang#138569 - aDotInTheVoid:reprdoc-json, r=GuillaumeGomez
rustdoc-json: Add tests for `#[repr(...)]` Works towards rust-lang#137645 and rust-lang#81359 Based on rust-lang#138018, but with only the test changes. CC `@obi1kenobi` r? `@GuillaumeGomez`
2 parents a478d0b + f5ecb74 commit 560b40d

File tree

6 files changed

+163
-0
lines changed

6 files changed

+163
-0
lines changed
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![no_std]
2+
3+
//@ is "$.index[*][?(@.name=='Aligned')].attrs" '["#[attr = Repr([ReprAlign(Align(4 bytes))])]\n"]'
4+
#[repr(align(4))]
5+
pub struct Aligned {
6+
a: i8,
7+
b: i64,
8+
}

tests/rustdoc-json/attrs/repr_c.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![no_std]
2+
3+
//@ is "$.index[*][?(@.name=='ReprCStruct')].attrs" '["#[attr = Repr([ReprC])]\n"]'
4+
#[repr(C)]
5+
pub struct ReprCStruct(pub i64);
6+
7+
//@ is "$.index[*][?(@.name=='ReprCEnum')].attrs" '["#[attr = Repr([ReprC])]\n"]'
8+
#[repr(C)]
9+
pub enum ReprCEnum {
10+
First,
11+
}
12+
13+
//@ is "$.index[*][?(@.name=='ReprCUnion')].attrs" '["#[attr = Repr([ReprC])]\n"]'
14+
#[repr(C)]
15+
pub union ReprCUnion {
16+
pub left: i64,
17+
pub right: u64,
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#![no_std]
2+
3+
// Combinations of `#[repr(..)]` attributes.
4+
5+
//@ is "$.index[*][?(@.name=='ReprCI8')].attrs" '["#[attr = Repr([ReprC, ReprInt(SignedInt(I8))])]\n"]'
6+
#[repr(C, i8)]
7+
pub enum ReprCI8 {
8+
First,
9+
}
10+
11+
//@ is "$.index[*][?(@.name=='SeparateReprCI16')].attrs" '["#[attr = Repr([ReprC, ReprInt(SignedInt(I16))])]\n"]'
12+
#[repr(C)]
13+
#[repr(i16)]
14+
pub enum SeparateReprCI16 {
15+
First,
16+
}
17+
18+
//@ is "$.index[*][?(@.name=='ReversedReprCUsize')].attrs" '["#[attr = Repr([ReprInt(UnsignedInt(Usize)), ReprC])]\n"]'
19+
#[repr(usize, C)]
20+
pub enum ReversedReprCUsize {
21+
First,
22+
}
23+
24+
//@ is "$.index[*][?(@.name=='ReprCPacked')].attrs" '["#[attr = Repr([ReprC, ReprPacked(Align(1 bytes))])]\n"]'
25+
#[repr(C, packed)]
26+
pub struct ReprCPacked {
27+
a: i8,
28+
b: i64,
29+
}
30+
31+
//@ is "$.index[*][?(@.name=='SeparateReprCPacked')].attrs" '["#[attr = Repr([ReprC, ReprPacked(Align(2 bytes))])]\n"]'
32+
#[repr(C)]
33+
#[repr(packed(2))]
34+
pub struct SeparateReprCPacked {
35+
a: i8,
36+
b: i64,
37+
}
38+
39+
//@ is "$.index[*][?(@.name=='ReversedReprCPacked')].attrs" '["#[attr = Repr([ReprPacked(Align(2 bytes)), ReprC])]\n"]'
40+
#[repr(packed(2), C)]
41+
pub struct ReversedReprCPacked {
42+
a: i8,
43+
b: i64,
44+
}
45+
46+
//@ is "$.index[*][?(@.name=='ReprCAlign')].attrs" '["#[attr = Repr([ReprC, ReprAlign(Align(16 bytes))])]\n"]'
47+
#[repr(C, align(16))]
48+
pub struct ReprCAlign {
49+
a: i8,
50+
b: i64,
51+
}
52+
53+
//@ is "$.index[*][?(@.name=='SeparateReprCAlign')].attrs" '["#[attr = Repr([ReprC, ReprAlign(Align(2 bytes))])]\n"]'
54+
#[repr(C)]
55+
#[repr(align(2))]
56+
pub struct SeparateReprCAlign {
57+
a: i8,
58+
b: i64,
59+
}
60+
61+
//@ is "$.index[*][?(@.name=='ReversedReprCAlign')].attrs" '["#[attr = Repr([ReprAlign(Align(2 bytes)), ReprC])]\n"]'
62+
#[repr(align(2), C)]
63+
pub struct ReversedReprCAlign {
64+
a: i8,
65+
b: i64,
66+
}
67+
68+
//@ is "$.index[*][?(@.name=='AlignedExplicitRepr')].attrs" '["#[attr = Repr([ReprC, ReprAlign(Align(16 bytes)), ReprInt(SignedInt(Isize))])]\n"]'
69+
#[repr(C, align(16), isize)]
70+
pub enum AlignedExplicitRepr {
71+
First,
72+
}
73+
74+
//@ is "$.index[*][?(@.name=='ReorderedAlignedExplicitRepr')].attrs" '["#[attr = Repr([ReprInt(SignedInt(Isize)), ReprC, ReprAlign(Align(16 bytes))])]\n"]'
75+
#[repr(isize, C, align(16))]
76+
pub enum ReorderedAlignedExplicitRepr {
77+
First,
78+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![no_std]
2+
3+
//@ is "$.index[*][?(@.name=='I8')].attrs" '["#[attr = Repr([ReprInt(SignedInt(I8))])]\n"]'
4+
#[repr(i8)]
5+
pub enum I8 {
6+
First,
7+
}
8+
9+
//@ is "$.index[*][?(@.name=='I32')].attrs" '["#[attr = Repr([ReprInt(SignedInt(I32))])]\n"]'
10+
#[repr(i32)]
11+
pub enum I32 {
12+
First,
13+
}
14+
15+
//@ is "$.index[*][?(@.name=='Usize')].attrs" '["#[attr = Repr([ReprInt(UnsignedInt(Usize))])]\n"]'
16+
#[repr(usize)]
17+
pub enum Usize {
18+
First,
19+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![no_std]
2+
3+
// Note the normalization:
4+
// `#[repr(packed)]` in has the implict "1" in rustdoc JSON.
5+
6+
//@ is "$.index[*][?(@.name=='Packed')].attrs" '["#[attr = Repr([ReprPacked(Align(1 bytes))])]\n"]'
7+
#[repr(packed)]
8+
pub struct Packed {
9+
a: i8,
10+
b: i64,
11+
}
12+
13+
//@ is "$.index[*][?(@.name=='PackedAligned')].attrs" '["#[attr = Repr([ReprPacked(Align(4 bytes))])]\n"]'
14+
#[repr(packed(4))]
15+
pub struct PackedAligned {
16+
a: i8,
17+
b: i64,
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![no_std]
2+
3+
// Rustdoc JSON currently includes `#[repr(transparent)]`
4+
// even if the transparency is not part of the public API
5+
//
6+
// https://doc.rust-lang.org/nomicon/other-reprs.html#reprtransparent
7+
8+
//@ is "$.index[*][?(@.name=='Transparent')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]'
9+
#[repr(transparent)]
10+
pub struct Transparent(pub i64);
11+
12+
//@ is "$.index[*][?(@.name=='TransparentNonPub')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]'
13+
#[repr(transparent)]
14+
pub struct TransparentNonPub(i64);
15+
16+
//@ is "$.index[*][?(@.name=='AllZst')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]'
17+
#[repr(transparent)]
18+
pub struct AllZst<'a>(pub core::marker::PhantomData<&'a ()>, ());
19+
20+
//@ is "$.index[*][?(@.name=='AllZstNotPublic')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]'
21+
#[repr(transparent)]
22+
pub struct AllZstNotPublic<'a>(core::marker::PhantomData<&'a ()>, ());

0 commit comments

Comments
 (0)