about summary refs log tree commit diff
path: root/tests/rustdoc-json
diff options
context:
space:
mode:
authorPredrag Gruevski <obi1kenobi82@gmail.com>2025-03-05 04:46:14 +0000
committerPredrag Gruevski <obi1kenobi82@gmail.com>2025-03-05 04:46:14 +0000
commite07d9a8200bc37e3cd816386d35931f9f02e9464 (patch)
tree12a4b1db678e968723a23f2e4d075b42523f19c9 /tests/rustdoc-json
parentf9e0239a7bc813b4aceffc7f069f4797cde3175c (diff)
downloadrust-e07d9a8200bc37e3cd816386d35931f9f02e9464.tar.gz
rust-e07d9a8200bc37e3cd816386d35931f9f02e9464.zip
rustdoc: Add attribute-related tests for rustdoc JSON.
Diffstat (limited to 'tests/rustdoc-json')
-rw-r--r--tests/rustdoc-json/attrs/export_name_2021.rs6
-rw-r--r--tests/rustdoc-json/attrs/export_name_2024.rs9
-rw-r--r--tests/rustdoc-json/attrs/must_use.rs9
-rw-r--r--tests/rustdoc-json/attrs/no_mangle_2021.rs6
-rw-r--r--tests/rustdoc-json/attrs/no_mangle_2024.rs9
-rw-r--r--tests/rustdoc-json/attrs/non_exhaustive.rs19
6 files changed, 58 insertions, 0 deletions
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 00000000000..badf124bdde
--- /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 00000000000..c5bb9dcc8f6
--- /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 00000000000..dca73abc76a
--- /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<Item = i64> {}
+
+//@ 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<Item = i64> {}
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 00000000000..258542086ec
--- /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 00000000000..4c01082d045
--- /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 00000000000..5d738fc0560
--- /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,
+}