Skip to content

compile_warning!Β #3704

@trueb2

Description

@trueb2

Related to #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)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions