Skip to content

Commit 21d4ba2

Browse files
nikomatsakisGuillaumeGomez
authored andcommitted
add some comments
1 parent c30435b commit 21d4ba2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/librustc_typeck/check/demand.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,24 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
262262
None
263263
}
264264
(_, &ty::TyRef(_, checked)) => {
265+
// We have `&T`, check if what was expected was `T`. If so,
266+
// we may want to suggest adding a `*`, or removing
267+
// a `&`.
268+
//
269+
// (But, also check check the `expn_info()` to see if this is
270+
// a macro; if so, it's hard to extract the text and make a good
271+
// suggestion, so don't bother.)
265272
if self.infcx.can_sub(self.param_env, checked.ty, &expected).is_ok() &&
266273
expr.span.ctxt().outer().expn_info().is_none() {
267274
match expr.node {
275+
// Maybe remove `&`?
268276
hir::ExprAddrOf(_, ref expr) => {
269277
if let Ok(code) = self.tcx.sess.codemap().span_to_snippet(expr.span) {
270278
return Some(format!("try with `{}`", code));
271279
}
272280
}
281+
282+
// Maybe add `*`? Only if `T: Copy`.
273283
_ => {
274284
if !self.infcx.type_moves_by_default(self.param_env,
275285
checked.ty,

0 commit comments

Comments
 (0)