Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore arguments when looking for IndexMut for subsequent mut obligation #72068

Merged
merged 1 commit into from
May 19, 2020
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
}