Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: --crate-attr #3791

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

RFC: --crate-attr #3791

wants to merge 1 commit into from

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Mar 17, 2025

# Unresolved questions
[unresolved-questions]: #unresolved-questions

How should this interact with doctests? Does it apply to the crate being tested or to the generated test?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after thinking about this, i think this should always apply to the crate being tested. to apply to the generated test people can use --crate-attr=doc(test(attr(...))) (which is a bit of a mouthful, but, at least it's unambiguous.)

3. Tools that require a specific attribute can pass that attribute automatically.

Each of these corresponds to a different set of stakeholders. The first corresponds to developers writing Rust code. For this group, as the size of their code increases and they split it into multiple crates, it becomes more and more difficult to configure attributes for the whole workspace; they need to be duplicated into the root of each crate. Some attributes that could be useful to configure workspace-wide:
- `no_std`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the potential routes for build-std is that the Cargo.toml has metadata for which std crates are used which means Cargo would need to be able to tell rustc about #[no_std]. Unsure if there would have been another way to do it but this looks like it would allow that!


Additionally, some existing CLI options could have been useful as attributes. This leads to the second group: Maintainers of the Rust language. Often we need to decide between attributes and flags; either we duplicate features between the two (lints, `crate-name`, `crate-type`), or we make it harder to configure the options for stakeholder group 1.

The third group is the authors of external tools. The [original motivation][impl] for this feature was for Crater, which wanted to enable a rustfix feature in *all* crates it built without having to modify the source code. Other motivations include the currently-unstable [`register-tool`], which with this RFC could be an attribute passed by the external tool (or configured in the workspace), and [custom test frameworks].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at custom test frameworks, I'm not quite following how this would be useful.

Note that the current plan for custom test frameworks is very different than #2318, see rust-lang/testing-devex-team#2

@ehuss ehuss added the T-compiler Relevant to the compiler team, which will review and decide on the RFC. label Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-compiler Relevant to the compiler team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants