Suggest dereferencing boolean reference when used in 'if' or 'while'

Change-Id: I0c5c4d767be2647e6f017ae7bf83558c56dbca97
This commit is contained in:
wangxiangqing 2019-10-06 12:03:53 +08:00
parent 7870050796
commit 0b0aeaca43
2 changed files with 7 additions and 1 deletions

View file

@ -349,7 +349,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If the span is from a macro, then it's hard to extract the text
// and make a good suggestion, so don't bother.
let is_macro = sp.from_expansion();
let is_desugaring = match sp.desugaring_kind() {
Some(k) => sp.is_desugaring(k),
None => false
};
let is_macro = sp.from_expansion() && !is_desugaring;
match (&expr.kind, &expected.kind, &checked_ty.kind) {
(_, &ty::Ref(_, exp, _), &ty::Ref(_, check, _)) => match (&exp.kind, &check.kind) {

View file

@ -87,6 +87,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
if let Some(mut err) = self.demand_suptype_diag(expr.span, expected_ty, ty) {
self.suggest_ref_or_into(&mut err, expr, expected_ty, ty);
let expr = match &expr.kind {
ExprKind::DropTemps(expr) => expr,
_ => expr,