Skip to content

Commit f01e75f

Browse files
lcnrehuss
authored andcommitted
review
1 parent f193405 commit f01e75f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/trait-bounds.md

Lines changed: 10 additions & 2 deletions
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:
171-
```rust
171+
```rust,compile_fail
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)