about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_typeck/check/demand.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs
index 081ef6585b1..7110a1ba81d 100644
--- a/src/librustc_typeck/check/demand.rs
+++ b/src/librustc_typeck/check/demand.rs
@@ -262,14 +262,24 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
                 None
             }
             (_, &ty::TyRef(_, checked)) => {
+                // We have `&T`, check if what was expected was `T`. If so,
+                // we may want to suggest adding a `*`, or removing
+                // a `&`.
+                //
+                // (But, also check check the `expn_info()` to see if this is
+                // a macro; if so, it's hard to extract the text and make a good
+                // suggestion, so don't bother.)
                 if self.infcx.can_sub(self.param_env, checked.ty, &expected).is_ok() &&
                    expr.span.ctxt().outer().expn_info().is_none() {
                     match expr.node {
+                        // Maybe remove `&`?
                         hir::ExprAddrOf(_, ref expr) => {
                             if let Ok(code) = self.tcx.sess.codemap().span_to_snippet(expr.span) {
                                 return Some(format!("try with `{}`", code));
                             }
                         }
+
+                        // Maybe add `*`? Only if `T: Copy`.
                         _ => {
                             if !self.infcx.type_moves_by_default(self.param_env,
                                                                 checked.ty,