You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the code below Rust fails to infer an appropriate lifetime, even though y and w
clearly both live long enough to compare them.
Note that the suggested fix of giving the &str contained in y the lifetime 'a is undesirable in case y lives shorter than x and the returned value.
fntest<'a>(x:&'aOption<String>,y:Option<&str>) -> Option<&'aOption<String>>{let w = x.as_ref().map(|z| z.as_slice());if y == w {returnSome(x);}None}fnmain(){let x = Some("asdf".to_string());println!("{}", test(&x,Some("foo")));}
<anon>:1:1: 7:2 note: consider using an explicit lifetime parameter as shown: fn test<'a>(x: &'a Option<String>, y: Option<&'a str>) ->
Option<&'a Option<String>>
<anon>:1 fn test<'a>(x: &'a Option<String>, y: Option<&str>) -> Option<&'a Option<String>> {
<anon>:2 let w = x.as_ref().map(|z| z.as_slice());
<anon>:3 if y == w {
<anon>:4 return Some(x);
<anon>:5 }
<anon>:6 None
...
<anon>:2:13: 2:23 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
<anon>:2 let w = x.as_ref().map(|z| z.as_slice());
^~~~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101
The text was updated successfully, but these errors were encountered:
also features an updated version of `lex!` which allows for
user-defined parsers (at expense of a slight syntax modification);
we need it as, say, `f32` and `f64` can't be simply unified to
the same code without introducing a new trait.
a new trait `FromStrPrefix` subsumes the existing `scan_*` extension
methods, and thus `util::std::str` has been greatly reduced.
also due to the recent lifetime inference problem (rust-lang/rust#15140)
we now use custom methods `.as_ref_slice()` and `.as_ref_slice_or()`
for the major source of this problem.
In the code below Rust fails to infer an appropriate lifetime, even though
y
andw
clearly both live long enough to compare them.
Note that the suggested fix of giving the
&str
contained iny
the lifetime'a
is undesirable in casey
lives shorter thanx
and the returned value.The text was updated successfully, but these errors were encountered: