}
) = &self.mir.basic_blocks()[location.block].terminator {
if self.tcx.parent(id) == self.tcx.lang_items().index_trait() {
+
+ let mut found = false;
+ self.tcx.for_each_relevant_impl(
+ self.tcx.lang_items().index_mut_trait().unwrap(),
+ substs.type_at(0),
+ |_relevant_impl| {
+ found = true;
+ }
+ );
+
+ let extra = if found {
+ String::from("")
+ } else {
+ format!(", but it is not implemented for `{}`",
+ substs.type_at(0))
+ };
+
err.help(
&format!(
- "trait `IndexMut` is required to modify indexed content, \
- but it is not implemented for `{}`",
- substs.type_at(0),
+ "trait `IndexMut` is required to modify indexed content{}",
+ extra,
),
);
}
--- /dev/null
+error[E0596]: cannot borrow data in a `&` reference as mutable
+ --> $DIR/index-mut-help-with-impl.rs:19:5
+ |
+LL | Index::index(&v, 1..2).make_ascii_uppercase(); //~ ERROR
+ | ^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
+ |
+ = help: trait `IndexMut` is required to modify indexed content
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0596`.
--- /dev/null
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// When mutably indexing a type that implements `Index` and `IndexMut` but
+// `Index::index` is being used specifically, the normal special help message
+// should not mention a missing `IndexMut` impl.
+
+fn main() {
+ use std::ops::Index;
+
+ let v = String::from("dinosaur");
+ Index::index(&v, 1..2).make_ascii_uppercase(); //~ ERROR
+}
--- /dev/null
+error[E0596]: cannot borrow immutable borrowed content as mutable
+ --> $DIR/index-mut-help-with-impl.rs:19:5
+ |
+LL | Index::index(&v, 1..2).make_ascii_uppercase(); //~ ERROR
+ | ^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0596`.