Open
Description
As part of #67792, #[derive_const]
is the current way to indicate that a derive should be impl const Trait
rather than impl Trait
. However, this only works for built-in macros. It should be possible for end-user proc macros to know if they were invoked with #[derive_const]
, permitting the derive to emit the appropriate code.
In my opinion, this could be an opaque type provided as an additional parameter to the derive implementation. That type would have methods to obtain constness and any other future extension (i.e. effects).
cc @fee1-dead per this Zulip comment.
@rustbot label +A-proc-macros +C-enhancement +F-const-trait-impl +T-libs-api
Metadata
Metadata
Assignees
Labels
Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: Trait systemCategory: An issue proposing an enhancement or a PR with one.`#![feature(const_trait_impl)]`Project group: Const traitsStatus: Blocked on something else such as an RFC or other implementation work.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.Working group: Macros
Activity
impl const Trait for Ty
and[const]
(conditionally const) syntax (const_trait_impl
) #67792#[derive_const]
#118580fmease commentedon Jul 1, 2024
PR #118580 extends support for
#[derive_const]
to user-defined derive proc-macros as outlined in the issue description. However,#[derive_const]
itself is very ad-hoc and non-extensible as petrochenkov criticizes, justifiably so:Originally posted by @petrochenkov in #118580 (comment)
Originally posted by @petrochenkov in #118580 (comment)
Originally posted by @petrochenkov in #118580 (comment)
fmease commentedon Jul 1, 2024
I will therefore close the aforementioned PR and block this issue on further design work to be done by PG-const-traitsProject group: Const traits
and likely also
WG-macros
Working group: Macros
.