Skip to content

raw-borrows-via-references lint causes syntax error #161693

Closed

Description

@matthiaskrgr

Using the following flags

--force-warn raw-borrows-via-references

this code:

//@ check-pass
#![feature(const_volatile)]

const _READ: () = unsafe {
    let x = 42i32;
    let y = (&x as *const i32).read_volatile();
    assert!(x == y);
};

const _WRITE: () = unsafe {
    let mut x = 42i32;
    (&mut x as *mut i32).write_volatile(13);
    assert!(x == 13);
};

fn main() {}

caused the following diagnostics:

    Checking _volatile v0.1.0 (/tmp/icemaker_global_tempdir.e4pJywawOZz0/icemaker_clippyfix_tempdir.8L3d64fmzMwO/_volatile)
warning: creating an intermediate reference implies aliasing requirements even when immediately cast to a raw pointers
 --> src/main.rs:6:13
  |
6 |     let y = (&x as *const i32).read_volatile();
  |             ^^^^^^^^^^^^^^^^^^
  |
  = note: requested on the command line with `--force-warn raw-borrows-via-references`
help: consider using `&raw const` for a safer and more explicit raw pointer
  |
6 -     let y = (&x as *const i32).read_volatile();
6 +     let y = &raw const x).read_volatile();
  |

warning: creating an intermediate reference implies aliasing requirements even when immediately cast to a raw pointers
  --> src/main.rs:12:5
   |
12 |     (&mut x as *mut i32).write_volatile(13);
   |     ^^^^^^^^^^^^^^^^^^^^
   |
help: consider using `&raw mut` for a safer and more explicit raw pointer
   |
12 -     (&mut x as *mut i32).write_volatile(13);
12 +     &raw mut x).write_volatile(13);
   |

warning: `_volatile` (bin "_volatile") generated 2 warnings (run `cargo clippy --fix --bin "_volatile" -p _volatile -- -Aclippy::all -Awarnings --force-warn raw-borrows-via-references --cap-lints warn` to apply 2 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s

However after applying these diagnostics, the resulting code:

//@ check-pass
#![feature(const_volatile)]

const _READ: () = unsafe {
    let x = 42i32;
    let y = &raw const x).read_volatile();
    assert!(x == y);
};

const _WRITE: () = unsafe {
    let mut x = 42i32;
    &raw mut x).write_volatile(13);
    assert!(x == 13);
};

fn main() {}

no longer compiled:

    Checking _volatile v0.1.0 (/tmp/icemaker_global_tempdir.e4pJywawOZz0/icemaker_clippyfix_tempdir.8L3d64fmzMwO/_volatile)
error: unexpected closing delimiter: `}`
 --> src/main.rs:8:1
  |
4 | const _READ: () = unsafe {
  |                          - the nearest open delimiter
5 |     let x = 42i32;
6 |     let y = &raw const x).read_volatile();
  |                         - missing open `(` for this delimiter
7 |     assert!(x == y);
8 | };
  | ^ unexpected closing delimiter

error: could not compile `_volatile` (bin "_volatile") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_volatile` (bin "_volatile" test) due to 1 previous error

Version:

rustc 1.100.0-nightly (347a1dbf4 2026-08-24)
binary: rustc
commit-hash: 347a1dbf428ab92f284e3afafacfa7eb46341a5d
commit-date: 2026-08-24
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.0

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 24, 2026
  2. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    D-papercutDiagnostics: An error or lint that needs small tweaks.
    D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
    on Aug 24, 2026
  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Aug 24, 2026
  4. Urgau commented on Aug 25, 2026

    @Urgau
    Member
  5. self-assigned this
    on Aug 28, 2026
  6. added 2 commits that reference this issue on Sep 21, 2026
    3232b90
    8085033
  7. added a commit that references this issue on Sep 21, 2026
    0e5f5c3
  8. added a commit that references this issue on Sep 21, 2026
    77e8ebc
  9. added a commit that references this issue on Sep 22, 2026
    594ef1a
  10. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions