Skip to content

Commit e07d9a8

Browse files
committed
rustdoc: Add attribute-related tests for rustdoc JSON.
1 parent f9e0239 commit e07d9a8

6 files changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ edition: 2021
2+
#![no_std]
3+
4+
//@ is "$.index[*][?(@.name=='example')].attrs" '["#[export_name = \"altered\"]"]'
5+
#[export_name = "altered"]
6+
pub extern "C" fn example() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ edition: 2024
2+
#![no_std]
3+
4+
// The representation of `#[unsafe(export_name = ..)]` in rustdoc in edition 2024
5+
// is still `#[export_name = ..]` without the `unsafe` attribute wrapper.
6+
7+
//@ is "$.index[*][?(@.name=='example')].attrs" '["#[export_name = \"altered\"]"]'
8+
#[unsafe(export_name = "altered")]
9+
pub extern "C" fn example() {}

tests/rustdoc-json/attrs/must_use.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![no_std]
2+
3+
//@ is "$.index[*][?(@.name=='example')].attrs" '["#[must_use]"]'
4+
#[must_use]
5+
pub fn example() -> impl Iterator<Item = i64> {}
6+
7+
//@ is "$.index[*][?(@.name=='explicit_message')].attrs" '["#[must_use = \"does nothing if you do not use it\"]"]'
8+
#[must_use = "does nothing if you do not use it"]
9+
pub fn explicit_message() -> impl Iterator<Item = i64> {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ edition: 2021
2+
#![no_std]
3+
4+
//@ is "$.index[*][?(@.name=='example')].attrs" '["#[no_mangle]"]'
5+
#[no_mangle]
6+
pub extern "C" fn example() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ edition: 2024
2+
#![no_std]
3+
4+
// The representation of `#[unsafe(no_mangle)]` in rustdoc in edition 2024
5+
// is still `#[no_mangle]` without the `unsafe` attribute wrapper.
6+
7+
//@ is "$.index[*][?(@.name=='example')].attrs" '["#[no_mangle]"]'
8+
#[unsafe(no_mangle)]
9+
pub extern "C" fn example() {}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![no_std]
2+
3+
//@ is "$.index[*][?(@.name=='MyEnum')].attrs" '["#[non_exhaustive]"]'
4+
#[non_exhaustive]
5+
pub enum MyEnum {
6+
First,
7+
}
8+
9+
pub enum NonExhaustiveVariant {
10+
//@ is "$.index[*][?(@.name=='Variant')].attrs" '["#[non_exhaustive]"]'
11+
#[non_exhaustive]
12+
Variant(i64),
13+
}
14+
15+
//@ is "$.index[*][?(@.name=='MyStruct')].attrs" '["#[non_exhaustive]"]'
16+
#[non_exhaustive]
17+
pub struct MyStruct {
18+
pub x: i64,
19+
}

0 commit comments

Comments
 (0)