Skip to content

Commit a7ef12b

Browse files
authored
Unrolled build for rust-lang#138033
Rollup merge of rust-lang#138033 - obi1kenobi:pg/json-attrs-tests, r=aDotInTheVoid rustdoc: Add attribute-related tests for rustdoc JSON. Add rustdoc JSON tests covering the use of the following attributes: - `#[non_exhaustive]` applied to enums, variants, and structs - `#[must_use]`, both with and without a message - `#[no_mangle]`, in both edition 2021 and 2024 (`#[unsafe(no_mangle)]`) flavors - `#[export_name]`, also in both edition 2021 and 2024 flavors Related to rust-lang#137645; this is a subset of the attributes that `cargo-semver-checks` relies on and tests in its own test suite or in the test suites of its components such as `trustfall-rustdoc-adapter`. Helps with rust-lang#81359 r? `@aDotInTheVoid`
2 parents f5a1ef7 + e07d9a8 commit a7ef12b

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)