The topic suggests
const(pure) fn foo() {...}
impl const(pure) Trait ...
similar to but more permissive than vanilla const
:
- can only call
fn
-s that areconst(pure)
themselves - no access to static variables
- no assignments through references
- no
asm
- ...
- can dereference pointers and use heap
Hopefully implementation can follow in footsteps of const
fn
-s and traits.
Motivation
- make Somewhat Random Idea: Deref patterns design simpler
- other cases when caller wants to be sure to get identical results while passing in identical args
Future Possibilities
As written const(pure) fn
-s have same limitation as const fn
-s:
- can modify
mut
local bindings - cannot modify through
&mut
references at all - so, no iterators, sorry
To solve this would require coloring all &mut
references throughout the type system in two colors - unique immutable and unique mutable. One idea here is to mark lifetimes as const
..
Because of the size of the change it's left out as a future possibility. Initially const(pure) fn
-s would treat all &mut
references as immutable.
Note
It is hoped present-day It simplifies things to say that vanilla const
fn
-s/traits will be a subset of const(pure)
fn
-s and traits. However to leave more future possibilities open initially const(pure)
and const
can be marked separately:const fn
will always be a stronger requirement than const(pure) fn
.
Objections
It is interesting why pure
was dropped but the suggestion just keeps coming back..