File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std:: ops:: Index ;
2
+
3
+ struct Test ;
4
+ struct Container ( Test ) ;
5
+
6
+ impl Test {
7
+ fn test ( & mut self ) { }
8
+ }
9
+
10
+ impl < ' a > Index < & ' a bool > for Container {
11
+ type Output = Test ;
12
+
13
+ fn index ( & self , _index : & ' a bool ) -> & Test {
14
+ & self . 0
15
+ }
16
+ }
17
+
18
+ fn main ( ) {
19
+ let container = Container ( Test ) ;
20
+ let mut val = true ;
21
+ container[ & mut val] . test ( ) ; //~ ERROR: cannot borrow data
22
+ }
Original file line number Diff line number Diff line change
1
+ error[E0596]: cannot borrow data in an index of `Container` as mutable
2
+ --> $DIR/issue-44405.rs:21:5
3
+ |
4
+ LL | container[&mut val].test();
5
+ | ^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
6
+ |
7
+ = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `Container`
8
+
9
+ error: aborting due to previous error
10
+
11
+ For more information about this error, try `rustc --explain E0596`.
You can’t perform that action at this time.
0 commit comments