File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
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
163163``` rust
164164fn 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
167167contains the type ` &'a T ` which is only valid if ` T: 'a ` holds.
168168
169169Rust adds implied bounds for all inputs and outputs of functions. Inside of ` requires_t_outlives_a `
170170you can assume ` T: 'a ` to hold even if you don't explicitly specify this:
171- ``` rust
171+ ``` rust,compile_fail
172172fn 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
You can’t perform that action at this time.
0 commit comments