Skip to content

Commit

Permalink
fixed double ref hint
Browse files Browse the repository at this point in the history
  • Loading branch information
rizakrko committed May 9, 2018
1 parent 127d243 commit fa8ac4a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
52 changes: 34 additions & 18 deletions src/librustc_typeck/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
format!("cannot use `{}=` on type `{}`",
op.node.as_str(), lhs_ty));
let mut suggested_deref = false;
if let TyRef(_, ref ty_mut) = lhs_ty.sty {
if let TyRef(_, mut ty_mut) = lhs_ty.sty {
if {
!self.infcx.type_moves_by_default(self.param_env,
ty_mut.ty,
Expand All @@ -269,10 +269,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
.is_ok()
} {
if let Ok(lstring) = codemap.span_to_snippet(lhs_expr.span) {
while let TyRef(_, ty_mut_inner) = ty_mut.ty.sty{
ty_mut = ty_mut_inner;
}
let msg = &format!(
"`{}=` can be used on '{}', you can \
dereference `{2}`: `*{2}`",
op.node.as_str(), ty_mut.ty, lstring);
op.node.as_str(),
ty_mut.ty,
lstring
);
err.help(msg);
suggested_deref = true;
}
Expand Down Expand Up @@ -300,14 +306,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// we don't want the note in the else clause to be emitted
} else if let ty::TyParam(_) = lhs_ty.sty {
// FIXME: point to span of param
err.note(
&format!("`{}` might need a bound for `{}`",
lhs_ty, missing_trait));
err.note(&format!(
"`{}` might need a bound for `{}`",
lhs_ty, missing_trait
));
} else if !suggested_deref {
err.note(
&format!("an implementation of `{}` might \
be missing for `{}`",
missing_trait, lhs_ty));
err.note(&format!(
"an implementation of `{}` might \
be missing for `{}`",
missing_trait, lhs_ty
));
}
}
err.emit();
Expand All @@ -318,7 +326,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
op.node.as_str(),
lhs_ty);
let mut suggested_deref = false;
if let TyRef(_, ref ty_mut) = lhs_ty.sty {
if let TyRef(_, mut ty_mut) = lhs_ty.sty {
if {
!self.infcx.type_moves_by_default(self.param_env,
ty_mut.ty,
Expand All @@ -329,10 +337,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
.is_ok()
} {
if let Ok(lstring) = codemap.span_to_snippet(lhs_expr.span) {
while let TyRef(_, ty_mut_inner) = ty_mut.ty.sty{
ty_mut = ty_mut_inner;
}
let msg = &format!(
"`{}` can be used on '{}', you can \
dereference `{2}`: `*{2}`",
op.node.as_str(), ty_mut.ty, lstring);
op.node.as_str(),
ty_mut.ty,
lstring
);
err.help(msg);
suggested_deref = true;
}
Expand Down Expand Up @@ -363,14 +377,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// we don't want the note in the else clause to be emitted
} else if let ty::TyParam(_) = lhs_ty.sty {
// FIXME: point to span of param
err.note(
&format!("`{}` might need a bound for `{}`",
lhs_ty, missing_trait));
err.note(&format!(
"`{}` might need a bound for `{}`",
lhs_ty, missing_trait
));
} else if !suggested_deref {
err.note(
&format!("an implementation of `{}` might \
be missing for `{}`",
missing_trait, lhs_ty));
err.note(&format!(
"an implementation of `{}` might \
be missing for `{}`",
missing_trait, lhs_ty
));
}
}
err.emit();
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/binary-op-on-double-ref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0369]: binary operation `%` cannot be applied to type `&&{integer}`
LL | x % 2 == 0
| ^^^^^
|
= help: `%` can be used on '&{integer}', you can dereference `x`: `*x`
= help: `%` can be used on '{integer}', you can dereference `x`: `*x`

error: aborting due to previous error

Expand Down

0 comments on commit fa8ac4a

Please sign in to comment.