Skip to content

Commit 55f15d7

Browse files
committed
Add test for issue-44405
1 parent 642ee70 commit 55f15d7

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/test/ui/issues/issue-44405.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

src/test/ui/issues/issue-44405.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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`.

0 commit comments

Comments
 (0)