Skip to content
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

rust-analyzer doesn't like zerocopy::KnownLayout on DSTs #18682

Open
allisonkarlitskaya opened this issue Dec 13, 2024 · 0 comments
Open

rust-analyzer doesn't like zerocopy::KnownLayout on DSTs #18682

allisonkarlitskaya opened this issue Dec 13, 2024 · 0 comments
Assignees
Labels
C-bug Category: bug

Comments

@allisonkarlitskaya
Copy link

rust-analyzer version: rust-analyzer 1.83.0 via rust-analyzer-1.83.0-1.fc41.x86_64
rustc version: rustc 1.83.0 (90b35a623 2024-11-26) (Fedora 1.83.0-1.fc41) via rust-1.83.0-1.fc41.x86_64
editor or extension: nvim from Fedora 41: neovim-0.10.2-1.fc41.x86_64
relevant settings:

LSP configs active in this buffer (bufnr: 1) ~
- Language client log: ~/.local/state/nvim/lsp.log
- Detected filetype: `rust`
- 1 client(s) attached to this buffer
- Client: `rust_analyzer` (id: 1, bufnr: [1])
  root directory:    ~/src/reproducer/
  filetypes:         rust
  cmd:               /usr/local/bin/rust-analyzer
  version:           `rust-analyzer 1.85.0-nightly (d4025ee 2024-12-12)`
  executable:        true
  autostart:         true

code snippet to reproduce:

// add your code here
use zerocopy::KnownLayout;

#[derive(KnownLayout)]
#[repr(C)]
struct Flexible {
    header: u32,
    body: [u8],
}

This gets you

1. casting `*mut _` as `*mut __ZerocopyKnownLayoutMaybeUninit` is invalid: vtable kinds may not match [E0606]
2. casting `*mut __ZerocopyKnownLayoutMaybeUninit` as `*mut _` is invalid: vtable kinds may not match [E0606]

but with cargo build it's fine.

This is caused by Flexible being a DST (dynamically sized type). Dropping the variable-sized body: [u8] field makes the problem go away.

I also tried with nightly (rust-analyzer 1.85.0-nightly (d4025ee 2024-12-12)) without improvement.

@allisonkarlitskaya allisonkarlitskaya added the C-bug Category: bug label Dec 13, 2024
@ShoyuVanilla ShoyuVanilla self-assigned this Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants