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
Move text about the timing of checking of bounds on generics
from the "Where clauses" subsection to "Trait and lifetime
bounds", where it makes more sense. Split parts of the example
accordingly. Correct an error about when `Clone`, `Copy`, and
`Sized` trait bounds are checked.
Copy file name to clipboardExpand all lines: src/trait-bounds.md
+25
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
77
+
checked when the item is defined. 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][arrays].
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