Gilnaa / memoffset

offsetof for Rust
MIT License
224 stars 29 forks source link

Add some compile-fail tests. #68

Closed Gilnaa closed 2 years ago

Gilnaa commented 2 years ago

Ticket:

The compilation failures look like this: (after applying this suggestion)

successes:

---- src/raw_field.rs - raw_field::_memoffset__field_check_tuple (line 82) stdout ----
error[E0308]: mismatched types
 --> src/raw_field.rs:85:1
  |
6 | _memoffset__field_check_tuple!(i32, 0);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---^^^^
  | |                              |
  | |                              expected due to this
  | expected `i32`, found tuple
  |
  = note: expected type `i32`
            found tuple `(_,)`
  = note: this error originates in the macro `_memoffset__field_check_tuple` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
---- src/raw_field.rs - raw_field::_memoffset__field_check (line 46) stdout ----
error[E0026]: struct `Box` does not have a field named `foo`
 --> src/raw_field.rs:52:36
  |
9 | _memoffset__field_check!(BoxedFoo, foo);
  |                                    ^^^ struct `Box` does not have this field

error: aborting due to previous error

For more information about this error, try `rustc --explain E0026`.
---- src/raw_field.rs - raw_field::_memoffset__field_check_union (line 111) stdout ----
error[E0769]: tuple variant `BoxedFoo` written as struct variant
  --> src/raw_field.rs:120:1
   |
12 | _memoffset__field_check_union!(BoxedFoo, variant_a);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `_memoffset__field_check_union` (in Nightly builds, run with -Z macro-backtrace for more info)
help: use the tuple variant pattern syntax instead
  --> /home/gilad/src/memoffset/src/raw_field.rs:134:36
   |
134|             let $type { $field: _ }(_, _);
   |                                    ++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0769`.

---- src/offset_of.rs - offset_of::offset_of_tuple (line 104) stdout ----