File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 86
86
/// }
87
87
/// ```
88
88
///
89
+ /// If we `derive`:
90
+ ///
91
+ /// ```
92
+ /// #[derive(Copy, Clone)]
93
+ /// struct Generate<T>(fn() -> T);
94
+ /// ```
95
+ ///
96
+ /// the auto-derived implementations will have unnecessary `T: Copy` and `T: Clone` bounds:
97
+ ///
98
+ /// ```
99
+ /// # struct Generate<T>(fn() -> T);
100
+ ///
101
+ /// // Automatically derived
102
+ /// impl<T: Copy> Copy for Generate<T> { }
103
+ ///
104
+ /// // Automatically derived
105
+ /// impl<T: Clone> Clone for Generate<T> {
106
+ /// fn clone(&self) -> Generate<T> {
107
+ /// Generate(Clone::clone(&self.0))
108
+ /// }
109
+ /// }
110
+ /// ```
111
+ ///
112
+ /// The bounds are unnecessary because clearly the function itself should be
113
+ /// copy- and cloneable even if its return type is not:
114
+ ///
115
+ /// ```compile_fail,E0599
116
+ /// #[derive(Copy, Clone)]
117
+ /// struct Generate<T>(fn() -> T);
118
+ ///
119
+ /// struct NotCloneable;
120
+ ///
121
+ /// fn generate_not_cloneable() -> NotCloneable {
122
+ /// NotCloneable
123
+ /// }
124
+ ///
125
+ /// Generate(generate_not_cloneable).clone(); // error: trait bounds were not satisfied
126
+ /// // Note: With the manual implementations the above line will compile.
127
+ /// ```
128
+ ///
89
129
/// ## Additional implementors
90
130
///
91
131
/// In addition to the [implementors listed below][impls],
You can’t perform that action at this time.
0 commit comments