about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_lint/src/unused.rs1
-rw-r--r--library/core/src/mem/mod.rs4
-rw-r--r--tests/ui/offset-of/offset-of-dst-field.stderr28
-rw-r--r--tests/ui/offset-of/offset-of-must-use.rs2
-rw-r--r--tests/ui/offset-of/offset-of-must-use.stderr4
-rw-r--r--tests/ui/offset-of/offset-of-self.rs5
-rw-r--r--tests/ui/offset-of/offset-of-self.stderr10
7 files changed, 28 insertions, 26 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs
index 0b0949e4dd8..98f2e95a389 100644
--- a/compiler/rustc_lint/src/unused.rs
+++ b/compiler/rustc_lint/src/unused.rs
@@ -176,6 +176,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
                 | hir::BinOpKind::Shr => Some("bitwise operation"),
             },
             hir::ExprKind::AddrOf(..) => Some("borrow"),
+            hir::ExprKind::OffsetOf(..) => Some("`offset_of` call"),
             hir::ExprKind::Unary(..) => Some("unary operation"),
             _ => None,
         };
diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs
index 75d42edbaa0..9054ade2d79 100644
--- a/library/core/src/mem/mod.rs
+++ b/library/core/src/mem/mod.rs
@@ -1340,8 +1340,8 @@ impl<T> SizedTypeProperties for T {}
 /// assert_eq!(mem::offset_of!(Option<&u8>, Some.0), 0);
 /// ```
 #[stable(feature = "offset_of", since = "1.77.0")]
-#[allow_internal_unstable(builtin_syntax, hint_must_use)]
+#[allow_internal_unstable(builtin_syntax)]
 pub macro offset_of($Container:ty, $($fields:expr)+ $(,)?) {
     // The `{}` is for better error messages
-    crate::hint::must_use({builtin # offset_of($Container, $($fields)+)})
+    {builtin # offset_of($Container, $($fields)+)}
 }
diff --git a/tests/ui/offset-of/offset-of-dst-field.stderr b/tests/ui/offset-of/offset-of-dst-field.stderr
index 753ba809e7d..adfd16c6f2b 100644
--- a/tests/ui/offset-of/offset-of-dst-field.stderr
+++ b/tests/ui/offset-of/offset-of-dst-field.stderr
@@ -34,20 +34,6 @@ LL |     offset_of!((u8, dyn Trait), 1);
    = help: the trait `Sized` is not implemented for `dyn Trait`
    = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
-  --> $DIR/offset-of-dst-field.rs:44:5
-   |
-LL |     offset_of!(Delta<Alpha>, z);
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
-   |
-   = help: within `Alpha`, the trait `Sized` is not implemented for `[u8]`, which is required by `Alpha: Sized`
-note: required because it appears within the type `Alpha`
-  --> $DIR/offset-of-dst-field.rs:5:8
-   |
-LL | struct Alpha {
-   |        ^^^^^
-   = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
-
 error[E0277]: the size for values of type `Extern` cannot be known at compilation time
   --> $DIR/offset-of-dst-field.rs:45:5
    |
@@ -66,6 +52,20 @@ LL |     offset_of!(Delta<dyn Trait>, z);
    = help: the trait `Sized` is not implemented for `dyn Trait`
    = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
 
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+  --> $DIR/offset-of-dst-field.rs:44:5
+   |
+LL |     offset_of!(Delta<Alpha>, z);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+   |
+   = help: within `Alpha`, the trait `Sized` is not implemented for `[u8]`, which is required by `Alpha: Sized`
+note: required because it appears within the type `Alpha`
+  --> $DIR/offset-of-dst-field.rs:5:8
+   |
+LL | struct Alpha {
+   |        ^^^^^
+   = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
+
 error[E0277]: the size for values of type `T` cannot be known at compilation time
   --> $DIR/offset-of-dst-field.rs:50:5
    |
diff --git a/tests/ui/offset-of/offset-of-must-use.rs b/tests/ui/offset-of/offset-of-must-use.rs
index f0c242891d8..87918b8ff95 100644
--- a/tests/ui/offset-of/offset-of-must-use.rs
+++ b/tests/ui/offset-of/offset-of-must-use.rs
@@ -4,5 +4,5 @@
 
 fn main() {
     core::mem::offset_of!((String,), 0);
-    //~^ WARN unused return value of `must_use` that must be used
+    //~^ WARN unused `offset_of` call that must be used
 }
diff --git a/tests/ui/offset-of/offset-of-must-use.stderr b/tests/ui/offset-of/offset-of-must-use.stderr
index b6d88e098d0..9f0e37a59f4 100644
--- a/tests/ui/offset-of/offset-of-must-use.stderr
+++ b/tests/ui/offset-of/offset-of-must-use.stderr
@@ -1,8 +1,8 @@
-warning: unused return value of `must_use` that must be used
+warning: unused `offset_of` call that must be used
   --> $DIR/offset-of-must-use.rs:6:5
    |
 LL |     core::mem::offset_of!((String,), 0);
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `offset_of` call produces a value
    |
 note: the lint level is defined here
   --> $DIR/offset-of-must-use.rs:3:9
diff --git a/tests/ui/offset-of/offset-of-self.rs b/tests/ui/offset-of/offset-of-self.rs
index 1558e13b530..51b1a0b2427 100644
--- a/tests/ui/offset-of/offset-of-self.rs
+++ b/tests/ui/offset-of/offset-of-self.rs
@@ -23,8 +23,9 @@ impl S {
     fn offs_in_c() -> usize {
         offset_of!(C<Self>, w)
     }
-    fn offs_in_c_colon() -> 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)]
     }
 }
 
diff --git a/tests/ui/offset-of/offset-of-self.stderr b/tests/ui/offset-of/offset-of-self.stderr
index 7c7576e066b..a2104a438ad 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:34:26
+  --> $DIR/offset-of-self.rs:35: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:51:16
+  --> $DIR/offset-of-self.rs:52: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:40:30
+  --> $DIR/offset-of-self.rs:41:30
    |
 LL |             offset_of!(Self, v)
    |                              ^ private field
 
 error[E0609]: no field `self` on type `S`
-  --> $DIR/offset-of-self.rs:53:19
+  --> $DIR/offset-of-self.rs:54: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:54:21
+  --> $DIR/offset-of-self.rs:55:21
    |
 LL |     offset_of!(S, v.self);
    |                     ^^^^