Skip to content

Commit fcad3e1

Browse files
committed
review
1 parent 80d84bc commit fcad3e1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/trait-bounds.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,21 @@ Rust sometimes infers some bounds the user would have otherwise been required to
163163
```rust
164164
fn requires_t_outlives_a<'a, T>(x: &'a T) {}
165165
```
166-
While this function requires `t` to outlive `'a`, this is inferred as the function signature
166+
While this function requires `T` to outlive `'a`, this is inferred because the function signature
167167
contains the type `&'a T` which is only valid if `T: 'a` holds.
168168

169169
Rust adds implied bounds for all inputs and outputs of functions. Inside of `requires_t_outlives_a`
170170
you can assume `T: 'a` to hold even if you don't explicitly specify this:
171171
```rust
172172
fn requires_t_outlives_a<'a, T>(x: &'a T) {
173+
// This compiles, because `T: 'a` is implied by
174+
// the reference type `&'a T`.
175+
requires_t_outlives_a_not_implied::<'a, T>();
176+
}
177+
178+
fn not_implied<'a, T>() {
179+
// This errors, because `T: 'a` is not implied by
180+
// the function signature.
173181
requires_t_outlives_a_not_implied::<'a, T>();
174182
}
175183

0 commit comments

Comments
 (0)