-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Tracking issue for associated_consts feature #29646
Copy link
Copy link
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamfinal-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.Blocker: Approved by a merged RFC and implemented but not stabilized.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamfinal-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The feature is currently quite buggy, but this issue tracks its eventual stabilization.
Blocked onconst_fn.Type params in const expressions (associated-constants can not be used in constant expressions #34344 /cannot use an outer type parameter in this context#39211)T: 'staticforT::CONSTtraitandimpl(rustc_typeck::check::compare_method::compare_const_impl doesn't drain its fullfillment context nor invoke regionck. #41323)Shortcomings of the current implementation
Associated consts in const expressions must be concrete
Associated consts can only be used in const contexts if their input types are fully concrete. That is, this works:
But this does not work:
Associated consts are never object safe
Associated consts make a trait non-object-safe. There is no way to bound the const
where Self: Sized, nor to specify the const when creating the object.Associated consts referencing other associated consts have spurious destructor warnings
This works:
But this does not, because we (unnecessarily) assume the const could be a variant that runs a destructor: