Skip to content

Commit 1c14973

Browse files
committed
fix wording/punctuation in "Lifetime bounds"
Clarify that "outlives" really means "lives at least as long as". Also fix some more minor punctuation and wording issues.
1 parent c0f756e commit 1c14973

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/trait-bounds.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ not be used as a bound for other types.
103103

104104
## Lifetime bounds
105105

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

110110
```rust
111111
fn f<'a, 'b>(x: &'a i32, mut y: &'b i32) where 'a: 'b {
@@ -114,9 +114,8 @@ fn f<'a, 'b>(x: &'a i32, mut y: &'b i32) where 'a: 'b {
114114
}
115115
```
116116

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

121120
## Higher-ranked trait bounds
122121

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

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

140-
Only a higher-ranked bound can be used here as the lifetime of the reference is
141-
shorter than a lifetime parameter on the function:
139+
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:
142140

143141
```rust
144142
fn call_on_ref_zero<F>(f: F) where for<'a> F: Fn(&'a i32) {
@@ -147,7 +145,7 @@ fn call_on_ref_zero<F>(f: F) where for<'a> F: Fn(&'a i32) {
147145
}
148146
```
149147

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

0 commit comments

Comments
 (0)