Skip to content

Commit 90aa25a

Browse files
committed
rustdoc: update attribute tests
1 parent 3ac32ca commit 90aa25a

File tree

5 files changed

+71
-10
lines changed

5 files changed

+71
-10
lines changed

tests/rustdoc/attribute-rendering.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#![crate_name = "foo"]
22

33
//@ has 'foo/fn.f.html'
4-
//@ has - //*[@'class="rust item-decl"]' '#[unsafe(export_name = "f")] pub fn f()'
4+
//@ has - //*[@'class="code-attribute"]' '#[unsafe(export_name = "f")]'
5+
//@ has - //*[@'class="rust item-decl"]' 'pub fn f()'
56
#[unsafe(export_name = "\
67
f")]
78
pub fn f() {}

tests/rustdoc/attributes.rs

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,77 @@
11
//@ edition: 2024
22
#![crate_name = "foo"]
33

4-
//@ has foo/fn.f.html '//pre[@class="rust item-decl"]' '#[unsafe(no_mangle)]'
4+
//@ has foo/fn.f.html '//*[@class="code-attribute"]' '#[unsafe(no_mangle)]'
55
#[unsafe(no_mangle)]
66
pub extern "C" fn f() {}
77

8-
//@ has foo/fn.g.html '//pre[@class="rust item-decl"]' '#[unsafe(export_name = "bar")]'
8+
//@ has foo/fn.g.html '//*[@class="code-attribute"]' '#[unsafe(export_name = "bar")]'
99
#[unsafe(export_name = "bar")]
1010
pub extern "C" fn g() {}
1111

12-
//@ has foo/fn.example.html '//pre[@class="rust item-decl"]' '#[unsafe(link_section = ".text")]'
12+
//@ has foo/fn.example.html '//*[@class="code-attribute"]' '#[unsafe(link_section = ".text")]'
1313
#[unsafe(link_section = ".text")]
1414
pub extern "C" fn example() {}
1515

16-
//@ has foo/struct.Repr.html '//pre[@class="rust item-decl"]' '#[repr(C, align(8))]'
16+
//@ has foo/struct.Repr.html '//*[@class="code-attribute"]' '#[repr(C, align(8))]'
1717
#[repr(C, align(8))]
1818
pub struct Repr;
19+
20+
//@ has foo/macro.macro_rule.html '//*[@class="code-attribute"]' '#[unsafe(link_section = ".text")]'
21+
#[unsafe(link_section = ".text")]
22+
#[macro_export]
23+
macro_rules! macro_rule {
24+
() => {};
25+
}
26+
27+
//@ has 'foo/enum.Enum.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "enum")]'
28+
#[unsafe(link_section = "enum")]
29+
pub enum Enum {
30+
//@ has 'foo/enum.Enum.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "a")]'
31+
#[unsafe(link_section = "a")]
32+
A,
33+
//@ has 'foo/enum.Enum.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "quz")]'
34+
#[unsafe(link_section = "quz")]
35+
Quz {
36+
//@ has 'foo/enum.Enum.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "b")]'
37+
#[unsafe(link_section = "b")]
38+
b: (),
39+
},
40+
}
41+
42+
//@ has 'foo/trait.Trait.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "trait")]'
43+
#[unsafe(link_section = "trait")]
44+
pub trait Trait {
45+
//@ has 'foo/trait.Trait.html'
46+
//@ has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]/*[@class="code-attribute"]' '#[unsafe(link_section = "bar")]'
47+
//@ has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' 'const BAR: u32 = 0u32'
48+
#[unsafe(link_section = "bar")]
49+
const BAR: u32 = 0;
50+
51+
//@ has - '//*[@class="code-attribute"]' '#[unsafe(link_section = "foo")]'
52+
#[unsafe(link_section = "foo")]
53+
fn foo() {}
54+
}
55+
56+
//@ has 'foo/union.Union.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "union")]'
57+
#[unsafe(link_section = "union")]
58+
pub union Union {
59+
//@ has 'foo/union.Union.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "x")]'
60+
#[unsafe(link_section = "x")]
61+
pub x: u32,
62+
y: f32,
63+
}
64+
65+
//@ has 'foo/struct.Struct.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "struct")]'
66+
#[unsafe(link_section = "struct")]
67+
pub struct Struct {
68+
//@ has 'foo/struct.Struct.html' '//*[@class="code-attribute"]' '#[unsafe(link_section = "x")]'
69+
#[unsafe(link_section = "x")]
70+
pub x: u32,
71+
y: f32,
72+
}
73+
74+
// Check that the attributes from the trait items show up consistently in the impl.
75+
//@ has 'foo/struct.Struct.html' '//*[@id="trait-implementations-list"]//*[@class="code-attribute"]' '#[unsafe(link_section = "bar")]'
76+
//@ has 'foo/struct.Struct.html' '//*[@id="trait-implementations-list"]//*[@class="code-attribute"]' '#[unsafe(link_section = "foo")]'
77+
impl Trait for Struct {}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<code>pub enum TypeAlias {
2-
#[non_exhaustive]
2+
<div class="code-attribute">#[non_exhaustive]</div>
33
Variant,
4-
}</code>
4+
}</code>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<code>pub enum Type {
2-
#[non_exhaustive]
2+
<div class="code-attribute">#[non_exhaustive]</div>
33
Variant,
4-
}</code>
4+
}</code>

tests/rustdoc/type-alias/repr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ pub union Foo2 {
2222
}
2323

2424
//@ has 'foo/type.Bar2.html'
25-
//@ matches - '//*[@class="rust item-decl"]' '#\[repr\(C\)\]\npub union Bar2 \{*'
25+
//@ matches - '//*[@class="code-attribute"]' '#\[repr\(C\)\]'
26+
//@ matches - '//*[@class="rust item-decl"]' 'pub union Bar2 \{*'
2627
// Ensures that we see the doc comment of the type alias and not of the aliased type.
2728
//@ has - '//*[@class="toggle top-doc"]/*[@class="docblock"]' 'bar'
2829
/// bar

0 commit comments

Comments
 (0)