We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2cfcc0c commit 000f5cdCopy full SHA for 000f5cd
src/test/ui/typeck/issue-74933.rs
@@ -0,0 +1,38 @@
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
0 commit comments