Skip to content

Commit 400075d

Browse files
committed
Fixed all unnecessary muts in language core
1 parent 35b9bd0 commit 400075d

File tree

32 files changed

+41
-41
lines changed

32 files changed

+41
-41
lines changed

src/liballoc/btree/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ impl<'a, K: 'a, V: 'a, NodeType>
10371037
Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>, marker::KV> {
10381038

10391039
pub fn into_kv_mut(self) -> (&'a mut K, &'a mut V) {
1040-
let (mut keys, mut vals) = self.node.into_slices_mut();
1040+
let (keys, vals) = self.node.into_slices_mut();
10411041
unsafe {
10421042
(keys.get_unchecked_mut(self.idx), vals.get_unchecked_mut(self.idx))
10431043
}
@@ -1047,7 +1047,7 @@ impl<'a, K: 'a, V: 'a, NodeType>
10471047
impl<'a, K, V, NodeType> Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>, marker::KV> {
10481048
pub fn kv_mut(&mut self) -> (&mut K, &mut V) {
10491049
unsafe {
1050-
let (mut keys, mut vals) = self.node.reborrow_mut().into_slices_mut();
1050+
let (keys, vals) = self.node.reborrow_mut().into_slices_mut();
10511051
(keys.get_unchecked_mut(self.idx), vals.get_unchecked_mut(self.idx))
10521052
}
10531053
}

src/liballoc/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
17511751
type Item = &'a mut T;
17521752
type IntoIter = slice::IterMut<'a, T>;
17531753

1754-
fn into_iter(mut self) -> slice::IterMut<'a, T> {
1754+
fn into_iter(self) -> slice::IterMut<'a, T> {
17551755
self.iter_mut()
17561756
}
17571757
}

src/liballoc/vec_deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,7 @@ impl<'a, T> IntoIterator for &'a mut VecDeque<T> {
23942394
type Item = &'a mut T;
23952395
type IntoIter = IterMut<'a, T>;
23962396

2397-
fn into_iter(mut self) -> IterMut<'a, T> {
2397+
fn into_iter(self) -> IterMut<'a, T> {
23982398
self.iter_mut()
23992399
}
24002400
}

src/libcore/ops/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ mod impls {
187187
where F : FnMut<A>
188188
{
189189
type Output = F::Output;
190-
extern "rust-call" fn call_once(mut self, args: A) -> F::Output {
190+
extern "rust-call" fn call_once(self, args: A) -> F::Output {
191191
(*self).call_mut(args)
192192
}
193193
}

src/libcore/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ impl<'a, T> IntoIterator for &'a mut Option<T> {
872872
type Item = &'a mut T;
873873
type IntoIter = IterMut<'a, T>;
874874

875-
fn into_iter(mut self) -> IterMut<'a, T> {
875+
fn into_iter(self) -> IterMut<'a, T> {
876876
self.iter_mut()
877877
}
878878
}

src/libcore/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ impl<'a, T, E> IntoIterator for &'a mut Result<T, E> {
909909
type Item = &'a mut T;
910910
type IntoIter = IterMut<'a, T>;
911911

912-
fn into_iter(mut self) -> IterMut<'a, T> {
912+
fn into_iter(self) -> IterMut<'a, T> {
913913
self.iter_mut()
914914
}
915915
}

