Skip to content

Commit a24afdb

Browse files
committed
[rustdoc] Display unsafe attrs with edition 2024 unsafe() wrappers.
1 parent a7a1618 commit a24afdb

File tree

6 files changed

+43
-11
lines changed

6 files changed

+43
-11
lines changed

src/librustdoc/clean/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,13 +768,13 @@ impl Item {
768768
.iter()
769769
.filter_map(|attr| match attr {
770770
hir::Attribute::Parsed(AttributeKind::LinkSection { name, .. }) => {
771-
Some(format!("#[link_section = \"{name}\"]"))
771+
Some(format!("#[unsafe(link_section = \"{name}\")]"))
772772
}
773773
hir::Attribute::Parsed(AttributeKind::NoMangle(..)) => {
774-
Some("#[no_mangle]".to_string())
774+
Some("#[unsafe(no_mangle)]".to_string())
775775
}
776776
hir::Attribute::Parsed(AttributeKind::ExportName { name, .. }) => {
777-
Some(format!("#[export_name = \"{name}\"]"))
777+
Some(format!("#[unsafe(export_name = \"{name}\")]"))
778778
}
779779
hir::Attribute::Parsed(AttributeKind::NonExhaustive(..)) => {
780780
Some("#[non_exhaustive]".to_string())

tests/rustdoc/attribute-rendering.rs

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

33
//@ has 'foo/fn.f.html'
4-
//@ has - //*[@'class="rust item-decl"]' '#[export_name = "f"] pub fn f()'
5-
#[export_name = "\
6-
f"]
4+
//@ has - //*[@'class="rust item-decl"]' '#[unsafe(export_name = "f")] pub fn f()'
5+
#[unsafe(export_name = "\
6+
f")]
77
pub fn f() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ edition: 2021
2+
#![crate_name = "foo"]
3+
4+
//@ has foo/fn.f.html '//pre[@class="rust item-decl"]' '#[unsafe(no_mangle)]'
5+
#[no_mangle]
6+
pub extern "C" fn f() {}
7+
8+
//@ has foo/fn.g.html '//pre[@class="rust item-decl"]' '#[unsafe(export_name = "bar")]'
9+
#[export_name = "bar"]
10+
pub extern "C" fn g() {}
11+
12+
//@ has foo/fn.example.html '//pre[@class="rust item-decl"]' '#[unsafe(link_section = ".text")]'
13+
#[link_section = ".text"]
14+
pub extern "C" fn example() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Tests that attributes are correctly copied onto a re-exported item.
2+
//@ edition:2024
3+
#![crate_name = "re_export"]
4+
5+
//@ has 're_export/fn.thingy2.html' '//pre[@class="rust item-decl"]' '#[unsafe(no_mangle)]'
6+
pub use thingymod::thingy as thingy2;
7+
8+
mod thingymod {
9+
#[unsafe(no_mangle)]
10+
pub fn thingy() {
11+
12+
}
13+
}

tests/rustdoc/attributes-re-export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ edition:2021
33
#![crate_name = "re_export"]
44

5-
//@ has 're_export/fn.thingy2.html' '//pre[@class="rust item-decl"]' '#[no_mangle]'
5+
//@ has 're_export/fn.thingy2.html' '//pre[@class="rust item-decl"]' '#[unsafe(no_mangle)]'
66
pub use thingymod::thingy as thingy2;
77

88
mod thingymod {

tests/rustdoc/attributes.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
//@ edition: 2024
12
#![crate_name = "foo"]
23

3-
//@ has foo/fn.f.html '//pre[@class="rust item-decl"]' '#[no_mangle]'
4-
#[no_mangle]
4+
//@ has foo/fn.f.html '//pre[@class="rust item-decl"]' '#[unsafe(no_mangle)]'
5+
#[unsafe(no_mangle)]
56
pub extern "C" fn f() {}
67

7-
//@ has foo/fn.g.html '//pre[@class="rust item-decl"]' '#[export_name = "bar"]'
8-
#[export_name = "bar"]
8+
//@ has foo/fn.g.html '//pre[@class="rust item-decl"]' '#[unsafe(export_name = "bar")]'
9+
#[unsafe(export_name = "bar")]
910
pub extern "C" fn g() {}
1011

12+
//@ has foo/fn.example.html '//pre[@class="rust item-decl"]' '#[unsafe(link_section = ".text")]'
13+
#[unsafe(link_section = ".text")]
14+
pub extern "C" fn example() {}
15+
1116
//@ has foo/struct.Repr.html '//pre[@class="rust item-decl"]' '#[repr(C, align(8))]'
1217
#[repr(C, align(8))]
1318
pub struct Repr;

0 commit comments

Comments
 (0)