Skip to content

lint: keep type-changing casts in raw_borrows_via_references - #164690

Open
caelyreth wants to merge 1 commit into
rust-lang:mainfrom
caelyreth:fix-raw-borrow-cast
Open

caelyreth wants to merge 1 commit into
rust-lang:mainfrom
caelyreth:fix-raw-borrow-cast

Conversation

@caelyreth

@caelyreth caelyreth commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #164144

about this bug

raw_borrows_via_references rewrites &mut x as *mut usize to &raw mut x.

When x is [usize; 2], that drops the cast, so p becomes *mut [usize; 2] and the fixed code does not compile.

A cast that only changes mutability, &mut x as *const i32, is dropped the same way.

after this fix

  • Remove as *const T only when &raw already has that type.
  • Otherwise suggest &raw mut x as *mut usize.
  • A redundant cast such as &(*x).0 as *const i32 is still removed.

llm disclosure

The LLM (specifically, Grok 4.7) was used for improving the ui test case edge case coverage only.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 21, 2026
@caelyreth
caelyreth marked this pull request as ready for review October 22, 2026 01:35
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 22, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 22, 2026
@rustbot

rustbot commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 20 candidates

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

raw-borrows-via-references eats casts

3 participants