Closed
Description
This code has some interesting results
fn foo(_: &[&str]) {}
fn bad(a: &str, b: &str) {
foo([a, b]);
}
fn good(a: &str, b: &str) {
foo([a.as_slice(), b.as_slice()]);
}
fn main() {}
foo.rs:4:12: 4:13 error: mismatched types: expected `&str` but found `&str` (lifetime mismatch)
foo.rs:4 foo([a, b]);
^
foo.rs:3:25: 5:1 note: the anonymous lifetime #2 defined on the block at 3:25...
foo.rs:3 fn bad(a: &str, b: &str) {
foo.rs:4 foo([a, b]);
foo.rs:5 }
foo.rs:3:25: 5:1 note: ...does not necessarily outlive the anonymous lifetime #1 defined on the block at 3:25
foo.rs:3 fn bad(a: &str, b: &str) {
foo.rs:4 foo([a, b]);
foo.rs:5 }
error: aborting due to previous error
I find it odd that if good
compiles then why bad
doesn't compile...