Skip to content

Commit 8a164ac

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

File tree

2 files changed

+80
-12
lines changed

2 files changed

+80
-12
lines changed

src/test/ui/if/if-no-match-bindings.stderr

+34-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ error[E0308]: mismatched types
22
--> $DIR/if-no-match-bindings.rs:18:8
33
|
44
LL | if b_ref() {}
5-
| ^^^^^^^ expected bool, found &bool
5+
| ^^^^^^^
6+
| |
7+
| expected bool, found &bool
8+
| help: consider dereferencing the borrow: `*b_ref()`
69
|
710
= note: expected type `bool`
811
found type `&bool`
@@ -11,7 +14,10 @@ error[E0308]: mismatched types
1114
--> $DIR/if-no-match-bindings.rs:19:8
1215
|
1316
LL | if b_mut_ref() {}
14-
| ^^^^^^^^^^^ expected bool, found &mut bool
17+
| ^^^^^^^^^^^
18+
| |
19+
| expected bool, found &mut bool
20+
| help: consider dereferencing the borrow: `*b_mut_ref()`
1521
|
1622
= note: expected type `bool`
1723
found type `&mut bool`
@@ -20,7 +26,10 @@ error[E0308]: mismatched types
2026
--> $DIR/if-no-match-bindings.rs:20:8
2127
|
2228
LL | if &true {}
23-
| ^^^^^ expected bool, found &bool
29+
| ^^^^^
30+
| |
31+
| expected bool, found &bool
32+
| help: consider dereferencing the borrow: `*&true`
2433
|
2534
= note: expected type `bool`
2635
found type `&bool`
@@ -29,7 +38,10 @@ error[E0308]: mismatched types
2938
--> $DIR/if-no-match-bindings.rs:21:8
3039
|
3140
LL | if &mut true {}
32-
| ^^^^^^^^^ expected bool, found &mut bool
41+
| ^^^^^^^^^
42+
| |
43+
| expected bool, found &mut bool
44+
| help: consider dereferencing the borrow: `*&mut true`
3345
|
3446
= note: expected type `bool`
3547
found type `&mut bool`
@@ -38,7 +50,10 @@ error[E0308]: mismatched types
3850
--> $DIR/if-no-match-bindings.rs:24:11
3951
|
4052
LL | while b_ref() {}
41-
| ^^^^^^^ expected bool, found &bool
53+
| ^^^^^^^
54+
| |
55+
| expected bool, found &bool
56+
| help: consider dereferencing the borrow: `*b_ref()`
4257
|
4358
= note: expected type `bool`
4459
found type `&bool`
@@ -47,25 +62,34 @@ error[E0308]: mismatched types
4762
--> $DIR/if-no-match-bindings.rs:25:11
4863
|
4964
LL | while b_mut_ref() {}
50-
| ^^^^^^^^^^^ expected bool, found &mut bool
65+
| ^^^^^^^^^^^
66+
| |
67+
| expected bool, found &mut bool
68+
| help: consider dereferencing the borrow: `*b_mut_ref()`
5169
|
5270
= note: expected type `bool`
5371
found type `&mut bool`
5472

5573
error[E0308]: mismatched types
5674
--> $DIR/if-no-match-bindings.rs:26:11
5775
|
58-
LL | while &true {}
59-
| ^^^^^ expected bool, found &bool
76+
26 | while &true {}
77+
| ^^^^^
78+
| |
79+
| expected bool, found &bool
80+
| help: consider dereferencing the borrow: `*&true`
6081
|
6182
= note: expected type `bool`
6283
found type `&bool`
6384

6485
error[E0308]: mismatched types
6586
--> $DIR/if-no-match-bindings.rs:27:11
6687
|
67-
LL | while &mut true {}
68-
| ^^^^^^^^^ expected bool, found &mut bool
88+
27 | while &mut true {}
89+
| ^^^^^^^^^
90+
| |
91+
| expected bool, found &mut bool
92+
| help: consider dereferencing the borrow: `*&mut true`
6993
|
7094
= note: expected type `bool`
7195
found type `&mut bool`

src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr

+46-2
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,52 @@ warning: the feature `let_chains` is incomplete and may cause the compiler to cr
513513
LL | #![feature(let_chains)] // Avoid inflating `.stderr` with overzealous gates in this test.
514514
| ^^^^^^^^^^
515515

516+
warning: unnecessary parentheses around `if` condition
517+
--> $DIR/disallowed-positions.rs:51:8
518+
|
519+
LL | if (true || let 0 = 0) {}
520+
| ^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
521+
|
522+
= note: `#[warn(unused_parens)]` on by default
523+
524+
warning: unnecessary parentheses around `while` condition
525+
--> $DIR/disallowed-positions.rs:115:11
526+
|
527+
LL | while (true || let 0 = 0) {}
528+
| ^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
529+
530+
wrning: unnecessary parentheses around `let` head expression
531+
--> $DIR/disallowed-positions.rs:160:41
532+
|
533+
LL | if let Range { start: _, end: _ } = (true..true || false) { }
534+
| ^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
535+
536+
warning: unnecessary parentheses around `let` head expression
537+
--> $DIR/disallowed-positions.rs:162:41
538+
|
539+
LL | if let Range { start: _, end: _ } = (true..true && false) { }
540+
| ^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
541+
542+
warning: unnecessary parentheses around `let` head expression
543+
--> $DIR/disallowed-positions.rs:164:44
544+
|
545+
LL | while let Range { start: _, end: _ } = (true..true || false) { }
546+
| ^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
547+
548+
warning: unnecessary parentheses around `let` head expression
549+
--> $DIR/disallowed-positions.rs:166:44
550+
|
551+
LL | while let Range { start: _, end: _ } = (true..true && false) { }
552+
| ^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
553+
516554
error[E0308]: mismatched types
517555
--> $DIR/disallowed-positions.rs:32:8
518556
|
519557
LL | if &let 0 = 0 {}
520-
| ^^^^^^^^^^ expected bool, found &bool
558+
| ^^^^^^^^^^
559+
| |
560+
| expected bool, found &bool
561+
| help: consider dereferencing the borrow: `*&let 0 = 0`
521562
|
522563
= note: expected type `bool`
523564
found type `&bool`
@@ -702,7 +743,10 @@ error[E0308]: mismatched types
702743
--> $DIR/disallowed-positions.rs:96:11
703744
|
704745
LL | while &let 0 = 0 {}
705-
| ^^^^^^^^^^ expected bool, found &bool
746+
| ^^^^^^^^^^
747+
| |
748+
| expected bool, found &bool
749+
| help: consider dereferencing the borrow: `*&let 0 = 0`
706750
|
707751
= note: expected type `bool`
708752
found type `&bool`

0 commit comments

Comments
 (0)