about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Kalbertodt <lukas.kalbertodt@gmail.com>2018-08-07 22:38:14 +0200
committerLukas Kalbertodt <lukas.kalbertodt@gmail.com>2018-08-07 23:08:34 +0200
commit764d472b1f04041adfcf91b4a5486712b6de41f2 (patch)
treef9f580188b9d9586c1958033c987663c2c9d2c4f
parent9d59c6b76e96005201d3b66dae946cc01dc5e565 (diff)
downloadrust-764d472b1f04041adfcf91b4a5486712b6de41f2.tar.gz
rust-764d472b1f04041adfcf91b4a5486712b6de41f2.zip
Make `IndexMut` note apply to more cases
Previously it was only emitted for assigments, which was an
unnecessary restriction. Now it doesn't care where the mutability
comes from.

This commit also adds `` quotes around the printed type.
-rw-r--r--src/librustc_borrowck/borrowck/mod.rs44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs
index 97348c168de..2e16e316a18 100644
--- a/src/librustc_borrowck/borrowck/mod.rs
+++ b/src/librustc_borrowck/borrowck/mod.rs
@@ -882,28 +882,6 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
                             }
                         }
 
-                        // We add a special note about `IndexMut`, if the source of this error
-                        // is the fact that `Index` is implemented, but `IndexMut` is not. Needing
-                        // to implement two traits for "one operator" is not very intuitive for
-                        // many programmers.
-                        if err.cmt.note == mc::NoteIndex {
-                            let node_id = self.tcx.hir.hir_to_node_id(err.cmt.hir_id);
-                            let node =  self.tcx.hir.get(node_id);
-
-                            // This pattern probably always matches.
-                            if let hir_map::NodeExpr(
-                                hir::Expr { node: hir::ExprKind::Index(lhs, _), ..}
-                            ) = node {
-                                let ty = self.tables.expr_ty(lhs);
-
-                                db.help(&format!(
-                                    "trait `IndexMut` is required to modify indexed content, but \
-                                     it is not implemented for {}",
-                                    ty
-                                ));
-                            }
-                        }
-
                         db
                     }
                     BorrowViolation(euv::ClosureCapture(_)) => {
@@ -924,6 +902,28 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
                     }
                 };
 
+                // We add a special note about `IndexMut`, if the source of this error
+                // is the fact that `Index` is implemented, but `IndexMut` is not. Needing
+                // to implement two traits for "one operator" is not very intuitive for
+                // many programmers.
+                if err.cmt.note == mc::NoteIndex {
+                    let node_id = self.tcx.hir.hir_to_node_id(err.cmt.hir_id);
+                    let node =  self.tcx.hir.get(node_id);
+
+                    // This pattern probably always matches.
+                    if let hir_map::NodeExpr(
+                        hir::Expr { node: hir::ExprKind::Index(lhs, _), ..}
+                    ) = node {
+                        let ty = self.tables.expr_ty(lhs);
+
+                        db.help(&format!(
+                            "trait `IndexMut` is required to modify indexed content, but \
+                             it is not implemented for `{}`",
+                            ty
+                        ));
+                    }
+                }
+
                 self.note_and_explain_mutbl_error(&mut db, &err, &error_span);
                 self.note_immutability_blame(
                     &mut db,