]> git.lizzy.rs Git - rust.git/blob - tests/ui/typeck/issue-74933.rs
Auto merge of #106092 - asquared31415:start_lang_item_checks, r=davidtwco
[rust.git] / tests / ui / typeck / issue-74933.rs
1 // check-pass
2 //
3 // rust-lang/rust#74933: Lifetime error when indexing with borrowed index
4
5 use std::ops::{Index, IndexMut};
6
7 struct S(V);
8 struct K<'a>(&'a ());
9 struct V;
10
11 impl<'a> Index<&'a K<'a>> for S {
12     type Output = V;
13
14     fn index(&self, _: &'a K<'a>) -> &V {
15         &self.0
16     }
17 }
18
19 impl<'a> IndexMut<&'a K<'a>> for S {
20     fn index_mut(&mut self, _: &'a K<'a>) -> &mut V {
21         &mut self.0
22     }
23 }
24
25 impl V {
26     fn foo(&mut self) {}
27 }
28
29 fn test(s: &mut S, k: &K<'_>) {
30     s[k] = V;
31     s[k].foo();
32 }
33
34 fn main() {
35     let mut s = S(V);
36     let k = K(&());
37     test(&mut s, &k);
38 }