Closed
Description
While attempting to store a set of values that differ in type but not layout together in a collection, I discovered that the following code, strangely, results in E0512 ("transmute called with types of different sizes").
trait Foo {
type Bar;
}
unsafe fn noop<F: Foo>(foo: F::Bar) -> F::Bar {
::std::mem::transmute(foo)
}
Here is the exact error message produced:
error[E0512]: transmute called with types of different sizes
--> src/main.rs:5:5
|
5 | ::std::mem::transmute(foo)
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: <F as Foo>::Bar (this type's size can vary)
= note: target type: <F as Foo>::Bar (this type's size can vary)
Either I'm missing something extremely subtle and non-intuitive here, or this a bug or blindspot of the compiler. If it is anything but an easily fixable bug, I would suggest that a special error message be added for this case in the meantime, as the current one is rather confusing.
Output of rustc --version --verbose
:
rustc 1.25.0 (84203cac6 2018-03-25)
binary: rustc
commit-hash: 84203cac67e65ca8640b8392348411098c856985
commit-date: 2018-03-25
host: x86_64-pc-windows-msvc
release: 1.25.0
LLVM version: 6.0