Skip to content

Suggest changing argument mutability from &T to &mut T - #162657

Open
enesmahmtoglu wants to merge 1 commit into
rust-lang:mainfrom
enesmahmtoglu:suggest-changing-argument-mutability
Open

Suggest changing argument mutability from &T to &mut T#162657
enesmahmtoglu wants to merge 1 commit into
rust-lang:mainfrom
enesmahmtoglu:suggest-changing-argument-mutability

Conversation

@enesmahmtoglu

@enesmahmtoglu enesmahmtoglu commented Sep 11, 2026

Copy link
Copy Markdown

Fixes #159490.

When a function or method takes a mutable reference &mut T but an immutable reference &T is supplied (e.g. read_line(&input)), rustc reports types differ in mutability but did not provide a suggestion to change the borrow.

This commit adds a diagnostic suggestion in rustc_hir_typeck to change the borrow to mutable (&mut ...), along with a new UI regression test.

@rustbot rustbot added 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. labels Sep 11, 2026
@rustbot

rustbot commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @ShoyuVanilla (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

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

@rustbot

This comment has been minimized.

When a function or method takes a mutable reference but an immutable reference is provided, suggest changing the borrow to be mutable.
@enesmahmtoglu
enesmahmtoglu force-pushed the suggest-changing-argument-mutability branch from d186516 to bf137d3 Compare September 11, 2026 17:34
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.

Suggest changing argument mutability

4 participants