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

Add a note about Higher-Ranked Trait Bounds in docs on Closures. #33611

Merged
merged 2 commits into from
May 19, 2016

Conversation

vvanders
Copy link
Contributor

I hit a snag with lifetimes a few days ago and it wasn't until @birkenfeld pointed out Higher-Ranked Trait Bounds that I was able to solve the issue involving lifetimes on closure traits. This adds a small section in the book so that other users can find it.

r? @steveklabnik

When using closures that take references with explicit lifetimes sometimes
it's required to use where F: for<..> ... syntax to express the right
lifetimes. This adds a quick note to the docs so other users can discover
it as well.
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @steveklabnik (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

where F: for<'a> Fn(&'a 32) -> i32 {
```

This lets the rust compiler find the minimum lifetime to invoke our closure and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust, not rust

@steveklabnik
Copy link
Member

Thanks so much for this @vvanders ! I have one small grammar nit, and also, you need to add some annotations:

failures:

---- Taking_closures_as_arguments_5 stdout ----
    <anon>:4:2: 4:2 error: this file contains an un-closed delimiter
<anon>:4 }
          ^
<anon>:1:11: 1:12 help: did you mean to close this delimiter?
<anon>:1 fn main() {
                   ^
<anon>:3:21: 3:23 error: expected type, found `32`
<anon>:3     where F: Fn(&'a 32) -> i32 {
                             ^~
<anon>:3:23: 3:24 error: expected one of `+`, `,`, `->`, `::`, or `{`, found `)`
<anon>:3     where F: Fn(&'a 32) -> i32 {
                               ^
error: aborting due to previous error(s)
thread 'Taking_closures_as_arguments_5' panicked at 'Box<Any>', src/librustc/session/mod.rs:167
note: Run with `RUST_BACKTRACE=1` for a backtrace.

---- Taking_closures_as_arguments_6 stdout ----
    <anon>:4:2: 4:2 error: this file contains an un-closed delimiter
<anon>:4 }
          ^
<anon>:1:11: 1:12 help: did you mean to close this delimiter?
<anon>:1 fn main() {
                   ^
<anon>:3:29: 3:31 error: expected type, found `32`
<anon>:3     where F: for<'a> Fn(&'a 32) -> i32 {
                                     ^~
<anon>:3:31: 3:32 error: expected one of `+`, `,`, `->`, `::`, or `{`, found `)`
<anon>:3     where F: for<'a> Fn(&'a 32) -> i32 {
                                       ^
error: aborting due to previous error(s)
thread 'Taking_closures_as_arguments_6' panicked at 'Box<Any>', src/librustc/session/mod.rs:167


failures:
    Taking_closures_as_arguments_5
    Taking_closures_as_arguments_6

The examples get run as tests, so they don't work. Adding ignore will fix it:

```ignore

Update it with that, and this should be good to go 👍

@vvanders
Copy link
Contributor Author

Thanks for the feedback and happy to help where I can. I'll see if I can address those and get an updated PR sent.

@vvanders
Copy link
Contributor Author

Hey @steveklabnik, just wanted to check in here and make sure everything is good. Let me know if there's any further feedback or if you think this is okay to merge.

@steveklabnik
Copy link
Member

@vvanders ah! Sorry about that. GitHub doesn't send a message when you push new commits; I didn't know you'd done so.

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented May 19, 2016

📌 Commit 64feba0 has been approved by steveklabnik

Manishearth added a commit to Manishearth/rust that referenced this pull request May 19, 2016
Add a note about Higher-Ranked Trait Bounds in docs on Closures.

I hit a snag with lifetimes a few days ago and it wasn't until @birkenfeld pointed out Higher-Ranked Trait Bounds that I was able to solve the issue involving lifetimes on closure traits. This adds a small section in the book so that other users can find it.

r? @steveklabnik
bors added a commit that referenced this pull request May 19, 2016
Rollup of 10 pull requests

- Successful merges: #33353, #33611, #33696, #33698, #33705, #33708, #33712, #33720, #33721, #33730
- Failed merges:
@bors bors merged commit 64feba0 into rust-lang:master May 19, 2016
@vvanders
Copy link
Contributor Author

No worries, glad to have it merged :).

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 this pull request may close these issues.

4 participants