]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-72002.rs
Rollup merge of #92942 - Xaeroxe:raw_arg, r=dtolnay
[rust.git] / src / test / ui / issues / issue-72002.rs
1 // check-pass
2 struct Indexable;
3
4 impl Indexable {
5     fn boo(&mut self) {}
6 }
7
8 impl std::ops::Index<&str> for Indexable {
9     type Output = Indexable;
10
11     fn index(&self, field: &str) -> &Indexable {
12         self
13     }
14 }
15
16 impl std::ops::IndexMut<&str> for Indexable {
17     fn index_mut(&mut self, field: &str) -> &mut Indexable {
18         self
19     }
20 }
21
22 fn main() {
23     let mut v = Indexable;
24     let field = "hello".to_string();
25
26     v[field.as_str()].boo();
27
28     v[&field].boo(); // < This should work
29 }