File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -81,14 +81,24 @@ for it.
81
81
These rules for associated types exist to make this RFC forward compatible with adding const default bodies
82
82
for trait methods. These are further discussed in the "future work" section.
83
83
84
- ## Generic ` impl ` blocks
84
+ ## Generic bounds
85
85
86
- Similar to generic parameters on ` const ` functions, one can have generic parameters on ` impl ` blocks.
87
- These follow the same rules as bounds on ` const ` functions:
86
+ The above section skimmed over a few topics for brevity. First of all, ` impl const ` items can also
87
+ have generic parameters and thus bounds on these parameters, and these bounds follow the same rules
88
+ as bounds on generic parameters on ` const ` functions: all bounds can only be substituted with types
89
+ that have ` impl const ` items for all the bounds. Thus the ` T ` in the following ` impl ` requires that
90
+ when ` MyType<T> ` is used in a const context, ` T ` needs to have an ` impl const Add for Foo ` .
88
91
89
- * all bounds are required to have ` impl const ` for substituted types if the impl is used in a const context
90
- * except in the presence of ` ?const ` (see below)
91
- * if the impl is used at runtime, there are no restrictions what kind of bounds are required
92
+ ``` rust
93
+ impl <T : Add > const Add for MyType <T > {
94
+ /* some code here */
95
+ }
96
+ const FOO : MyType <u32 > = ... ;
97
+ const BAR : MyType <u32 > = FOO + FOO ; // only legal because `u32: const Add`
98
+ ```
99
+
100
+ Furthermore, if ` MyType ` is used outside a const context, there are no constness requirements on the
101
+ bounds for types substituted for ` T ` .
92
102
93
103
## Drop
94
104
You can’t perform that action at this time.
0 commit comments