File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ // Checks for `if` expressions with respect to default match bindings.
2+ // Specifically, we do not accept `if cond { ... }` where `cond: &mut? bool`.
3+ // Meanwhile, `match cond { true => ..., _ => ... }` does accept that.
4+
5+ // FIXME(@rust-lang/lang-team): consider relaxing this?
6+
7+ fn b_ref < ' a > ( ) -> & ' a bool { & true }
8+ fn b_mut_ref < ' a > ( ) -> & ' a mut bool { & mut true }
9+
10+ fn main ( ) {
11+ // This is OK:
12+ match b_ref ( ) { true => { } , _ => { } }
13+ match b_mut_ref ( ) { true => { } , _ => { } }
14+ match & true { true => { } , _ => { } }
15+ match & mut true { true => { } , _ => { } }
16+
17+ // This is NOT:
18+ if b_ref ( ) { } //~ ERROR mismatched types [E0308]
19+ if b_mut_ref ( ) { } //~ ERROR mismatched types [E0308]
20+ if & true { } //~ ERROR mismatched types [E0308]
21+ if & mut true { } //~ ERROR mismatched types [E0308]
22+ }
Original file line number Diff line number Diff line change 1+ error[E0308]: mismatched types
2+ --> $DIR/if-no-match-bindings.rs:18:8
3+ |
4+ LL | if b_ref() {}
5+ | ^^^^^^^ expected bool, found &bool
6+ |
7+ = note: expected type `bool`
8+ found type `&bool`
9+
10+ error[E0308]: mismatched types
11+ --> $DIR/if-no-match-bindings.rs:19:8
12+ |
13+ LL | if b_mut_ref() {}
14+ | ^^^^^^^^^^^ expected bool, found &mut bool
15+ |
16+ = note: expected type `bool`
17+ found type `&mut bool`
18+
19+ error[E0308]: mismatched types
20+ --> $DIR/if-no-match-bindings.rs:20:8
21+ |
22+ LL | if &true {}
23+ | ^^^^^ expected bool, found &bool
24+ |
25+ = note: expected type `bool`
26+ found type `&bool`
27+
28+ error[E0308]: mismatched types
29+ --> $DIR/if-no-match-bindings.rs:21:8
30+ |
31+ LL | if &mut true {}
32+ | ^^^^^^^^^ expected bool, found &mut bool
33+ |
34+ = note: expected type `bool`
35+ found type `&mut bool`
36+
37+ error: aborting due to 4 previous errors
38+
39+ For more information about this error, try `rustc --explain E0308`.
You can’t perform that action at this time.
0 commit comments