about summary refs log tree commit diff
path: root/tests/ui/lang-items
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-12-08 14:25:39 +0800
committer许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-12-08 15:32:04 +0800
commit6959582ac6378e1c1c2b858497770df609feb37e (patch)
tree8cb5015793b08a9b89e40cb32f6bb7656d37acbf /tests/ui/lang-items
parent1e3328dd72a3aed8050d2c090b0dd818a5645d9d (diff)
downloadrust-6959582ac6378e1c1c2b858497770df609feb37e.tar.gz
rust-6959582ac6378e1c1c2b858497770df609feb37e.zip
Move `assoc-lang-items.rs` to `tests/ui/lang-items/`
Diffstat (limited to 'tests/ui/lang-items')
-rw-r--r--tests/ui/lang-items/assoc-lang-items.rs35
-rw-r--r--tests/ui/lang-items/assoc-lang-items.stderr27
2 files changed, 62 insertions, 0 deletions
diff --git a/tests/ui/lang-items/assoc-lang-items.rs b/tests/ui/lang-items/assoc-lang-items.rs
new file mode 100644
index 00000000000..460d3ed2326
--- /dev/null
+++ b/tests/ui/lang-items/assoc-lang-items.rs
@@ -0,0 +1,35 @@
+//! Check that associated items can be marked as lang items, so that they don't have to be looked up
+//! by name or by definition order indirectly.
+//!
+//! This test is not *quite* high-fidelity: it checks that you can use lang items on associated
+//! items by looking at the error message *as a proxy*. That is, the error message is about
+//! undefined lang items and not invalid attribute target, indicating that it has reached lang item
+//! machinery (which is relying on knowing the implementation detail). However, it's annoying to
+//! write a full-fidelity test for this, so I think this is acceptable even though it's not *great*.
+//!
+//! This was implemented in <https://github.com/rust-lang/rust/pull/72559> to help with
+//! <https://github.com/rust-lang/rust/issues/70718>, which is itself relevant for e.g. `Fn::Output`
+//! or `Future::Output` or specific use cases like [Use `T`'s discriminant type in
+//! `mem::Discriminant<T>` instead of `u64`](https://github.com/rust-lang/rust/pull/70705).
+
+#![feature(lang_items)]
+
+trait Foo {
+    #[lang = "dummy_lang_item_1"] //~ ERROR definition
+    fn foo() {}
+
+    #[lang = "dummy_lang_item_2"] //~ ERROR definition
+    fn bar();
+
+    #[lang = "dummy_lang_item_3"] //~ ERROR definition
+    type MyType;
+}
+
+struct Bar;
+
+impl Bar {
+    #[lang = "dummy_lang_item_4"] //~ ERROR definition
+    fn test() {}
+}
+
+fn main() {}
diff --git a/tests/ui/lang-items/assoc-lang-items.stderr b/tests/ui/lang-items/assoc-lang-items.stderr
new file mode 100644
index 00000000000..7e61fea449b
--- /dev/null
+++ b/tests/ui/lang-items/assoc-lang-items.stderr
@@ -0,0 +1,27 @@
+error[E0522]: definition of an unknown lang item: `dummy_lang_item_1`
+  --> $DIR/assoc-lang-items.rs:18:5
+   |
+LL |     #[lang = "dummy_lang_item_1"]
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_1`
+
+error[E0522]: definition of an unknown lang item: `dummy_lang_item_2`
+  --> $DIR/assoc-lang-items.rs:21:5
+   |
+LL |     #[lang = "dummy_lang_item_2"]
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_2`
+
+error[E0522]: definition of an unknown lang item: `dummy_lang_item_3`
+  --> $DIR/assoc-lang-items.rs:24:5
+   |
+LL |     #[lang = "dummy_lang_item_3"]
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_3`
+
+error[E0522]: definition of an unknown lang item: `dummy_lang_item_4`
+  --> $DIR/assoc-lang-items.rs:31:5
+   |
+LL |     #[lang = "dummy_lang_item_4"]
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_4`
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0522`.