]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/lub-if.rs
Auto merge of #101138 - Rejyr:diagnostic-migration-rustc-lint-pt2, r=davidtwco
[rust.git] / tests / ui / nll / lub-if.rs
1 // Test that we correctly consider the type of `match` to be the LUB
2 // of the various arms, particularly in the case where regions are
3 // involved.
4
5 pub fn opt_str0<'a>(maybestr: &'a Option<String>) -> &'a str {
6     if maybestr.is_none() {
7         "(none)"
8     } else {
9         let s: &'a str = maybestr.as_ref().unwrap();
10         s
11     }
12 }
13
14 pub fn opt_str1<'a>(maybestr: &'a Option<String>) -> &'a str {
15     if maybestr.is_some() {
16         let s: &'a str = maybestr.as_ref().unwrap();
17         s
18     } else {
19         "(none)"
20     }
21 }
22
23 pub fn opt_str2<'a>(maybestr: &'a Option<String>) -> &'static str {
24     if maybestr.is_none() {
25         "(none)"
26     } else {
27         let s: &'a str = maybestr.as_ref().unwrap();
28         s
29         //~^ ERROR lifetime may not live long enough
30     }
31 }
32
33 pub fn opt_str3<'a>(maybestr: &'a Option<String>) -> &'static str {
34     if maybestr.is_some() {
35         let s: &'a str = maybestr.as_ref().unwrap();
36         s
37         //~^ ERROR lifetime may not live long enough
38     } else {
39         "(none)"
40     }
41 }
42
43
44 fn main() {}