Skip to content

Commit f0a3296

Browse files
Zoxcbrson
authored andcommitted
Make the next variable mutable to allow for ref mut in for patterns.
1 parent cc273a5 commit f0a3296

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/librustc/hir/lowering.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,12 +2168,12 @@ impl<'a> LoweringContext<'a> {
21682168
// let result = match ::std::iter::IntoIterator::into_iter(<head>) {
21692169
// mut iter => {
21702170
// [opt_ident]: loop {
2171-
// let next;
2171+
// let mut _next;
21722172
// match ::std::iter::Iterator::next(&mut iter) {
2173-
// ::std::option::Option::Some(val) => next = val,
2173+
// ::std::option::Option::Some(val) => _next = val,
21742174
// ::std::option::Option::None => break
21752175
// };
2176-
// let <pat> = next;
2176+
// let <pat> = _next;
21772177
// StmtExpr(<body>);
21782178
// }
21792179
// }
@@ -2186,8 +2186,8 @@ impl<'a> LoweringContext<'a> {
21862186

21872187
let iter = self.str_to_ident("iter");
21882188

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

21922192
// `::std::option::Option::Some(val) => next = val`
21932193
let pat_arm = {
@@ -2233,13 +2233,13 @@ impl<'a> LoweringContext<'a> {
22332233

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

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

2242-
// `let <pat> = next`
2242+
// `let <pat> = _next`
22432243
let pat = self.lower_pat(pat);
22442244
let pat_let = self.stmt_let_pat(e.span,
22452245
Some(next_expr),
Lines changed: 15 additions & 0 deletions
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)