diff options
| author | Roman Stoliar <rizakrko@rambler.ru> | 2018-05-09 12:38:09 +0300 |
|---|---|---|
| committer | Roman Stoliar <rizakrko@rambler.ru> | 2018-05-11 15:12:53 +0300 |
| commit | d9b71d215677145bad8dd3ea8abb2114a3c9231e (patch) | |
| tree | 4a489e719d39df8b4846e8167f91978de1c2f605 | |
| parent | 747d5d99cdbe49d590b3e0b8856953f1a545fdd7 (diff) | |
fixed double ref hint
| -rw-r--r-- | src/librustc_typeck/check/op.rs | 52 | ||||
| -rw-r--r-- | src/test/ui/binary-op-on-double-ref.stderr | 2 |
2 files changed, 35 insertions, 19 deletions
diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 51a455dc25c..629b02bdf13 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -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, @@ -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; } @@ -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(); @@ -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, @@ -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; } @@ -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(); diff --git a/src/test/ui/binary-op-on-double-ref.stderr b/src/test/ui/binary-op-on-double-ref.stderr index 020d74bee52..c89defa3dd1 100644 --- a/src/test/ui/binary-op-on-double-ref.stderr +++ b/src/test/ui/binary-op-on-double-ref.stderr @@ -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 |
