You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/trait-bounds.md
+26
Original file line number
Diff line number
Diff line change
@@ -73,6 +73,26 @@ fn name_figure<U: Shape>(
73
73
}
74
74
```
75
75
76
+
Bounds that don't use the item's parameters or [higher-ranked lifetimes] are checked when the item is defined.
77
+
It is an error for such a bound to be false.
78
+
79
+
[`Copy`], [`Clone`], and [`Sized`] bounds are also checked for certain generic types when using the item, even if the use does not provide a concrete type.
80
+
It is an error to have `Copy` or `Clone` as a bound on a mutable reference, [trait object], or [slice].
81
+
It is an error to have `Sized` as a bound on a trait object or slice.
82
+
83
+
```rust,compile_fail
84
+
struct A<'a, T>
85
+
where
86
+
i32: Default, // Allowed, but not useful
87
+
i32: Iterator, // Error: `i32` is not an iterator
88
+
&'a mut T: Copy, // (at use) Error: the trait bound is not satisfied
89
+
[T]: Sized, // (at use) Error: size cannot be known at compilation
90
+
{
91
+
f: &'a T,
92
+
}
93
+
struct UsesA<'a, T>(A<'a, T>);
94
+
```
95
+
76
96
Trait and lifetime bounds are also used to name [trait objects].
0 commit comments