Alternative syntax suggestion for tilde keyword (~const
): where const
#107003
Labels
F-const_trait_impl
`#![feature(const_trait_impl)]`
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
In #67792 it was suggested to file a new issue regarding any additional discussion, and it looks like the syntax for
~const
is not finalized. In rust-lang/lang-team#162 and #102090, it still looks like~const
is still a placeholder keyword. I'd like to propose another syntax:where const
Like with normal trait bounds, we would add another
where
clause to functions that define when the function isconst
. In the previous example, there is a type bounds onT
that always applies, followed by the declaration thattriple_add
is const if and only if theAdd
implementation isconst
.While this looks a little verbose,
where const
allows for different bounds to permitconst
as well. If there was aConstAdd
trait that was alwaysconst
, we could express the following instead:This gives us flexibility in different how different the
const
bounds are expressed in the future, should we decide to expand or restrict it.A trait could express
const
bounds as well in a similar way:I think this form has a lot of benefits over the existing
~const
:where const
is more familiar than~const
in my opinion:where
adds bounds to the function, so its more intuitive thatwhere const
addsconst
bounds the the function.const
is opt-in, without theconst
keyword in the frontconst
bounds are expressed, in the way that other traits could expressconst
ness, as shown with the previous snippets.async
:where const
clauses to beT: const Trait
whereTrait
is defined in thewhere
bound, and then later opening up to more free bounds.To the best of my ability, I haven't seen any suggestion of this. Please let me know if I've missed anything.
The text was updated successfully, but these errors were encountered: