]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/issue-46095.rs
Rollup merge of #106798 - scottmcm:signum-via-cmp, r=Mark-Simulacrum
[rust.git] / tests / ui / borrowck / issue-46095.rs
1 // run-pass
2 struct A;
3
4 impl A {
5     fn take_mutably(&mut self) {}
6 }
7
8 fn identity<T>(t: T) -> T {
9     t
10 }
11
12 // Issue 46095
13 // Built-in indexing should be used even when the index is not
14 // trivially an integer
15 // Overloaded indexing would cause wrapped to be borrowed mutably
16
17 fn main() {
18     let mut a1 = A;
19     let mut a2 = A;
20
21     let wrapped = [&mut a1, &mut a2];
22
23     {
24         wrapped[0 + 1 - 1].take_mutably();
25     }
26
27     {
28         wrapped[identity(0)].take_mutably();
29     }
30 }