about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2023-06-02 00:41:02 +0000
committerclubby789 <jamie@hill-daniel.co.uk>2023-06-02 01:18:59 +0000
commit731601ccd1617a9ca4b1fe09fdb5906c2019110b (patch)
tree57b2ca1344249aab4ac2db54d27d2bd4b665acbf /tests
parentd59363ad0b6391b7fc5bbb02c9ccf9300eef3753 (diff)
downloadrust-731601ccd1617a9ca4b1fe09fdb5906c2019110b.tar.gz
rust-731601ccd1617a9ca4b1fe09fdb5906c2019110b.zip
Check tuple elements are `Sized` in `offset_of`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/offset-of/offset-of-dst-field.rs2
-rw-r--r--tests/ui/offset-of/offset-of-dst-field.stderr19
-rw-r--r--tests/ui/offset-of/offset-of-unsized.rs3
3 files changed, 18 insertions, 6 deletions
diff --git a/tests/ui/offset-of/offset-of-dst-field.rs b/tests/ui/offset-of/offset-of-dst-field.rs
index 3b8dc0b84a4..e393b159e64 100644
--- a/tests/ui/offset-of/offset-of-dst-field.rs
+++ b/tests/ui/offset-of/offset-of-dst-field.rs
@@ -36,6 +36,8 @@ fn main() {
     offset_of!(Alpha, z); //~ ERROR the size for values of type
     offset_of!(Beta, z); //~ ERROR the size for values of type
     offset_of!(Gamma, z); //~ ERROR the size for values of type
+    offset_of!((u8, dyn Trait), 0); // ok
+    offset_of!((u8, dyn Trait), 1); //~ ERROR the size for values of type
 }
 
 fn delta() {
diff --git a/tests/ui/offset-of/offset-of-dst-field.stderr b/tests/ui/offset-of/offset-of-dst-field.stderr
index 128c783d5dd..4eaceaa9358 100644
--- a/tests/ui/offset-of/offset-of-dst-field.stderr
+++ b/tests/ui/offset-of/offset-of-dst-field.stderr
@@ -25,8 +25,17 @@ LL |     offset_of!(Gamma, z);
    = help: the trait `Sized` is not implemented for `Extern`
    = 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 `dyn Trait` cannot be known at compilation time
+  --> $DIR/offset-of-dst-field.rs:40:5
+   |
+LL |     offset_of!((u8, dyn Trait), 1);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+   |
+   = 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 `Extern` cannot be known at compilation time
-  --> $DIR/offset-of-dst-field.rs:43:5
+  --> $DIR/offset-of-dst-field.rs:45:5
    |
 LL |     offset_of!(Delta<Extern>, z);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
@@ -35,7 +44,7 @@ LL |     offset_of!(Delta<Extern>, z);
    = 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 `dyn Trait` cannot be known at compilation time
-  --> $DIR/offset-of-dst-field.rs:44:5
+  --> $DIR/offset-of-dst-field.rs:46:5
    |
 LL |     offset_of!(Delta<dyn Trait>, z);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
@@ -44,7 +53,7 @@ LL |     offset_of!(Delta<dyn Trait>, z);
    = 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:42:5
+  --> $DIR/offset-of-dst-field.rs:44:5
    |
 LL |     offset_of!(Delta<Alpha>, z);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
@@ -58,7 +67,7 @@ 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:48:5
+  --> $DIR/offset-of-dst-field.rs:50:5
    |
 LL | fn generic_with_maybe_sized<T: ?Sized>() -> usize {
    |                             - this type parameter needs to be `std::marker::Sized`
@@ -72,6 +81,6 @@ LL - fn generic_with_maybe_sized<T: ?Sized>() -> usize {
 LL + fn generic_with_maybe_sized<T>() -> usize {
    |
 
-error: aborting due to 7 previous errors
+error: aborting due to 8 previous errors
 
 For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/offset-of/offset-of-unsized.rs b/tests/ui/offset-of/offset-of-unsized.rs
index 666387e615e..49c8328da5c 100644
--- a/tests/ui/offset-of/offset-of-unsized.rs
+++ b/tests/ui/offset-of/offset-of-unsized.rs
@@ -1,5 +1,6 @@
 // build-pass
-// regression test for #112051
+// regression test for #112051, not in `offset-of-dst` as the issue is in codegen,
+// and isn't triggered in the presence of typeck errors
 
 #![feature(offset_of)]