Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

Avoid using cfg with destination-crate feature in proc-macro derive#132

Closed
BenWiederhake wants to merge 1 commit intouutils:mainfrom
BenWiederhake:dev-avoid-cfg-in-derive
Closed

Avoid using cfg with destination-crate feature in proc-macro derive#132
BenWiederhake wants to merge 1 commit intouutils:mainfrom
BenWiederhake:dev-avoid-cfg-in-derive

Conversation

@BenWiederhake
Copy link
Copy Markdown
Contributor

Quoting cargo:

using a cfg inside a derive macro will use the cfgs from the
destination crate and not the ones from the defining crate

In these two instances, the cfg was simply used to avoid emitting dead code if the "complete" feature is not desired. By passing the "complete" feature down to the derive crate and evaluating if there, we achieve the same goal, without having to deal with suprisingly-valued and unexpected cfgs downstream.

Discovered while trying to integrate uutils-args into coreutils: https://github.com/uutils/coreutils/actions/runs/14420666926/job/40442804575?pr=7739

This is not my favourite approach.

Alternatively, we could just remove the feature-flag and make it part of the permanent API, as implemented in #131.

Quoting cargo:

    using a cfg inside a derive macro will use the cfgs from the
    destination crate and not the ones from the defining crate

In these two instances, the cfg was simply used to avoid emitting dead
code if the "complete" feature is not desired. By passing the "complete"
feature down to the derive crate and evaluating if there, we achieve the
same goal, without having to deal with suprisingly-valued and unexpected
cfgs downstream.

Alternatively, we could just remove the feature-flag and make it part of
the permanent API.
@tertsdiepraam
Copy link
Copy Markdown
Collaborator

Closed in favor of #131. I agree with your judgment that #131 is the better option. Thanks!

@BenWiederhake BenWiederhake deleted the dev-avoid-cfg-in-derive branch April 15, 2025 13:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants