compile_warning!
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
Related to https://github.com/rust-lang/rfcs/issues/2902 and https://internals.rust-lang.org/t/pre-rfc-add-compile-warning-macro/9370, I want a compile_warning! macro that is similar to compile_error! except that it is not a hard error.
Here is a motivating use case. Say I have two barely compatible features, I would expect to be able to emit a warning based on my knowledge as a developer and experience with interface symmetry. However, it is not possible to do this:
#[cfg(all(feature = "feature_a", feature = "feature_b"))]
compile_warning!("Using 'feature_a' and 'feature_b' together is not recommended.");
There are many reasons why it may not be possible to have truly mutually exclusive features in Rust. I hit this a lot when trying to divvy up the limited static memory on microcontrollers.
I think the #[allow] and #[deny] points in the threads very relevant. It would be good feedback to someone building the crate to see the warning once, then be able to silence the warning. For example:
In a library crate:
#[cfg(all(feature = "feature_a", feature = "feature_b"))]
compile_warning!(foobar, "Using 'feature_a' and 'feature_b' together is not recommended.");
In the consuming crate:
// We checked we want this ill-advised configuration
#[allow(foobar)]
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading RFC 2902 and the linked pre-RFC discussion, then compare the requested compile_warning! behavior with compile_error!, including the proposed #[allow] and #[deny] handling. Done would require a settled design for warning emission, feature-gated use cases, and suppression in consuming crates; this issue does not name implementation files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100