File tree 1 file changed +9
-1
lines changed 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -163,13 +163,21 @@ Rust sometimes infers some bounds the user would have otherwise been required to
163
163
``` rust
164
164
fn requires_t_outlives_a <'a , T >(x : & 'a T ) {}
165
165
```
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
167
167
contains the type ` &'a T ` which is only valid if ` T: 'a ` holds.
168
168
169
169
Rust adds implied bounds for all inputs and outputs of functions. Inside of ` requires_t_outlives_a `
170
170
you can assume ` T: 'a ` to hold even if you don't explicitly specify this:
171
171
``` rust
172
172
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.
173
181
requires_t_outlives_a_not_implied :: <'a , T >();
174
182
}
175
183
You can’t perform that action at this time.
0 commit comments