2013-06-05 21:04:07 -04:00
|
|
|
// Test that we correctly consider the type of `match` to be the LUB
|
|
|
|
// of the various arms, particularly in the case where regions are
|
|
|
|
// involved.
|
|
|
|
|
2014-05-22 16:57:53 -07:00
|
|
|
pub fn opt_str0<'a>(maybestr: &'a Option<String>) -> &'a str {
|
2013-06-05 21:04:07 -04:00
|
|
|
match *maybestr {
|
|
|
|
Some(ref s) => {
|
2015-02-01 21:53:25 -05:00
|
|
|
let s: &'a str = s;
|
2013-06-05 21:04:07 -04:00
|
|
|
s
|
|
|
|
}
|
|
|
|
None => "(none)",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 16:57:53 -07:00
|
|
|
pub fn opt_str1<'a>(maybestr: &'a Option<String>) -> &'a str {
|
2013-06-05 21:04:07 -04:00
|
|
|
match *maybestr {
|
|
|
|
None => "(none)",
|
|
|
|
Some(ref s) => {
|
2015-02-01 21:53:25 -05:00
|
|
|
let s: &'a str = s;
|
2013-06-05 21:04:07 -04:00
|
|
|
s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 16:57:53 -07:00
|
|
|
pub fn opt_str2<'a>(maybestr: &'a Option<String>) -> &'static str {
|
2014-10-24 21:17:50 +02:00
|
|
|
match *maybestr {
|
2013-06-05 21:04:07 -04:00
|
|
|
None => "(none)",
|
|
|
|
Some(ref s) => {
|
2015-02-01 21:53:25 -05:00
|
|
|
let s: &'a str = s;
|
2022-04-01 19:51:50 -04:00
|
|
|
s
|
2022-04-01 13:13:25 -04:00
|
|
|
//~^ ERROR lifetime may not live long enough
|
2013-06-05 21:04:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 16:57:53 -07:00
|
|
|
pub fn opt_str3<'a>(maybestr: &'a Option<String>) -> &'static str {
|
2014-10-24 21:17:50 +02:00
|
|
|
match *maybestr {
|
2013-06-05 21:04:07 -04:00
|
|
|
Some(ref s) => {
|
2015-02-01 21:53:25 -05:00
|
|
|
let s: &'a str = s;
|
2022-04-01 19:51:50 -04:00
|
|
|
s
|
2022-04-01 13:13:25 -04:00
|
|
|
//~^ ERROR lifetime may not live long enough
|
2013-06-05 21:04:07 -04:00
|
|
|
}
|
|
|
|
None => "(none)",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-23 17:20:36 -07:00
|
|
|
fn main() {}
|