Skip to content

Commit

Permalink
fix wording/punctuation in "Lifetime bounds"
Browse files Browse the repository at this point in the history
Clarify that "outlives" really means "lives at least as long as".
Also fix some more minor punctuation and wording issues.
  • Loading branch information
tlyu committed Jul 15, 2021
1 parent a162596 commit f5088ea
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/trait-bounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ not be used as a bound for other types.

## Lifetime bounds

Lifetime bounds can be applied to types or other lifetimes. The bound `'a: 'b`
is usually read as `'a` *outlives* `'b`. `'a: 'b` means that `'a` lasts longer
than `'b`, so a reference `&'a ()` is valid whenever `&'b ()` is valid.
Lifetime bounds can be applied to types or to other lifetimes.
The bound `'a: 'b` is usually read as `'a` *outlives* `'b`.
`'a: 'b` means that `'a` lasts at least as long as `'b`, so a reference `&'a ()` is valid whenever `&'b ()` is valid.

```rust
fn f<'a, 'b>(x: &'a i32, mut y: &'b i32) where 'a: 'b {
Expand All @@ -114,9 +114,8 @@ fn f<'a, 'b>(x: &'a i32, mut y: &'b i32) where 'a: 'b {
}
```

`T: 'a` means that all lifetime parameters of `T` outlive `'a`. For example if
`'a` is an unconstrained lifetime parameter then `i32: 'static` and
`&'static str: 'a` are satisfied but `Vec<&'a ()>: 'static` is not.
`T: 'a` means that all lifetime parameters of `T` outlive `'a`.
For example, if `'a` is an unconstrained lifetime parameter, then `i32: 'static` and `&'static str: 'a` are satisfied, but `Vec<&'a ()>: 'static` is not.

## Higher-ranked trait bounds

Expand All @@ -137,8 +136,7 @@ impl<'a> PartialEq<i32> for &'a T {

and could then be used to compare a `&'a T` with any lifetime to an `i32`.

Only a higher-ranked bound can be used here as the lifetime of the reference is
shorter than a lifetime parameter on the function:
Only a higher-ranked bound can be used here, because the lifetime of the reference is shorter than any possible lifetime parameter on the function:

```rust
fn call_on_ref_zero<F>(f: F) where for<'a> F: Fn(&'a i32) {
Expand All @@ -147,7 +145,7 @@ fn call_on_ref_zero<F>(f: F) where for<'a> F: Fn(&'a i32) {
}
```

Higher-ranked lifetimes may also be specified just before the trait, the only
Higher-ranked lifetimes may also be specified just before the trait: the only
difference is the scope of the lifetime parameter, which extends only to the
end of the following trait instead of the whole bound. This function is
equivalent to the last one.
Expand Down

0 comments on commit f5088ea

Please sign in to comment.