src/librustc/infer/error_reporting/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
415415
/// -------- this type is the same as a type argument in the other type, not highlighted
416416
/// ```
417417
fn highlight_outer(&self,
418-
mut value: &mut DiagnosticStyledString,
419-
mut other_value: &mut DiagnosticStyledString,
418+
value: &mut DiagnosticStyledString,
419+
other_value: &mut DiagnosticStyledString,
420420
name: String,
421421
sub: &ty::subst::Substs<'tcx>,
422422
pos: usize,

src/librustc/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ pub fn fully_normalize<'a, 'gcx, 'tcx, T>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
560560
{
561561
debug!("fully_normalize(value={:?})", value);
562562

563-
let mut selcx = &mut SelectionContext::new(infcx);
563+
let selcx = &mut SelectionContext::new(infcx);
564564
// FIXME (@jroesch) ISSUE 26721
565565
// I'm not sure if this is a bug or not, needs further investigation.
566566
// It appears that by reusing the fulfillment_cx here we incur more

src/librustc/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
494494
never_obligation.predicate = never_obligation.predicate.map_bound(|mut trait_pred| {
495495
// Swap out () with ! so we can check if the trait is impld for !
496496
{
497-
let mut trait_ref = &mut trait_pred.trait_ref;
497+
let trait_ref = &mut trait_pred.trait_ref;
498498
let unit_substs = trait_ref.substs;
499499
let mut never_substs = Vec::with_capacity(unit_substs.len());
500500
never_substs.push(From::from(tcx.types.never));

src/librustc/ty/inhabitedness/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
171171
match self.sty {
172172
TyAdt(def, substs) => {
173173
{
174-
let mut substs_set = visited.entry(def.did).or_insert(FxHashSet::default());
174+
let substs_set = visited.entry(def.did).or_insert(FxHashSet::default());
175175
if !substs_set.insert(substs) {
176176
// We are already calculating the inhabitedness of this type.
177177
// The type must contain a reference to itself. Break the
@@ -193,7 +193,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
193193
}
194194
}
195195
let ret = def.uninhabited_from(visited, tcx, substs);
196-
let mut substs_set = visited.get_mut(&def.did).unwrap();
196+
let substs_set = visited.get_mut(&def.did).unwrap();
197197
substs_set.remove(substs);
198198
ret
199199
},

src/librustc_allocator/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'a> AllocFnFactory<'a> {
188188
fn arg_ty(&self,
189189
ty: &AllocatorTy,
190190
args: &mut Vec<Arg>,
191-
mut ident: &mut FnMut() -> Ident) -> P<Expr> {
191+
ident: &mut FnMut() -> Ident) -> P<Expr> {
192192
match *ty {
193193
AllocatorTy::Layout => {
194194
let usize = self.cx.path_ident(self.span, Ident::from_str("usize"));
@@ -263,7 +263,7 @@ impl<'a> AllocFnFactory<'a> {
263263
fn ret_ty(&self,
264264
ty: &AllocatorTy,
265265
args: &mut Vec<Arg>,
266-
mut ident: &mut FnMut() -> Ident,
266+
ident: &mut FnMut() -> Ident,
267267
expr: P<Expr>) -> (P<Ty>, P<Expr>)
268268
{
269269
match *ty {

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) {
9898
let body_id = tcx.hir.body_owned_by(owner_id);
9999
let tables = tcx.typeck_tables_of(owner_def_id);
100100
let region_maps = tcx.region_maps(owner_def_id);
101-
let mut bccx = &mut BorrowckCtxt { tcx, tables, region_maps, owner_def_id };
101+
let bccx = &mut BorrowckCtxt { tcx, tables, region_maps, owner_def_id };
102102

103103
let body = bccx.tcx.hir.body(body_id);
104104

src/librustc_data_structures/array_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl<'a, A: Array> Drop for Drain<'a, A> {
260260
let start = source_array_vec.len();
261261
let tail = self.tail_start;
262262
{
263-
let mut arr = &mut source_array_vec.values as &mut [ManuallyDrop<_>];
263+
let arr = &mut source_array_vec.values as &mut [ManuallyDrop<_>];
264264
let src = arr.as_ptr().offset(tail as isize);
265265
let dst = arr.as_mut_ptr().offset(start as isize);
266266
ptr::copy(src, dst, self.tail_len);

src/librustc_data_structures/bitvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl BitMatrix {
166166
pub fn add(&mut self, source: usize, target: usize) -> bool {
167167
let (start, _) = self.range(source);
168168
let (word, mask) = word_mask(target);
169-
let mut vector = &mut self.vector[..];
169+
let vector = &mut self.vector[..];
170170
let v1 = vector[start + word];
171171
let v2 = v1 | mask;
172172
vector[start + word] = v2;

src/librustc_data_structures/indexed_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<'a, I: Idx, T> IntoIterator for &'a mut IndexVec<I, T> {
259259
type IntoIter = slice::IterMut<'a, T>;
260260

261261
#[inline]
262-
fn into_iter(mut self) -> slice::IterMut<'a, T> {
262+
fn into_iter(self) -> slice::IterMut<'a, T> {
263263
self.raw.iter_mut()
264264
}
265265
}

src/librustc_driver/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ fn show_content_with_pager(content: &String) {
422422

423423
match Command::new(pager_name).stdin(Stdio::piped()).spawn() {
424424
Ok(mut pager) => {
425-
if let Some(mut pipe) = pager.stdin.as_mut() {
425+
if let Some(pipe) = pager.stdin.as_mut() {
426426
if pipe.write_all(content.as_bytes()).is_err() {
427427
fallback_to_println = true;
428428
}

src/librustc_metadata/cstore_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl CrateStore for cstore::CStore {
479479
_ => {},
480480
}
481481

482-
let mut bfs_queue = &mut VecDeque::new();
482+
let bfs_queue = &mut VecDeque::new();
483483
let mut add_child = |bfs_queue: &mut VecDeque<_>, child: def::Export, parent: DefId| {
484484
let child = child.def.def_id();
485485

src/librustc_mir/build/matches/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
206206
self.schedule_drop(span, extent, &Lvalue::Local(local_id), var_ty);
207207
}
208208

209-
pub fn visit_bindings<F>(&mut self, pattern: &Pattern<'tcx>, mut f: &mut F)
209+
pub fn visit_bindings<F>(&mut self, pattern: &Pattern<'tcx>, f: &mut F)
210210
where F: FnMut(&mut Self, Mutability, Name, NodeId, Span, Ty<'tcx>)
211211
{
212212
match *pattern.kind {

src/librustc_mir/transform/type_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
720720
value,
721721
obligations);
722722

723-
let mut fulfill_cx = &mut self.fulfillment_cx;
723+
let fulfill_cx = &mut self.fulfillment_cx;
724724
for obligation in obligations {
725725
fulfill_cx.register_predicate_obligation(self.infcx, obligation);
726726
}

src/librustc_privacy/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
781781
hir::ItemTrait(.., ref trait_item_refs) => {
782782
self.check_item(item.id).generics().predicates();
783783
for trait_item_ref in trait_item_refs {
784-
let mut check = self.check_item(trait_item_ref.id.node_id);
784+
let check = self.check_item(trait_item_ref.id.node_id);
785785
check.generics().predicates();
786786
if trait_item_ref.kind != hir::AssociatedItemKind::Type ||
787787
trait_item_ref.defaultness.has_value() {
@@ -814,7 +814,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
814814
}
815815
hir::ItemImpl(.., ref trait_ref, _, ref impl_item_refs) => {
816816
{
817-
let mut check = self.check_item(item.id);
817+
let check = self.check_item(item.id);
818818
check.ty().generics().predicates();
819819
if trait_ref.is_some() {
820820
check.impl_trait_ref();

src/librustc_resolve/resolve_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl<'a> Resolver<'a> {
379379
// Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
380380
// during which the resolution might end up getting re-defined via a glob cycle.
381381
let (binding, t) = {
382-
let mut resolution = &mut *self.resolution(module, ident, ns).borrow_mut();
382+
let resolution = &mut *self.resolution(module, ident, ns).borrow_mut();
383383
let old_binding = resolution.binding();
384384

385385
let t = f(self, resolution);

src/librustc_trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
14651465
let mut output = i.to_string(scx.tcx());
14661466
output.push_str(" @@");
14671467
let mut empty = Vec::new();
1468-
let mut cgus = item_to_cgus.get_mut(i).unwrap_or(&mut empty);
1468+
let cgus = item_to_cgus.get_mut(i).unwrap_or(&mut empty);
14691469
cgus.as_mut_slice().sort_by_key(|&(ref name, _)| name.clone());
14701470
cgus.dedup();
14711471
for &(ref cgu_name, (linkage, _)) in cgus.iter() {

src/librustc_trans/partitioning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ fn place_root_translation_items<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
348348
CodegenUnit::empty(codegen_unit_name.clone())
349349
};
350350

351-
let mut codegen_unit = codegen_units.entry(codegen_unit_name.clone())
351+
let codegen_unit = codegen_units.entry(codegen_unit_name.clone())
352352
.or_insert_with(make_codegen_unit);
353353

354354
let (linkage, visibility) = match trans_item.explicit_linkage(tcx) {

src/librustc_typeck/check/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
12041204
}
12051205
}
12061206

1207-
if let Some(mut augment_error) = augment_error {
1207+
if let Some(augment_error) = augment_error {
12081208
augment_error(&mut db);
12091209
}
12101210

src/librustc_typeck/check/method/probe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
538538
// We can't use normalize_associated_types_in as it will pollute the
539539
// fcx's fulfillment context after this probe is over.
540540
let cause = traits::ObligationCause::misc(self.span, self.body_id);
541-
let mut selcx = &mut traits::SelectionContext::new(self.fcx);
541+
let selcx = &mut traits::SelectionContext::new(self.fcx);
542542
let traits::Normalized { value: xform_self_ty, obligations } =
543543
traits::normalize(selcx, self.param_env, cause, &xform_self_ty);
544544
debug!("assemble_inherent_impl_probe: xform_self_ty = {:?}",
@@ -749,7 +749,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
749749
// as it will pollute the fcx's fulfillment context after this probe
750750
// is over.
751751
let cause = traits::ObligationCause::misc(self.span, self.body_id);
752-
let mut selcx = &mut traits::SelectionContext::new(self.fcx);
752+
let selcx = &mut traits::SelectionContext::new(self.fcx);
753753
let traits::Normalized { value: xform_self_ty, obligations } =
754754
traits::normalize(selcx, self.param_env, cause, &xform_self_ty);
755755

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,8 +4147,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
41474147
let tail_expr_ty = tail_expr.map(|t| self.check_expr_with_expectation(t, expected));
41484148

41494149
let mut enclosing_breakables = self.enclosing_breakables.borrow_mut();
4150-
let mut ctxt = enclosing_breakables.find_breakable(blk.id);
4151-
let mut coerce = ctxt.coerce.as_mut().unwrap();
4150+
let ctxt = enclosing_breakables.find_breakable(blk.id);
4151+
let coerce = ctxt.coerce.as_mut().unwrap();
41524152
if let Some(tail_expr_ty) = tail_expr_ty {
41534153
let tail_expr = tail_expr.unwrap();
41544154
let cause = self.cause(tail_expr.span,

src/librustc_typeck/check/op.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
300300
lhs_expr: &'gcx hir::Expr,
301301
lhs_ty: Ty<'tcx>,
302302
rhs_ty: Ty<'tcx>,
303-
mut err: &mut errors::DiagnosticBuilder) -> bool {
303+
err: &mut errors::DiagnosticBuilder) -> bool {
304304
// If this function returns true it means a note was printed, so we don't need
305305
// to print the normal "implementation of `std::ops::Add` might be missing" note
306306
let mut is_string_addition = false;

src/libstd/collections/hash/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ impl<'a, K, V, S> IntoIterator for &'a mut HashMap<K, V, S>
16181618
type Item = (&'a K, &'a mut V);
16191619
type IntoIter = IterMut<'a, K, V>;
16201620

1621-
fn into_iter(mut self) -> IterMut<'a, K, V> {
1621+
fn into_iter(self) -> IterMut<'a, K, V> {
16221622
self.iter_mut()
16231623
}
16241624
}

src/libstd/sync/once.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl Once {
267267
#[cold]
268268
fn call_inner(&'static self,
269269
ignore_poisoning: bool,
270-
mut init: &mut FnMut(bool)) {
270+
init: &mut FnMut(bool)) {
271271
let mut state = self.state.load(Ordering::SeqCst);
272272

273273
'outer: loop {

src/libstd/sys/unix/rand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ pub use self::imp::OsRng;
1212

1313
use mem;
1414

15-
fn next_u32(mut fill_buf: &mut FnMut(&mut [u8])) -> u32 {
15+
fn next_u32(fill_buf: &mut FnMut(&mut [u8])) -> u32 {
1616
let mut buf: [u8; 4] = [0; 4];
1717
fill_buf(&mut buf);
1818
unsafe { mem::transmute::<[u8; 4], u32>(buf) }
1919
}
2020

21-
fn next_u64(mut fill_buf: &mut FnMut(&mut [u8])) -> u64 {
21+
fn next_u64(fill_buf: &mut FnMut(&mut [u8])) -> u64 {
2222
let mut buf: [u8; 8] = [0; 8];
2323
fill_buf(&mut buf);
2424
unsafe { mem::transmute::<[u8; 8], u64>(buf) }

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub enum NamedMatch {
211211

212212
fn nameize<I: Iterator<Item=NamedMatch>>(sess: &ParseSess, ms: &[TokenTree], mut res: I)
213213
-> NamedParseResult {
214-
fn n_rec<I: Iterator<Item=NamedMatch>>(sess: &ParseSess, m: &TokenTree, mut res: &mut I,
214+
fn n_rec<I: Iterator<Item=NamedMatch>>(sess: &ParseSess, m: &TokenTree, res: &mut I,
215215
ret_val: &mut HashMap<Ident, Rc<NamedMatch>>)
216216
-> Result<(), (syntax_pos::Span, String)> {
217217
match *m {
@@ -445,7 +445,7 @@ pub fn parse(sess: &ParseSess,
445445
/* error messages here could be improved with links to orig. rules */
446446
if token_name_eq(&parser.token, &token::Eof) {
447447
if eof_items.len() == 1 {
448-
let matches = eof_items[0].matches.iter_mut().map(|mut dv| {
448+
let matches = eof_items[0].matches.iter_mut().map(|dv| {
449449
Rc::make_mut(dv).pop().unwrap()
450450
});
451451
return nameize(sess, ms, matches);

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl TTMacroExpander for MacroRulesMacroExpander {
8686

8787
fn trace_macros_note(cx: &mut ExtCtxt, sp: Span, message: String) {
8888
let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp);
89-
let mut values: &mut Vec<String> = cx.expansions.entry(sp).or_insert_with(Vec::new);
89+
let values: &mut Vec<String> = cx.expansions.entry(sp).or_insert_with(Vec::new);
9090
values.push(message);
9191
}
9292

0 commit comments

Comments
 (0)