Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymous regions only sometimes getting related #8874

Closed
alexcrichton opened this issue Aug 30, 2013 · 3 comments
Closed

Anonymous regions only sometimes getting related #8874

alexcrichton opened this issue Aug 30, 2013 · 3 comments
Labels
A-lifetimes Area: Lifetimes / regions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@alexcrichton
Copy link
Member

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

@nikomatsakis
Copy link
Contributor

That is somewhat odd, needs more investigation.

@aturon
Copy link
Member

aturon commented Dec 15, 2014

Triage visit. This example is now broken for other reasons. I've tried a few variations, and cannot reproduce the original issue.

@alexcrichton
Copy link
Member Author

This compiles today:

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() {}

Flagging as needstest

@alexcrichton alexcrichton added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 15, 2014
@bors bors closed this as completed in dd8fdff Dec 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

3 participants