1 Reference's lifetime of borrowed content doesn't match the expected lifetime.
3 Erroneous code example:
6 pub fn opt_str<'a>(maybestr: &'a Option<String>) -> &'static str {
7 if maybestr.is_none() {
10 let s: &'a str = maybestr.as_ref().unwrap();
11 s // Invalid lifetime!
16 To fix this error, either lessen the expected lifetime or find a way to not have
17 to use this reference outside of its current scope (by running the code directly
18 in the same block for example?):
21 // In this case, we can fix the issue by switching from "static" lifetime to 'a
22 pub fn opt_str<'a>(maybestr: &'a Option<String>) -> &'a str {
23 if maybestr.is_none() {
26 let s: &'a str = maybestr.as_ref().unwrap();