diff options
| author | bors <bors@rust-lang.org> | 2017-06-22 15:24:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-06-22 15:24:58 +0000 |
| commit | ab5bec25530aac43dfd64384b405c909b6e405e3 (patch) | |
| tree | cd10ff6cf849e2c3b92dee464495dbfc83c96503 /src/libcore | |
| parent | 74fa27928aceda1362a2266d9b9bf129999bc00a (diff) | |
| parent | 1409e707a2e6b152ab66a9d836e5e367f6f066cc (diff) | |
| download | rust-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.rs | 6 |
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); }; //! }, //! }; |
