Skip to content

Commit 0b0aeac

Browse files
committed
Suggest dereferencing boolean reference when used in 'if' or 'while'
Change-Id: I0c5c4d767be2647e6f017ae7bf83558c56dbca97
1 parent 7870050 commit 0b0aeac

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/librustc_typeck/check/demand.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
349349

350350
// If the span is from a macro, then it's hard to extract the text
351351
// and make a good suggestion, so don't bother.
352-
let is_macro = sp.from_expansion();
352+
let is_desugaring = match sp.desugaring_kind() {
353+
Some(k) => sp.is_desugaring(k),
354+
None => false
355+
};
356+
let is_macro = sp.from_expansion() && !is_desugaring;
353357

354358
match (&expr.kind, &expected.kind, &checked_ty.kind) {
355359
(_, &ty::Ref(_, exp, _), &ty::Ref(_, check, _)) => match (&exp.kind, &check.kind) {

src/librustc_typeck/check/expr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8787
}
8888

8989
if let Some(mut err) = self.demand_suptype_diag(expr.span, expected_ty, ty) {
90+
self.suggest_ref_or_into(&mut err, expr, expected_ty, ty);
91+
9092
let expr = match &expr.kind {
9193
ExprKind::DropTemps(expr) => expr,
9294
_ => expr,

0 commit comments

Comments
 (0)