Closed
Description
trait DescriptiveSpec<'r> {}
impl<'r, T> DescriptiveSpec<'r> for &'r T {}
fn from_spec<'r, T: DescriptiveSpec<'r>>(spec: &'r T) {}
fn matching_contains<'s, T: 's, I>(a: &mut &'s I) where &'s I: Sized {
from_spec(a);
}
fn main() {}
gives this error
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'r` due to conflicting requirements
--> src/main.rs:9:5
|
9 | from_spec(a);
| ^^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the function body at 8:1...
--> src/main.rs:8:1
|
8 | / fn matching_contains<'s, T: 's, I>(a: &mut &'s I) where &'s I: Sized {
9 | | from_spec(a);
10| | }
| |_^
note: ...so that reference does not outlive borrowed content
--> src/main.rs:9:15
|
9 | from_spec(a);
| ^
note: but, the lifetime must be valid for the lifetime 's as defined on the function body at 8:1...
--> src/main.rs:8:1
|
8 | / fn matching_contains<'s, T: 's, I>(a: &mut &'s I) where &'s I: Sized {
9 | | from_spec(a);
10| | }
| |_^
note: ...so that types are compatible (expected std::marker::Sized, found std::marker::Sized)
--> src/main.rs:9:5
|
9 | from_spec(a);
| ^^^^^^^^^
The note ...so that types are compatible (expected std::marker::Sized, found std::marker::Sized)
does not seem correct. This error is likely due to the function having two &'a I: Sized
bounds where 's
have two different lifetimes, see #21974.