about summary refs log tree commit diff
path: root/tests/ui/offset-of
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/offset-of')
-rw-r--r--tests/ui/offset-of/offset-of-self.rs5
-rw-r--r--tests/ui/offset-of/offset-of-self.stderr10
-rw-r--r--tests/ui/offset-of/offset-of-temporaries.rs23
3 files changed, 30 insertions, 8 deletions
diff --git a/tests/ui/offset-of/offset-of-self.rs b/tests/ui/offset-of/offset-of-self.rs
index 51b1a0b2427..1558e13b530 100644
--- a/tests/ui/offset-of/offset-of-self.rs
+++ b/tests/ui/offset-of/offset-of-self.rs
@@ -23,9 +23,8 @@ impl S {
     fn offs_in_c() -> usize {
         offset_of!(C<Self>, w)
     }
-    // Put offset_of in a slice - test #124478.
-    fn offs_in_c_colon() -> &'static [usize] {
-        &[offset_of!(C::<Self>, w)]
+    fn offs_in_c_colon() -> usize {
+        offset_of!(C::<Self>, w)
     }
 }
 
diff --git a/tests/ui/offset-of/offset-of-self.stderr b/tests/ui/offset-of/offset-of-self.stderr
index a2104a438ad..7c7576e066b 100644
--- a/tests/ui/offset-of/offset-of-self.stderr
+++ b/tests/ui/offset-of/offset-of-self.stderr
@@ -5,7 +5,7 @@ LL |         offset_of!(Self, Self::v);
    |                          ^^^^^^^
 
 error[E0412]: cannot find type `S` in module `self`
-  --> $DIR/offset-of-self.rs:35:26
+  --> $DIR/offset-of-self.rs:34:26
    |
 LL |         offset_of!(self::S, v);
    |                          ^ not found in `self`
@@ -21,7 +21,7 @@ LL +         offset_of!(S, v);
    |
 
 error[E0411]: cannot find type `Self` in this scope
-  --> $DIR/offset-of-self.rs:52:16
+  --> $DIR/offset-of-self.rs:51:16
    |
 LL | fn main() {
    |    ---- `Self` not allowed in a function
@@ -38,13 +38,13 @@ LL |         offset_of!(S, Self);
    = note: available fields are: `v`, `w`
 
 error[E0616]: field `v` of struct `T` is private
-  --> $DIR/offset-of-self.rs:41:30
+  --> $DIR/offset-of-self.rs:40:30
    |
 LL |             offset_of!(Self, v)
    |                              ^ private field
 
 error[E0609]: no field `self` on type `S`
-  --> $DIR/offset-of-self.rs:54:19
+  --> $DIR/offset-of-self.rs:53:19
    |
 LL |     offset_of!(S, self);
    |                   ^^^^
@@ -52,7 +52,7 @@ LL |     offset_of!(S, self);
    = note: available fields are: `v`, `w`
 
 error[E0609]: no field `self` on type `u8`
-  --> $DIR/offset-of-self.rs:55:21
+  --> $DIR/offset-of-self.rs:54:21
    |
 LL |     offset_of!(S, v.self);
    |                     ^^^^
diff --git a/tests/ui/offset-of/offset-of-temporaries.rs b/tests/ui/offset-of/offset-of-temporaries.rs
new file mode 100644
index 00000000000..951a8ee2b50
--- /dev/null
+++ b/tests/ui/offset-of/offset-of-temporaries.rs
@@ -0,0 +1,23 @@
+//@ build-pass
+
+//! Regression test #124478.
+
+use std::mem::offset_of;
+
+struct S {
+    v: u8,
+    w: u16,
+}
+
+impl S {
+    fn return_static_slice() -> &'static [usize] {
+        &[offset_of!(Self, v), offset_of!(Self, w)]
+    }
+    fn use_reference() -> usize {
+        let r = &offset_of!(Self, v);
+        *r * 6
+    }
+}
+
+fn main() {
+}