Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code shared from the Rust Playground
#![allow(unreachable_code)]
fn main() {
println!("{:?}", {
fn breed_cow<'a, 'b>(a: std::borrow::Cow<'a, str>) -> std::borrow::Cow<'b, str> { a.clone() }
});
}
/* ~~~~=== stderr ===~~~~
Compiling playground v0.0.1 (/playground)
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> src/main.rs:6:93
|
6 | fn breed_cow<'a, 'b>(a: std::borrow::Cow<'a, str>) -> std::borrow::Cow<'b, str> { a.clone() }
| ^^^^^
|
note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 6:22...
--> src/main.rs:6:22
|
6 | fn breed_cow<'a, 'b>(a: std::borrow::Cow<'a, str>) -> std::borrow::Cow<'b, str> { a.clone() }
| ^^
= note: ...so that the types are compatible:
expected &std::borrow::Cow<'_, str>
found &std::borrow::Cow<'a, str>
note: but, the lifetime must be valid for the lifetime 'b as defined on the function body at 6:26...
--> src/main.rs:6:26
|
6 | fn breed_cow<'a, 'b>(a: std::borrow::Cow<'a, str>) -> std::borrow::Cow<'b, str> { a.clone() }
| ^^
= note: ...so that the expression is assignable:
expected std::borrow::Cow<'b, _>
found std::borrow::Cow<'_, _>
error: aborting due to previous error
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
*/
/* ~~~~=== stdout ===~~~~
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.