Skip to content

Commit d7faa56

Browse files
committed
Avoid unnecessary mut-ness for various closures.
1 parent 3a0d0be commit d7faa56

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub(crate) fn codegen_fn<'tcx>(
4646
with_no_trimmed_paths!({
4747
use rustc_middle::mir::pretty;
4848
let options = pretty::PrettyPrintMirOptions::from_cli(tcx);
49-
pretty::write_mir_fn(tcx, mir, &mut |_, _| Ok(()), &mut buf, options).unwrap();
49+
pretty::write_mir_fn(tcx, mir, &|_, _| Ok(()), &mut buf, options).unwrap();
5050
});
5151
String::from_utf8_lossy(&buf).into_owned()
5252
});

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn dump_mir<'tcx, F>(
9191
body: &Body<'tcx>,
9292
extra_data: F,
9393
) where
94-
F: FnMut(PassWhere, &mut dyn io::Write) -> io::Result<()>,
94+
F: Fn(PassWhere, &mut dyn io::Write) -> io::Result<()>,
9595
{
9696
dump_mir_with_options(
9797
tcx,
@@ -119,7 +119,7 @@ pub fn dump_mir_with_options<'tcx, F>(
119119
extra_data: F,
120120
options: PrettyPrintMirOptions,
121121
) where
122-
F: FnMut(PassWhere, &mut dyn io::Write) -> io::Result<()>,
122+
F: Fn(PassWhere, &mut dyn io::Write) -> io::Result<()>,
123123
{
124124
if !dump_enabled(tcx, pass_name, body.source.def_id()) {
125125
return;
@@ -171,11 +171,11 @@ pub fn dump_mir_to_writer<'tcx, F>(
171171
disambiguator: &dyn Display,
172172
body: &Body<'tcx>,
173173
w: &mut dyn io::Write,
174-
mut extra_data: F,
174+
extra_data: F,
175175
options: PrettyPrintMirOptions,
176176
) -> io::Result<()>
177177
where
178-
F: FnMut(PassWhere, &mut dyn io::Write) -> io::Result<()>,
178+
F: Fn(PassWhere, &mut dyn io::Write) -> io::Result<()>,
179179
{
180180
// see notes on #41697 above
181181
let def_path =
@@ -193,7 +193,7 @@ where
193193
writeln!(w)?;
194194
extra_data(PassWhere::BeforeCFG, w)?;
195195
write_user_type_annotations(tcx, body, w)?;
196-
write_mir_fn(tcx, body, &mut extra_data, w, options)?;
196+
write_mir_fn(tcx, body, &extra_data, w, options)?;
197197
extra_data(PassWhere::AfterCFG, w)
198198
}
199199

@@ -343,11 +343,11 @@ pub fn write_mir_pretty<'tcx>(
343343
}
344344

345345
let render_body = |w: &mut dyn io::Write, body| -> io::Result<()> {
346-
write_mir_fn(tcx, body, &mut |_, _| Ok(()), w, options)?;
346+
write_mir_fn(tcx, body, &|_, _| Ok(()), w, options)?;
347347

348348
for body in tcx.promoted_mir(def_id) {
349349
writeln!(w)?;
350-
write_mir_fn(tcx, body, &mut |_, _| Ok(()), w, options)?;
350+
write_mir_fn(tcx, body, &|_, _| Ok(()), w, options)?;
351351
}
352352
Ok(())
353353
};
@@ -359,7 +359,7 @@ pub fn write_mir_pretty<'tcx>(
359359
writeln!(w, "// MIR FOR CTFE")?;
360360
// Do not use `render_body`, as that would render the promoteds again, but these
361361
// are shared between mir_for_ctfe and optimized_mir
362-
write_mir_fn(tcx, tcx.mir_for_ctfe(def_id), &mut |_, _| Ok(()), w, options)?;
362+
write_mir_fn(tcx, tcx.mir_for_ctfe(def_id), &|_, _| Ok(()), w, options)?;
363363
} else {
364364
let instance_mir = tcx.instance_mir(ty::InstanceKind::Item(def_id));
365365
render_body(w, instance_mir)?;
@@ -372,12 +372,12 @@ pub fn write_mir_pretty<'tcx>(
372372
pub fn write_mir_fn<'tcx, F>(
373373
tcx: TyCtxt<'tcx>,
374374
body: &Body<'tcx>,
375-
extra_data: &mut F,
375+
extra_data: &F,
376376
w: &mut dyn io::Write,
377377
options: PrettyPrintMirOptions,
378378
) -> io::Result<()>
379379
where
380-
F: FnMut(PassWhere, &mut dyn io::Write) -> io::Result<()>,
380+
F: Fn(PassWhere, &mut dyn io::Write) -> io::Result<()>,
381381
{
382382
write_mir_intro(tcx, body, w, options)?;
383383
for block in body.basic_blocks.indices() {
@@ -710,12 +710,12 @@ fn write_basic_block<'tcx, F>(
710710
tcx: TyCtxt<'tcx>,
711711
block: BasicBlock,
712712
body: &Body<'tcx>,
713-
extra_data: &mut F,
713+
extra_data: &F,
714714
w: &mut dyn io::Write,
715715
options: PrettyPrintMirOptions,
716716
) -> io::Result<()>
717717
where
718-
F: FnMut(PassWhere, &mut dyn io::Write) -> io::Result<()>,
718+
F: Fn(PassWhere, &mut dyn io::Write) -> io::Result<()>,
719719
{
720720
let data = &body[block];
721721

@@ -1363,11 +1363,11 @@ fn post_fmt_projection(projection: &[PlaceElem<'_>], fmt: &mut Formatter<'_>) ->
13631363
fn write_extra<'tcx, F>(
13641364
tcx: TyCtxt<'tcx>,
13651365
write: &mut dyn io::Write,
1366-
mut visit_op: F,
1366+
visit_op: F,
13671367
options: PrettyPrintMirOptions,
13681368
) -> io::Result<()>
13691369
where
1370-
F: FnMut(&mut ExtraComments<'tcx>),
1370+
F: Fn(&mut ExtraComments<'tcx>),
13711371
{
13721372
if options.include_extra_comments {
13731373
let mut extra_comments = ExtraComments { tcx, comments: vec![] };

compiler/rustc_mir_build/src/builder/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
834834
pretty::write_mir_fn(
835835
self.tcx,
836836
&body,
837-
&mut |_, _| Ok(()),
837+
&|_, _| Ok(()),
838838
&mut std::io::stdout(),
839839
options,
840840
)

0 commit comments

Comments
 (0)