]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/issue-83309-ice-immut-in-for-loop.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / issue-83309-ice-immut-in-for-loop.rs
1 // rust-lang/rust#83309: The compiler tries to suggest potential
2 // methods that return `&mut` items. However, when it doesn't
3 // find such methods, it still tries to add suggestions
4 // which then fails an assertion later because there was
5 // no suggestions to make.
6
7
8 fn main() {
9     for v in Query.iter_mut() {
10         //~^ NOTE this iterator yields `&` references
11         *v -= 1;
12         //~^ ERROR cannot assign to `*v`, which is behind a `&` reference
13         //~| NOTE `v` is a `&` reference, so the data it refers to cannot be written
14     }
15 }
16
17 pub struct Query;
18 pub struct QueryIter<'a>(&'a i32);
19
20 impl Query {
21     pub fn iter_mut<'a>(&'a mut self) -> QueryIter<'a> {
22         todo!();
23     }
24 }
25
26 impl<'a> Iterator for QueryIter<'a> {
27     type Item = &'a i32;
28
29     fn next(&mut self) -> Option<Self::Item> {
30         todo!();
31     }
32 }