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

Lifetime documentation should include an example where the lifetime of a return is dependent on two arguments #25417

Closed
brianquinlan opened this issue May 14, 2015 · 4 comments · Fixed by #25883

Comments

@brianquinlan
Copy link
Contributor

The document page:
https://doc.rust-lang.org/book/lifetimes.html

For example:
fn <'a>a_or_b(a : &'a str, b : &'a str) -> &'a str

@steveklabnik
Copy link
Member

There is an example of the syntax in the elision section, but you're right that more and better examples would be good here, for sure.

@brianquinlan
Copy link
Contributor Author

What example were you thinking of? I couldn't see one.

@steveklabnik
Copy link
Member

Oh, two of the same! I was looking at

fn frob(s: &str, t: &str) -> &str; // ILLEGAL, two inputs
fn frob<'a, 'b>(s: &'a str, t: &'b str) -> &str; // Expanded: Output lifetime is unclear

which has two lifetimes, they're just different ones

@brianquinlan
Copy link
Contributor Author

Yes, two of the same. I guessed the syntax would be:
fn <'a,'b>a_or_b(a : &'a str, b : &'b str) -> &'a 'b str

but I was wrong :-)

steveklabnik added a commit to steveklabnik/rust that referenced this issue May 29, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this issue May 29, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this issue May 29, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this issue May 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants