pub type cmt<'tcx> = Rc<cmt_<'tcx>>;
impl<'tcx> cmt_<'tcx> {
+ pub fn get_def(&self) -> Option<ast::NodeId> {
+ match self.cat {
+ Categorization::Deref(ref cmt, ..) |
+ Categorization::Interior(ref cmt, _) |
+ Categorization::Downcast(ref cmt, _) => {
+ if let Categorization::Local(nid) = cmt.cat {
+ Some(nid)
+ } else {
+ None
+ }
+ }
+ _ => None
+ }
+ }
+
pub fn get_field(&self, name: ast::Name) -> Option<DefId> {
match self.cat {
Categorization::Deref(ref cmt, ..) |
pub fn bckerr_to_diag(&self, err: &BckError<'tcx>) -> DiagnosticBuilder<'a> {
let span = err.span.clone();
let mut immutable_field = None;
+ let mut local_def = None;
let msg = &match err.code {
err_mutbl => {
}
None
});
+ local_def = err.cmt.get_def()
+ .and_then(|nid| {
+ if !self.tcx.hir.is_argument(nid) {
+ Some(self.tcx.hir.span(nid))
+ } else {
+ None
+ }
+ });
format!("cannot borrow {} as mutable", descr)
}
if let Some((span, msg)) = immutable_field {
db.span_label(span, &msg);
}
+ if let Some(span) = local_def {
+ db.span_label(span, &"this should be `mut`");
+ }
db
}