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

@ -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