Skip to content

Anonymous regions only sometimes getting related #8874

Closed
@alexcrichton

Description

@alexcrichton

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...

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions