Skip to content

Commit bd7cc77

Browse files
committed
Make the next variable mutable to allow for ref mut in for patterns.
1 parent 09bc092 commit bd7cc77

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/librustc/hir/lowering.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2170,12 +2170,12 @@ impl<'a> LoweringContext<'a> {
21702170
// let result = match ::std::iter::IntoIterator::into_iter(<head>) {
21712171
// mut iter => {
21722172
// [opt_ident]: loop {
2173-
// let next;
2173+
// let mut _next;
21742174
// match ::std::iter::Iterator::next(&mut iter) {
2175-
// ::std::option::Option::Some(val) => next = val,
2175+
// ::std::option::Option::Some(val) => _next = val,
21762176
// ::std::option::Option::None => break
21772177
// };
2178-
// let <pat> = next;
2178+
// let <pat> = _next;
21792179
// StmtExpr(<body>);
21802180
// }
21812181
// }
@@ -2188,8 +2188,8 @@ impl<'a> LoweringContext<'a> {
21882188

21892189
let iter = self.str_to_ident("iter");
21902190

2191-
let next_ident = self.str_to_ident("next");
2192-
let next_pat = self.pat_ident(e.span, next_ident);
2191+
let next_ident = self.str_to_ident("_next");
2192+
let next_pat = self.pat_ident_binding_mode(e.span, next_ident, hir::BindByValue(hir::MutMutable));
21932193

21942194
// `::std::option::Option::Some(val) => next = val`
21952195
let pat_arm = {
@@ -2235,13 +2235,13 @@ impl<'a> LoweringContext<'a> {
22352235

22362236
let next_expr = P(self.expr_ident(e.span, next_ident, next_pat.id));
22372237

2238-
// `let next`
2238+
// `let mut _next`
22392239
let next_let = self.stmt_let_pat(e.span,
22402240
None,
22412241
next_pat,
22422242
hir::LocalSource::ForLoopDesugar);
22432243

2244-
// `let <pat> = next`
2244+
// `let <pat> = _next`
22452245
let pat = self.lower_pat(pat);
22462246
let pat_let = self.stmt_let_pat(e.span,
22472247
Some(next_expr),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that for loops can bind elements as mutable references
12+
13+
fn main() {
14+
for ref mut _a in std::iter::once(true) {}
15+
}

0 commit comments

Comments
 (0)