Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc_typeck/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {

match expr.kind {
hir::ExprKind::Index(ref base_expr, ref index_expr) => {
let index_expr_ty = self.node_ty(index_expr.hir_id);
// We need to get the final type in case dereferences were needed for the trait
// to apply (#72002).
let index_expr_ty = self.tables.borrow().expr_ty_adjusted(index_expr);
self.convert_place_op_to_mutable(
PlaceOp::Index,
expr,
Expand Down
29 changes: 29 additions & 0 deletions src/test/ui/issues/issue-72002.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// check-pass
struct Indexable;

impl Indexable {
fn boo(&mut self) {}
}

impl std::ops::Index<&str> for Indexable {
type Output = Indexable;

fn index(&self, field: &str) -> &Indexable {
self
}
}

impl std::ops::IndexMut<&str> for Indexable {
fn index_mut(&mut self, field: &str) -> &mut Indexable {
self
}
}

fn main() {
let mut v = Indexable;
let field = "hello".to_string();

v[field.as_str()].boo();

v[&field].boo(); // < This should work
}