Allow using generic trait methods in `const fn` by jonas-schievink · Pull Reques...
source link: https://github.com/rust-lang/rust/pull/79287
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Conversation
Next step for #67792, this now also allows code like the following:
struct S; impl const PartialEq for S { fn eq(&self, _: &S) -> bool { true } } const fn equals_self<T: PartialEq>(t: &T) -> bool { *t == *t } pub const EQ: bool = equals_self(&S);
This works by threading const-ness of trait predicates through trait selection, in particular through ParamCandidate
, and exposing it in the resulting ImplSource
.
Since this change makes two bounds T: Trait
and T: ?const Trait
that only differ in their const-ness be treated like different bounds, candidate winnowing has been changed to drop the ?const
candidate in favor of the const candidate, to avoid ambiguities when both a const and a non-const bound is present.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK