Skip to content

Conversation

@nickdrozd
Copy link
Contributor

Hello. This PR cuts most of the unnecessary &mut references from the compiler, changing them to plain & references instead. There are also a few resulting mut variable flags cut as well.

Should cause no change in behavior. Possibly will make something along the way a little faster?

x check and x clippy passed locally.

@rustbot
Copy link
Collaborator

rustbot commented Aug 20, 2025

r? @jackh726

rustbot has assigned @jackh726.
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

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Aug 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 20, 2025

rustc_errors::annotate_snippet_emitter_writer was changed

cc @Muscraft

rustc_errors::emitter was changed

cc @Muscraft

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in match lowering

cc @Nadrieril

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

changes to the core type system

cc @compiler-errors, @lcnr

Some changes occurred in coverage instrumentation.

cc @Zalathar

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in rustc_ty_utils::consts.rs

cc @BoxyUwU

Some changes occurred in need_type_info.rs

cc @lcnr

Some changes occurred in match checking

cc @Nadrieril

Some changes occurred to constck

cc @fee1-dead

/// If this returns `None`, the function call has been handled and the function has returned.
fn hook_special_const_fn(
&mut self,
&self,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the mut here, we don't know which functions will be hooked here in the future and they may need mutable access.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I think some of these changes are desirable and cleanup the code and it's helpful to state "this doesn't actually mutate the visitor", there are quite a few cases where whether they mutate some context is an implementation detail and the fact that they currently don't isn't actually meaningful and would result in churn.

e.g. in confirmation all confirm_X functions should all be able to mutate the SelectionContext and the fact that they don't right now isn't meaningful. If we change them in the future to do so we now need to know whether adding mut here is fine, readd it, and then hope that nobody used them in ways where that's annoying.

I don't think removing them based on a mechanical check for "is the mut currently required" is worth it. There are a few which seem like clear improvements, but a general blanket change feels ambiguous (and likely to cause merge conflicts) enough that I would prefer not merging this.

@nickdrozd nickdrozd closed this Aug 20, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants