Rollup merge of #138569 - aDotInTheVoid:reprdoc-json, r=GuillaumeGomez
rustdoc-json: Add tests for `#[repr(...)]` Works towards #137645 and #81359 Based on #138018, but with only the test changes. CC ```@obi1kenobi``` r? ```@GuillaumeGomez```
This commit is contained in:
commit
bf98654e6c
6 changed files with 163 additions and 0 deletions
8
tests/rustdoc-json/attrs/repr_align.rs
Normal file
8
tests/rustdoc-json/attrs/repr_align.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='Aligned')].attrs" '["#[attr = Repr([ReprAlign(Align(4 bytes))])]\n"]'
|
||||||
|
#[repr(align(4))]
|
||||||
|
pub struct Aligned {
|
||||||
|
a: i8,
|
||||||
|
b: i64,
|
||||||
|
}
|
18
tests/rustdoc-json/attrs/repr_c.rs
Normal file
18
tests/rustdoc-json/attrs/repr_c.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='ReprCStruct')].attrs" '["#[attr = Repr([ReprC])]\n"]'
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct ReprCStruct(pub i64);
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='ReprCEnum')].attrs" '["#[attr = Repr([ReprC])]\n"]'
|
||||||
|
#[repr(C)]
|
||||||
|
pub enum ReprCEnum {
|
||||||
|
First,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='ReprCUnion')].attrs" '["#[attr = Repr([ReprC])]\n"]'
|
||||||
|
#[repr(C)]
|
||||||
|
pub union ReprCUnion {
|
||||||
|
pub left: i64,
|
||||||
|
pub right: u64,
|
||||||
|
}
|
78
tests/rustdoc-json/attrs/repr_combination.rs
Normal file
78
tests/rustdoc-json/attrs/repr_combination.rs
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
// Combinations of `#[repr(..)]` attributes.
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='ReprCI8')].attrs" '["#[attr = Repr([ReprC, ReprInt(SignedInt(I8))])]\n"]'
|
||||||
|
#[repr(C, i8)]
|
||||||
|
pub enum ReprCI8 {
|
||||||
|
First,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='SeparateReprCI16')].attrs" '["#[attr = Repr([ReprC, ReprInt(SignedInt(I16))])]\n"]'
|
||||||
|
#[repr(C)]
|
||||||
|
#[repr(i16)]
|
||||||
|
pub enum SeparateReprCI16 {
|
||||||
|
First,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='ReversedReprCUsize')].attrs" '["#[attr = Repr([ReprInt(UnsignedInt(Usize)), ReprC])]\n"]'
|
||||||
|
#[repr(usize, C)]
|
||||||
|
pub enum ReversedReprCUsize {
|
||||||
|
First,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='ReprCPacked')].attrs" '["#[attr = Repr([ReprC, ReprPacked(Align(1 bytes))])]\n"]'
|
||||||
|
#[repr(C, packed)]
|
||||||
|
pub struct ReprCPacked {
|
||||||
|
a: i8,
|
||||||
|
b: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='SeparateReprCPacked')].attrs" '["#[attr = Repr([ReprC, ReprPacked(Align(2 bytes))])]\n"]'
|
||||||
|
#[repr(C)]
|
||||||
|
#[repr(packed(2))]
|
||||||
|
pub struct SeparateReprCPacked {
|
||||||
|
a: i8,
|
||||||
|
b: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='ReversedReprCPacked')].attrs" '["#[attr = Repr([ReprPacked(Align(2 bytes)), ReprC])]\n"]'
|
||||||
|
#[repr(packed(2), C)]
|
||||||
|
pub struct ReversedReprCPacked {
|
||||||
|
a: i8,
|
||||||
|
b: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='ReprCAlign')].attrs" '["#[attr = Repr([ReprC, ReprAlign(Align(16 bytes))])]\n"]'
|
||||||
|
#[repr(C, align(16))]
|
||||||
|
pub struct ReprCAlign {
|
||||||
|
a: i8,
|
||||||
|
b: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='SeparateReprCAlign')].attrs" '["#[attr = Repr([ReprC, ReprAlign(Align(2 bytes))])]\n"]'
|
||||||
|
#[repr(C)]
|
||||||
|
#[repr(align(2))]
|
||||||
|
pub struct SeparateReprCAlign {
|
||||||
|
a: i8,
|
||||||
|
b: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='ReversedReprCAlign')].attrs" '["#[attr = Repr([ReprAlign(Align(2 bytes)), ReprC])]\n"]'
|
||||||
|
#[repr(align(2), C)]
|
||||||
|
pub struct ReversedReprCAlign {
|
||||||
|
a: i8,
|
||||||
|
b: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='AlignedExplicitRepr')].attrs" '["#[attr = Repr([ReprC, ReprAlign(Align(16 bytes)), ReprInt(SignedInt(Isize))])]\n"]'
|
||||||
|
#[repr(C, align(16), isize)]
|
||||||
|
pub enum AlignedExplicitRepr {
|
||||||
|
First,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='ReorderedAlignedExplicitRepr')].attrs" '["#[attr = Repr([ReprInt(SignedInt(Isize)), ReprC, ReprAlign(Align(16 bytes))])]\n"]'
|
||||||
|
#[repr(isize, C, align(16))]
|
||||||
|
pub enum ReorderedAlignedExplicitRepr {
|
||||||
|
First,
|
||||||
|
}
|
19
tests/rustdoc-json/attrs/repr_int_enum.rs
Normal file
19
tests/rustdoc-json/attrs/repr_int_enum.rs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='I8')].attrs" '["#[attr = Repr([ReprInt(SignedInt(I8))])]\n"]'
|
||||||
|
#[repr(i8)]
|
||||||
|
pub enum I8 {
|
||||||
|
First,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='I32')].attrs" '["#[attr = Repr([ReprInt(SignedInt(I32))])]\n"]'
|
||||||
|
#[repr(i32)]
|
||||||
|
pub enum I32 {
|
||||||
|
First,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='Usize')].attrs" '["#[attr = Repr([ReprInt(UnsignedInt(Usize))])]\n"]'
|
||||||
|
#[repr(usize)]
|
||||||
|
pub enum Usize {
|
||||||
|
First,
|
||||||
|
}
|
18
tests/rustdoc-json/attrs/repr_packed.rs
Normal file
18
tests/rustdoc-json/attrs/repr_packed.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
// Note the normalization:
|
||||||
|
// `#[repr(packed)]` in has the implict "1" in rustdoc JSON.
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='Packed')].attrs" '["#[attr = Repr([ReprPacked(Align(1 bytes))])]\n"]'
|
||||||
|
#[repr(packed)]
|
||||||
|
pub struct Packed {
|
||||||
|
a: i8,
|
||||||
|
b: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='PackedAligned')].attrs" '["#[attr = Repr([ReprPacked(Align(4 bytes))])]\n"]'
|
||||||
|
#[repr(packed(4))]
|
||||||
|
pub struct PackedAligned {
|
||||||
|
a: i8,
|
||||||
|
b: i64,
|
||||||
|
}
|
22
tests/rustdoc-json/attrs/repr_transparent.rs
Normal file
22
tests/rustdoc-json/attrs/repr_transparent.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
// Rustdoc JSON currently includes `#[repr(transparent)]`
|
||||||
|
// even if the transparency is not part of the public API
|
||||||
|
//
|
||||||
|
// https://doc.rust-lang.org/nomicon/other-reprs.html#reprtransparent
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='Transparent')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]'
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct Transparent(pub i64);
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='TransparentNonPub')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]'
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct TransparentNonPub(i64);
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='AllZst')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]'
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct AllZst<'a>(pub core::marker::PhantomData<&'a ()>, ());
|
||||||
|
|
||||||
|
//@ is "$.index[*][?(@.name=='AllZstNotPublic')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]'
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct AllZstNotPublic<'a>(core::marker::PhantomData<&'a ()>, ());
|
Loading…
Add table
Add a link
Reference in a new issue