about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-06-22 15:24:58 +0000
committerbors <bors@rust-lang.org>2017-06-22 15:24:58 +0000
commitab5bec25530aac43dfd64384b405c909b6e405e3 (patch)
treecd10ff6cf849e2c3b92dee464495dbfc83c96503 /src/libcore
parent74fa27928aceda1362a2266d9b9bf129999bc00a (diff)
parent1409e707a2e6b152ab66a9d836e5e367f6f066cc (diff)
downloadrust-ab5bec25530aac43dfd64384b405c909b6e405e3.tar.gz
rust-ab5bec25530aac43dfd64384b405c909b6e405e3.zip
Auto merge of #42634 - Zoxc:for-desugar2, r=nikomatsakis
Change the for-loop desugar so the `break` does not affect type inference. Fixes #42618

Rewrite the `for` loop desugaring to avoid contaminating the inference results. Under the older desugaring, `for x in vec![] { .. }` would erroneously type-check, even though the type of `vec![]` is unconstrained. (written by @nikomatsakis)
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/iter/mod.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs
index ee811513487..c91fd16391a 100644
--- a/src/libcore/iter/mod.rs
+++ b/src/libcore/iter/mod.rs
@@ -191,10 +191,12 @@
 //! {
 //!     let result = match IntoIterator::into_iter(values) {
 //!         mut iter => loop {
-//!             let x = match iter.next() {
-//!                 Some(val) => val,
+//!             let next;
+//!             match iter.next() {
+//!                 Some(val) => next = val,
 //!                 None => break,
 //!             };
+//!             let x = next;
 //!             let () = { println!("{}", x); };
 //!         },
 //!     };