From 21d4ba2ea66ee297e556af9b1e4e96130e2e1bcf Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 22 Sep 2017 10:37:46 -0400 Subject: [PATCH] add some comments --- src/librustc_typeck/check/demand.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) 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,