Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created August 25, 2019 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/95d3d23e446fe5eed6b00d982f52abe8 to your computer and use it in GitHub Desktop.
Save rust-play/95d3d23e446fe5eed6b00d982f52abe8 to your computer and use it in GitHub Desktop.
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