Repository navigation
raw-borrows-via-references lint causes syntax error #161693
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
Urgau commentedon Aug 25, 2026
cc @obeis
Rollup merge of rust-lang#162007 - chenyukang:yukang-fix-161693-raw-b…
Rollup merge of rust-lang#162007 - chenyukang:yukang-fix-161693-raw-b…
Unrolled build for #162007 in rollup 163111
Rollup merge of #162007 - chenyukang:yukang-fix-161693-raw-borrow-rus…
Rollup merge of #162007 - chenyukang:yukang-fix-161693-raw-borrow-rus…