@@ -131,6 +131,46 @@ It might also be desirable to make the automatic `Fn*` impls on function types a
131
131
This change should probably go in hand with allowing ` const fn ` pointers on const functions
132
132
that support being called (in contrast to regular function pointers).
133
133
134
+ ## Deriving ` const impl ` s
135
+
136
+ ``` rust
137
+ #[derive(Clone )]
138
+ pub struct Foo (Bar );
139
+
140
+ struct Bar ;
141
+
142
+ const impl Clone for Bar {
143
+ fn clone (& self ) -> Self { Bar }
144
+ }
145
+ ```
146
+
147
+ could theoretically have a scheme inferring ` Foo ` 's ` Clone ` impl to be ` const ` . If some time
148
+ later the ` const impl Clone for Bar ` (a private type) is changed to just ` impl ` , ` Foo ` 's ` Clone `
149
+ impl would suddenly stop being ` const ` , without any visible change to the API. This should not
150
+ be allowed for the same reason as why we're not inferring ` const ` on functions: changes to private
151
+ things should not affect the constness of public things, because that is not compatible with semver.
152
+
153
+ ## RPIT (Return position impl trait)
154
+
155
+ ``` rust
156
+ const fn foo () -> impl Bar { /* code here */ }
157
+ ```
158
+
159
+ does not allow us to call any methods on the result of a call to ` foo ` , if we are in a
160
+ const context. It seems like a natural extension to this RFC to allow
161
+
162
+ ``` rust
163
+ const fn foo () -> impl const Bar { /* code here */ }
164
+ ```
165
+
166
+ which requires that the function only returns types with ` const impl Bar ` blocks.
167
+
168
+ ## Specialization
169
+
170
+ Impl specialization is still unstable. There should be a separate RFC for declaring how
171
+ const impl blocks and specialization interact. For now one may not have both ` default `
172
+ and ` const ` modifiers on ` impl ` blocks.
173
+
134
174
# Unresolved questions
135
175
[ unresolved-questions ] : #unresolved-questions
136
176
@@ -148,7 +188,8 @@ const impl<T: Add> Add for Foo<T> {
148
188
```
149
189
150
190
would allow calling ` Foo(String::new()) + Foo(String::new()) ` even though that is (at the time
151
- of writing this RFC) most definitely not const.
191
+ of writing this RFC) most definitely not const, because ` String ` only has an ` impl Add for String `
192
+ and not a ` const impl Add for String ` .
152
193
153
194
This would go in hand with the current scheme for const functions, which may also be called
154
195
at runtime with runtime arguments, but are checked for soundness as if they were called in
@@ -158,3 +199,23 @@ a const context.
158
199
159
200
Should we also allow ` (SomeDropType, 42).1 ` as an expression if ` SomeDropType ` 's ` Drop ` impl
160
201
was declared with ` const impl Drop ` ?
202
+
203
+ ## Require ` const ` bounds on everything inside a ` const impl ` block?
204
+
205
+ Instead of inferring ` const ` ness on all bounds and functions inside a ` const impl ` block,
206
+ we force the user to supply these bounds. This is more consistent with not inferring ` const `
207
+ on ` const ` function argument types and generic bounds. The ` Hash ` example from above would
208
+ then look like
209
+
210
+ ``` rust
211
+ const impl Hash for MyInt {
212
+ const fn hash <H >(
213
+ & self ,
214
+ state : & mut H ,
215
+ )
216
+ where H : const Hasher
217
+ {
218
+ state . write (& [self . 0 as u8 ]);
219
+ }
220
+ }
221
+ ```
0 commit comments