Skip to content

&raw mut of a static mut treated as simultaneously safe and unsafe #18348

Closed as not planned
@cbiffle

Description

@cbiffle

On 1.82.0, rust-analyzer seems to have mixed opinions about place expressions in the newly stabilized &raw syntax. This bug also affects uses of the older addr_of/addr_of_mut macros. Specifically, it reports an error that was valid in 1.81 but is not correct in 1.82, and also warns (correctly) if you fix the "error" it describes.

rust-analyzer version: the one distributed with 1.82.0 through rustup (instructions were only given for finding the version through VScode, which I don't use): rust-analyzer 1.82.0 (f6e511e 2024-10-15)

rustc version: rustc 1.82.0 (f6e511eec 2024-10-15)

editor or extension: neovim + rustaceanvim

relevant settings: Not sure if it's relevant, but I am cross-compiling for thumbv7em-none-eabihf on an x86 linux host.

code snippet to reproduce:

static mut BUFFER: [u8; 8] = [u8; 8];
// this line is accepted by rustc but gets a big scary error diagnostic
// from rust-analyzer:
let array = &raw mut BUFFER;
// on this line, rust-analyzer insists the unsafe block is unused
// (which is correct on 1.82 but inconsistent with the above)
let array = unsafe { &raw mut BUFFER };

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions