Simplify for loop desugar

This commit is contained in:
Cameron Steffen 2021-10-25 23:33:12 -05:00
parent 3bfde2f1f4
commit 9c83f8c4d1
26 changed files with 181 additions and 256 deletions

View file

@ -183,7 +183,7 @@ pub fn add_loop_label_to_break() {
#[cfg(not(any(cfail1,cfail4)))]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
#[rustc_clean(cfg="cfail3")]
#[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
#[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
#[rustc_clean(cfg="cfail6")]
pub fn add_loop_label_to_break() {
let mut _x = 0;

View file

@ -7,39 +7,29 @@
let mut _2: std::ops::Range<i32>; // in scope 0 at $DIR/remove_storage_markers.rs:8:14: 8:19
let mut _3: std::ops::Range<i32>; // in scope 0 at $DIR/remove_storage_markers.rs:8:14: 8:19
let mut _5: (); // in scope 0 at $DIR/remove_storage_markers.rs:6:1: 11:2
let _7: (); // in scope 0 at $DIR/remove_storage_markers.rs:8:14: 8:19
let mut _8: std::option::Option<i32>; // in scope 0 at $DIR/remove_storage_markers.rs:8:14: 8:19
let _6: (); // in scope 0 at $DIR/remove_storage_markers.rs:8:14: 8:19
let mut _7: std::option::Option<i32>; // in scope 0 at $DIR/remove_storage_markers.rs:8:14: 8:19
let mut _8: &mut std::ops::Range<i32>; // in scope 0 at $DIR/remove_storage_markers.rs:8:14: 8:19
let mut _9: &mut std::ops::Range<i32>; // in scope 0 at $DIR/remove_storage_markers.rs:8:14: 8:19
let mut _10: &mut std::ops::Range<i32>; // in scope 0 at $DIR/remove_storage_markers.rs:8:14: 8:19
let mut _11: isize; // in scope 0 at $DIR/remove_storage_markers.rs:8:9: 8:10
let mut _13: i32; // in scope 0 at $DIR/remove_storage_markers.rs:8:9: 8:10
let mut _14: !; // in scope 0 at $DIR/remove_storage_markers.rs:8:5: 10:6
let _16: (); // in scope 0 at $DIR/remove_storage_markers.rs:8:20: 10:6
let mut _17: i32; // in scope 0 at $DIR/remove_storage_markers.rs:9:16: 9:17
let mut _10: isize; // in scope 0 at $DIR/remove_storage_markers.rs:8:5: 10:6
let mut _11: !; // in scope 0 at $DIR/remove_storage_markers.rs:8:5: 10:6
let mut _13: i32; // in scope 0 at $DIR/remove_storage_markers.rs:9:16: 9:17
scope 1 {
debug sum => _1; // in scope 1 at $DIR/remove_storage_markers.rs:7:9: 7:16
let mut _4: std::ops::Range<i32>; // in scope 1 at $DIR/remove_storage_markers.rs:8:14: 8:19
scope 2 {
debug iter => _4; // in scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19
let mut _6: i32; // in scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19
let _12: i32; // in scope 2 at $DIR/remove_storage_markers.rs:8:9: 8:10
scope 3 {
debug __next => _6; // in scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19
let _12: i32; // in scope 3 at $DIR/remove_storage_markers.rs:8:9: 8:10
let _15: i32; // in scope 3 at $DIR/remove_storage_markers.rs:8:9: 8:10
scope 4 {
debug val => _12; // in scope 4 at $DIR/remove_storage_markers.rs:8:9: 8:10
}
scope 5 {
debug i => _15; // in scope 5 at $DIR/remove_storage_markers.rs:8:9: 8:10
}
scope 7 (inlined iter::range::<impl Iterator for std::ops::Range<i32>>::next) { // at $DIR/remove_storage_markers.rs:8:14: 8:19
debug self => _9; // in scope 7 at $DIR/remove_storage_markers.rs:8:14: 8:19
let mut _18: &mut std::ops::Range<i32>; // in scope 7 at $DIR/remove_storage_markers.rs:8:14: 8:19
}
debug i => _12; // in scope 3 at $DIR/remove_storage_markers.rs:8:9: 8:10
}
scope 5 (inlined iter::range::<impl Iterator for std::ops::Range<i32>>::next) { // at $DIR/remove_storage_markers.rs:8:14: 8:19
debug self => _8; // in scope 5 at $DIR/remove_storage_markers.rs:8:14: 8:19
let mut _14: &mut std::ops::Range<i32>; // in scope 5 at $DIR/remove_storage_markers.rs:8:14: 8:19
}
}
scope 6 (inlined <std::ops::Range<i32> as IntoIterator>::into_iter) { // at $DIR/remove_storage_markers.rs:8:14: 8:19
debug self => _3; // in scope 6 at $DIR/remove_storage_markers.rs:8:14: 8:19
scope 4 (inlined <std::ops::Range<i32> as IntoIterator>::into_iter) { // at $DIR/remove_storage_markers.rs:8:14: 8:19
debug self => _3; // in scope 4 at $DIR/remove_storage_markers.rs:8:14: 8:19
}
}
@ -50,7 +40,7 @@
- StorageLive(_3); // scope 1 at $DIR/remove_storage_markers.rs:8:14: 8:19
(_3.0: i32) = const 0_i32; // scope 1 at $DIR/remove_storage_markers.rs:8:14: 8:19
(_3.1: i32) = const 10_i32; // scope 1 at $DIR/remove_storage_markers.rs:8:14: 8:19
_2 = move _3; // scope 6 at $DIR/remove_storage_markers.rs:8:14: 8:19
_2 = move _3; // scope 4 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageDead(_3); // scope 1 at $DIR/remove_storage_markers.rs:8:18: 8:19
- StorageLive(_4); // scope 1 at $DIR/remove_storage_markers.rs:8:14: 8:19
_4 = move _2; // scope 1 at $DIR/remove_storage_markers.rs:8:14: 8:19
@ -59,25 +49,39 @@
bb1: {
- StorageLive(_6); // scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageLive(_7); // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageLive(_8); // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageLive(_9); // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageLive(_10); // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19
_10 = &mut _4; // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19
_9 = &mut (*_10); // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageLive(_18); // scope 7 at $DIR/remove_storage_markers.rs:8:14: 8:19
_18 = &mut (*_9); // scope 7 at $DIR/remove_storage_markers.rs:8:14: 8:19
_8 = <std::ops::Range<i32> as iter::range::RangeIteratorImpl>::spec_next(move _18) -> bb4; // scope 7 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageLive(_7); // scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageLive(_8); // scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageLive(_9); // scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19
_9 = &mut _4; // scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19
_8 = &mut (*_9); // scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageLive(_14); // scope 5 at $DIR/remove_storage_markers.rs:8:14: 8:19
_14 = &mut (*_8); // scope 5 at $DIR/remove_storage_markers.rs:8:14: 8:19
_7 = <std::ops::Range<i32> as iter::range::RangeIteratorImpl>::spec_next(move _14) -> bb4; // scope 5 at $DIR/remove_storage_markers.rs:8:14: 8:19
// mir::Constant
// + span: $DIR/remove_storage_markers.rs:8:14: 8:19
// + literal: Const { ty: for<'r> fn(&'r mut std::ops::Range<i32>) -> std::option::Option<<std::ops::Range<i32> as std::iter::range::RangeIteratorImpl>::Item> {<std::ops::Range<i32> as std::iter::range::RangeIteratorImpl>::spec_next}, val: Value(Scalar(<ZST>)) }
}
bb2: {
_0 = const (); // scope 3 at $DIR/remove_storage_markers.rs:8:5: 10:6
- StorageDead(_10); // scope 3 at $DIR/remove_storage_markers.rs:8:18: 8:19
- StorageDead(_8); // scope 3 at $DIR/remove_storage_markers.rs:8:18: 8:19
- StorageDead(_7); // scope 3 at $DIR/remove_storage_markers.rs:8:18: 8:19
- StorageLive(_12); // scope 2 at $DIR/remove_storage_markers.rs:8:9: 8:10
_12 = ((_7 as Some).0: i32); // scope 2 at $DIR/remove_storage_markers.rs:8:9: 8:10
- StorageLive(_13); // scope 3 at $DIR/remove_storage_markers.rs:9:16: 9:17
_13 = _12; // scope 3 at $DIR/remove_storage_markers.rs:9:16: 9:17
_1 = Add(_1, move _13); // scope 3 at $DIR/remove_storage_markers.rs:9:9: 9:17
- StorageDead(_13); // scope 3 at $DIR/remove_storage_markers.rs:9:16: 9:17
_6 = const (); // scope 3 at $DIR/remove_storage_markers.rs:8:20: 10:6
- StorageDead(_12); // scope 2 at $DIR/remove_storage_markers.rs:10:5: 10:6
- StorageDead(_9); // scope 2 at $DIR/remove_storage_markers.rs:10:5: 10:6
- StorageDead(_7); // scope 2 at $DIR/remove_storage_markers.rs:10:5: 10:6
- StorageDead(_6); // scope 2 at $DIR/remove_storage_markers.rs:10:5: 10:6
_5 = const (); // scope 2 at $DIR/remove_storage_markers.rs:8:5: 10:6
goto -> bb1; // scope 2 at $DIR/remove_storage_markers.rs:8:5: 10:6
}
bb3: {
_0 = const (); // scope 2 at $DIR/remove_storage_markers.rs:8:5: 10:6
- StorageDead(_9); // scope 2 at $DIR/remove_storage_markers.rs:10:5: 10:6
- StorageDead(_7); // scope 2 at $DIR/remove_storage_markers.rs:10:5: 10:6
- StorageDead(_6); // scope 2 at $DIR/remove_storage_markers.rs:10:5: 10:6
- StorageDead(_4); // scope 1 at $DIR/remove_storage_markers.rs:10:5: 10:6
- StorageDead(_2); // scope 1 at $DIR/remove_storage_markers.rs:10:5: 10:6
@ -85,38 +89,11 @@
return; // scope 0 at $DIR/remove_storage_markers.rs:11:2: 11:2
}
bb3: {
- StorageLive(_12); // scope 3 at $DIR/remove_storage_markers.rs:8:9: 8:10
_12 = ((_8 as Some).0: i32); // scope 3 at $DIR/remove_storage_markers.rs:8:9: 8:10
- StorageLive(_13); // scope 4 at $DIR/remove_storage_markers.rs:8:9: 8:10
_13 = _12; // scope 4 at $DIR/remove_storage_markers.rs:8:9: 8:10
_6 = move _13; // scope 4 at $DIR/remove_storage_markers.rs:8:9: 8:10
_7 = const (); // scope 4 at $DIR/remove_storage_markers.rs:8:9: 8:10
- StorageDead(_13); // scope 4 at $DIR/remove_storage_markers.rs:8:9: 8:10
- StorageDead(_12); // scope 3 at $DIR/remove_storage_markers.rs:8:9: 8:10
- StorageDead(_10); // scope 3 at $DIR/remove_storage_markers.rs:8:18: 8:19
- StorageDead(_8); // scope 3 at $DIR/remove_storage_markers.rs:8:18: 8:19
- StorageDead(_7); // scope 3 at $DIR/remove_storage_markers.rs:8:18: 8:19
- StorageLive(_15); // scope 3 at $DIR/remove_storage_markers.rs:8:9: 8:10
_15 = _6; // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageLive(_16); // scope 5 at $DIR/remove_storage_markers.rs:8:20: 10:6
- StorageLive(_17); // scope 5 at $DIR/remove_storage_markers.rs:9:16: 9:17
_17 = _15; // scope 5 at $DIR/remove_storage_markers.rs:9:16: 9:17
_1 = Add(_1, move _17); // scope 5 at $DIR/remove_storage_markers.rs:9:9: 9:17
- StorageDead(_17); // scope 5 at $DIR/remove_storage_markers.rs:9:16: 9:17
_16 = const (); // scope 5 at $DIR/remove_storage_markers.rs:8:20: 10:6
- StorageDead(_16); // scope 5 at $DIR/remove_storage_markers.rs:10:5: 10:6
_5 = const (); // scope 2 at $DIR/remove_storage_markers.rs:8:5: 10:6
- StorageDead(_15); // scope 3 at $DIR/remove_storage_markers.rs:10:5: 10:6
- StorageDead(_6); // scope 2 at $DIR/remove_storage_markers.rs:10:5: 10:6
goto -> bb1; // scope 2 at $DIR/remove_storage_markers.rs:8:5: 10:6
}
bb4: {
- StorageDead(_18); // scope 7 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageDead(_9); // scope 3 at $DIR/remove_storage_markers.rs:8:18: 8:19
_11 = discriminant(_8); // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19
switchInt(move _11) -> [0_isize: bb2, otherwise: bb3]; // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageDead(_14); // scope 5 at $DIR/remove_storage_markers.rs:8:14: 8:19
- StorageDead(_8); // scope 2 at $DIR/remove_storage_markers.rs:8:18: 8:19
_10 = discriminant(_7); // scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19
switchInt(move _10) -> [0_isize: bb3, otherwise: bb2]; // scope 2 at $DIR/remove_storage_markers.rs:8:14: 8:19
}
}

View file

@ -27,7 +27,7 @@ where
let key = f(x);
result.entry(key).or_insert(Vec::new()).push(x);
}
result //~ ERROR cannot return value referencing local binding
result //~ ERROR cannot return value referencing temporary value
}
fn main() {}

View file

@ -1,8 +1,8 @@
error[E0515]: cannot return value referencing local binding
error[E0515]: cannot return value referencing temporary value
--> $DIR/return-local-binding-from-desugaring.rs:30:5
|
LL | for ref x in xs {
| -- local binding introduced here
| -- temporary value created here
...
LL | result
| ^^^^^^ returns a value referencing data owned by the current function

View file

@ -1,8 +1,10 @@
error[E0282]: type annotations needed
--> $DIR/for-loop-unconstrained-element-type.rs:8:14
--> $DIR/for-loop-unconstrained-element-type.rs:8:9
|
LL | for i in Vec::new() { }
| ^^^^^^^^^^ the element type for this iterator is not specified
| ^ ---------- the element type for this iterator is not specified
| |
| cannot infer type
error: aborting due to previous error

View file

@ -1,8 +1,8 @@
error[E0282]: type annotations needed for `&(_,)`
error[E0282]: type annotations needed for `(_,)`
--> $DIR/issue-20261.rs:4:11
|
LL | for (ref i,) in [].iter() {
| --------- the element type for this iterator is not specified
| --------- this method call resolves to `std::slice::Iter<'_, T>`
LL | i.clone();
| ^^^^^ cannot infer type
|

View file

@ -3,5 +3,4 @@ use std::collections::HashMap;
fn main() {
for _ in HashMap::new().iter().cloned() {} //~ ERROR type mismatch
//~^ ERROR type mismatch
//~| ERROR type mismatch
}

View file

@ -23,16 +23,6 @@ LL | for _ in HashMap::new().iter().cloned() {}
= note: required because of the requirements on the impl of `Iterator` for `Cloned<std::collections::hash_map::Iter<'_, _, _>>`
= note: required because of the requirements on the impl of `IntoIterator` for `Cloned<std::collections::hash_map::Iter<'_, _, _>>`
error[E0271]: type mismatch resolving `<std::collections::hash_map::Iter<'_, _, _> as Iterator>::Item == &_`
--> $DIR/issue-33941.rs:4:14
|
LL | for _ in HashMap::new().iter().cloned() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found tuple
|
= note: expected reference `&_`
found tuple `(&_, &_)`
= note: required because of the requirements on the impl of `Iterator` for `Cloned<std::collections::hash_map::Iter<'_, _, _>>`
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0271`.

View file

@ -2,7 +2,7 @@ error[E0596]: cannot borrow data in a `&` reference as mutable
--> $DIR/dont-print-desugared.rs:4:10
|
LL | for &ref mut x in s {}
| ^^^^^^^^^ cannot borrow as mutable through `&` reference
| ^^^^^^^^^ cannot borrow as mutable
error[E0597]: `y` does not live long enough
--> $DIR/dont-print-desugared.rs:17:16

View file

@ -2,12 +2,10 @@ error[E0713]: borrow may still be in use when destructor runs
--> $DIR/issue-53773.rs:41:22
|
LL | members.push(child.raw);
| ^^^^^^^^^
| -------------^^^^^^^^^- borrow later used here
LL |
LL | }
| - here, drop of `child` needs exclusive access to `*child.raw`, because the type `C<'_>` implements the `Drop` trait
LL | members.len();
| ------------- borrow later used here
|
= note: consider using a `let` binding to create a longer lived value

View file

@ -17,5 +17,4 @@ impl Iterator for Void {
fn main() {
for _ in unimplemented!() as Void {}
//~^ ERROR unreachable pattern
//~^^ ERROR unreachable pattern
}

View file

@ -10,11 +10,5 @@ note: the lint level is defined here
LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^
error: unreachable pattern
--> $DIR/unreachable-loop-patterns.rs:18:14
|
LL | for _ in unimplemented!() as Void {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to previous error