Is their a way to print custom warnings to the compiler?

What I want is to be able to print a custom warning to the terminal whenever the project is built, something like compile_error!() but instead of stopping the compiling just print a warning like the built-in warnings. Something like what I would imagine compile_warn!() would do if it existed.

Not currently on stable. The biggest open question is how custom lints should interact with lint levels, how they should be named, etc.

On nightly, proc macros have access to the Diagnostic type, which allows emitting warnings.


You can print warnings as part of a build script. This might be acceptable depending on your use case.

What happens if a proc macro just print!()s? (Or eprintln!()s, more likely)

Proc macro's stdout and stderr are piped to a file in the build directory by default, and not shown to the user.

Output may be shown at -vv, though I'm unsure and didn't check.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.