Skip to content

Attempting to transmute between two of the same associated type results in an error. #49793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AlphaModder opened this issue Apr 8, 2018 · 1 comment
Labels
A-associated-items Area: Associated items (types, constants & functions) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@AlphaModder
Copy link

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
@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-associated-items Area: Associated items (types, constants & functions) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 7, 2018
@strega-nil
Copy link
Contributor

strega-nil commented Oct 21, 2018

I'd argue this is just a bad error message - it should say something along the lines of "cannot transmute between types of different sizes, or dependent types".

bors added a commit that referenced this issue Dec 31, 2018
Add specific diagnostic when attempting to transmute between equal generic types

Also clarifies the wording of E0512.

Fixes #49793.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants