]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/mut-borrow-in-loop-2.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / mut-borrow-in-loop-2.rs
1 // run-rustfix
2 #![allow(dead_code)]
3
4 struct Events<R>(R);
5
6 struct Other;
7
8 pub trait Trait<T> {
9     fn handle(value: T) -> Self;
10 }
11
12 // Blanket impl. (If you comment this out, compiler figures out that it
13 // is passing an `&mut` to a method that must be expecting an `&mut`,
14 // and injects an auto-reborrow.)
15 impl<T, U> Trait<U> for T where T: From<U> {
16     fn handle(_: U) -> Self { unimplemented!() }
17 }
18
19 impl<'a, R> Trait<&'a mut Events<R>> for Other {
20     fn handle(_: &'a mut Events<R>) -> Self { unimplemented!() }
21 }
22
23 fn this_compiles<'a, R>(value: &'a mut Events<R>) {
24     for _ in 0..3 {
25         Other::handle(&mut *value);
26     }
27 }
28
29 fn this_does_not<'a, R>(value: &'a mut Events<R>) {
30     for _ in 0..3 {
31         Other::handle(value); //~ ERROR use of moved value: `value`
32     }
33 }
34
35 fn main() {}