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
Copy file name to clipboardExpand all lines: text/0000-const-trait-impls.md
+18-2Lines changed: 18 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -155,7 +155,7 @@ Examples:
155
155
*`dyn const Trait`, requiring any type that is unsized to this dyn trait to have a const trait impl for `Trait`.
156
156
* These are not part of this RFC because they require `const` function pointers. See [the Future Possibilities section](#future-possibilities).
157
157
*`impl const Trait` (in all positions).
158
-
* These are not part of this RFC because they require `const` function pointers. See [the Future Possibilities section](#future-possibilities).
158
+
* These are not part of this RFC.
159
159
*`trait Foo: const Bar {}`, requiring every type that has an impl for `Foo` (even a non-const one), to also have a const trait impl for `Bar`.
160
160
*`trait Foo { type Bar: const Trait; }`, requiring all the impls to provide a type for `Bar` that has a const trait impl for `Trait`
161
161
@@ -394,6 +394,17 @@ While this could be modelled with generic parameters in the type system, that:
394
394
395
395
Thus that approach was abandoned after proponents and opponents cooperated in trying to make the generic parameter approach work, resulting in all proponents becoming opponents, too.
396
396
397
+
### Sites where `const Trait` bounds can be used
398
+
399
+
Everywhere where non-const trait bounds can be written, but only for traits that are declared `const Trait`.
400
+
401
+
### Sites where `~const Trait` bounds can be used
402
+
403
+
*`const fn`
404
+
*`impl const Trait for Type`
405
+
* NOT in inherent impls, the individual `const fn` need to be annotated instead
406
+
* associated types bounds of `const trait Trait` declarations
We could default to making all `T: Trait` bounds be const if the function is called from a const context, and require a `T: ?const Trait` opt out
730
741
for when a trait bound is only used for its associated types and consts.
731
742
732
-
This requires a new `~const fn`syntax (sigils or syntax bikesheddable), as the existing `const fn` already has trait bounds that
743
+
This requires new syntax (demonstrated here with `#[next_const_fn]`), as the existing `const fn` already has trait bounds that
733
744
do not require const trait impls even if used in const contexts.
734
745
735
746
An example from libstd today is [the impl block of Vec::new](https://github.com/rust-lang/rust/blob/1ab85fbd7474e8ce84d5283548f21472860de3e2/library/alloc/src/vec/mod.rs#L406) which has an implicit `A: Allocator` bound from [the type definition](https://github.com/rust-lang/rust/blob/1ab85fbd7474e8ce84d5283548f21472860de3e2/library/alloc/src/vec/mod.rs#L397).
0 commit comments