about summary refs log tree commit diff
path: root/tests/ui/darwin-objc/darwin-objc-bad-ref.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/darwin-objc/darwin-objc-bad-ref.rs')
-rw-r--r--tests/ui/darwin-objc/darwin-objc-bad-ref.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui/darwin-objc/darwin-objc-bad-ref.rs b/tests/ui/darwin-objc/darwin-objc-bad-ref.rs
new file mode 100644
index 00000000000..fb1437366dd
--- /dev/null
+++ b/tests/ui/darwin-objc/darwin-objc-bad-ref.rs
@@ -0,0 +1,31 @@
+// Test that `objc::class!` and `objc::selector!` can't be returned by reference.
+// A single instance may have multiple addresses (e.g. across dylib boundaries).
+
+//@ edition: 2024
+//@ only-apple
+
+#![feature(darwin_objc)]
+
+use std::os::darwin::objc;
+
+pub fn class_ref<'a>() -> &'a objc::Class {
+    &objc::class!("NSObject")
+    //~^ ERROR cannot return reference to temporary value [E0515]
+}
+
+pub fn class_ref_static() -> &'static objc::Class {
+    &objc::class!("NSObject")
+    //~^ ERROR cannot return reference to temporary value [E0515]
+}
+
+pub fn selector_ref<'a>() -> &'a objc::SEL {
+    &objc::selector!("alloc")
+    //~^ ERROR cannot return reference to temporary value [E0515]
+}
+
+pub fn selector_ref_static() -> &'static objc::SEL {
+    &objc::selector!("alloc")
+    //~^ ERROR cannot return reference to temporary value [E0515]
+}
+
+pub fn main() {}