]> git.proxmox.com Git - rustc.git/blob - src/test/ui/if/if-no-match-bindings.rs
New upstream version 1.38.0+dfsg1
[rustc.git] / src / test / ui / if / if-no-match-bindings.rs
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
23 // This is also NOT:
24 while b_ref() {} //~ ERROR mismatched types [E0308]
25 while b_mut_ref() {} //~ ERROR mismatched types [E0308]
26 while &true {} //~ ERROR mismatched types [E0308]
27 while &mut true {} //~ ERROR mismatched types [E0308]
28 }