@@ -176,6 +176,27 @@ const fn new<T: ?const Trait>(t: T) -> Foo<T> {
176
176
}
177
177
```
178
178
179
+ ## ` const ` default method bodies
180
+
181
+ Trait methods can have default bodies for methods that are used if the method is not mentioned
182
+ in an ` impl ` . This has several uses, most notably
183
+
184
+ * reducing code repetition between impls that are all the same
185
+ * adding new methods is not a breaking change if they also have a default body
186
+
187
+ In order to keep both advantages in the presence of ` impl const ` s, we need a way to declare the
188
+ method default body as being ` const ` . The author of this RFC considers prepending the default body's
189
+ method signature with ` const ` to be the most intuitive syntax.
190
+
191
+ ``` rust
192
+ trait Foo {
193
+ const fn bar () {}
194
+ }
195
+ ```
196
+
197
+ While this conflicts with future work ideas like ` const ` trait methods or ` const trait ` declarations,
198
+ these features are unnecessary for full expressiveness as discussed in their respective sections.
199
+
179
200
# Reference-level explanation
180
201
[ reference-level-explanation ] : #reference-level-explanation
181
202
@@ -469,27 +490,6 @@ fn foo<T: const Bar>() -> i32 {
469
490
Which, once ` const ` items and array lengths inside of functions can make use of the generics of
470
491
the function, would allow the above function to actually exist.
471
492
472
- ## ` const ` default method bodies
473
-
474
- Trait methods can have default bodies for methods that are used if the method is not mentioned
475
- in an ` impl ` . This has several uses, most notably
476
-
477
- * reducing code repetition between impls that are all the same
478
- * adding new methods is not a breaking change if they also have a default body
479
-
480
- In order to keep both advantages in the presence of ` impl const ` s, we need a way to declare the
481
- method default body as being ` const ` . The author of this RFC considers prepending the default body's
482
- method signature with ` const ` to be the most intuitive syntax.
483
-
484
- ``` rust
485
- trait Foo {
486
- const fn bar () {}
487
- }
488
- ```
489
-
490
- While this conflicts with other future work ideas like ` const ` trait methods or ` const trait ` declarations,
491
- these features are unnecessary for full expressiveness as discussed in their respective sections.
492
-
493
493
# Unresolved questions
494
494
[ unresolved-questions ] : #unresolved-questions
495
495
0 commit comments