diff --git a/tests/rustdoc-json/attrs/export_name_2021.rs b/tests/rustdoc-json/attrs/export_name_2021.rs new file mode 100644 index 0000000000000..badf124bdde36 --- /dev/null +++ b/tests/rustdoc-json/attrs/export_name_2021.rs @@ -0,0 +1,6 @@ +//@ edition: 2021 +#![no_std] + +//@ is "$.index[*][?(@.name=='example')].attrs" '["#[export_name = \"altered\"]"]' +#[export_name = "altered"] +pub extern "C" fn example() {} diff --git a/tests/rustdoc-json/attrs/export_name_2024.rs b/tests/rustdoc-json/attrs/export_name_2024.rs new file mode 100644 index 0000000000000..c5bb9dcc8f68a --- /dev/null +++ b/tests/rustdoc-json/attrs/export_name_2024.rs @@ -0,0 +1,9 @@ +//@ edition: 2024 +#![no_std] + +// The representation of `#[unsafe(export_name = ..)]` in rustdoc in edition 2024 +// is still `#[export_name = ..]` without the `unsafe` attribute wrapper. + +//@ is "$.index[*][?(@.name=='example')].attrs" '["#[export_name = \"altered\"]"]' +#[unsafe(export_name = "altered")] +pub extern "C" fn example() {} diff --git a/tests/rustdoc-json/attrs/must_use.rs b/tests/rustdoc-json/attrs/must_use.rs new file mode 100644 index 0000000000000..dca73abc76a1a --- /dev/null +++ b/tests/rustdoc-json/attrs/must_use.rs @@ -0,0 +1,9 @@ +#![no_std] + +//@ is "$.index[*][?(@.name=='example')].attrs" '["#[must_use]"]' +#[must_use] +pub fn example() -> impl Iterator {} + +//@ is "$.index[*][?(@.name=='explicit_message')].attrs" '["#[must_use = \"does nothing if you do not use it\"]"]' +#[must_use = "does nothing if you do not use it"] +pub fn explicit_message() -> impl Iterator {} diff --git a/tests/rustdoc-json/attrs/no_mangle_2021.rs b/tests/rustdoc-json/attrs/no_mangle_2021.rs new file mode 100644 index 0000000000000..258542086ec37 --- /dev/null +++ b/tests/rustdoc-json/attrs/no_mangle_2021.rs @@ -0,0 +1,6 @@ +//@ edition: 2021 +#![no_std] + +//@ is "$.index[*][?(@.name=='example')].attrs" '["#[no_mangle]"]' +#[no_mangle] +pub extern "C" fn example() {} diff --git a/tests/rustdoc-json/attrs/no_mangle_2024.rs b/tests/rustdoc-json/attrs/no_mangle_2024.rs new file mode 100644 index 0000000000000..4c01082d045ef --- /dev/null +++ b/tests/rustdoc-json/attrs/no_mangle_2024.rs @@ -0,0 +1,9 @@ +//@ edition: 2024 +#![no_std] + +// The representation of `#[unsafe(no_mangle)]` in rustdoc in edition 2024 +// is still `#[no_mangle]` without the `unsafe` attribute wrapper. + +//@ is "$.index[*][?(@.name=='example')].attrs" '["#[no_mangle]"]' +#[unsafe(no_mangle)] +pub extern "C" fn example() {} diff --git a/tests/rustdoc-json/attrs/non_exhaustive.rs b/tests/rustdoc-json/attrs/non_exhaustive.rs new file mode 100644 index 0000000000000..5d738fc0560da --- /dev/null +++ b/tests/rustdoc-json/attrs/non_exhaustive.rs @@ -0,0 +1,19 @@ +#![no_std] + +//@ is "$.index[*][?(@.name=='MyEnum')].attrs" '["#[non_exhaustive]"]' +#[non_exhaustive] +pub enum MyEnum { + First, +} + +pub enum NonExhaustiveVariant { + //@ is "$.index[*][?(@.name=='Variant')].attrs" '["#[non_exhaustive]"]' + #[non_exhaustive] + Variant(i64), +} + +//@ is "$.index[*][?(@.name=='MyStruct')].attrs" '["#[non_exhaustive]"]' +#[non_exhaustive] +pub struct MyStruct { + pub x: i64, +}