Rfcs: debug_warn! macro

Created on 7 Apr 2020  ·  6Comments  ·  Source: rust-lang/rfcs

I had the idea of including a macro that issues compiler warnings to make it easier for library developers to tell the user what, for example, is not recommended.
assert! is more likely to issue errors, but adding such a warning might be useful.

Most helpful comment

compile_warning! would be rust-lang/rust#57751 (→ Pre-RFC #9370)

All 6 comments

can you show a code example how debug_warn! would be used?

let my_struct = MyStruct::new("ABCDEFGHIJJKLMN");
// so e.g. the person, that the struct wrote thinks, that e.g. double characters in the String are not necessary but it would not be an error.

```rust
pub fn new>(s: T) -> MyStruct {
if s.contains_duplicates() { // yes that fn does not exist but you'll understand
debug_warn!("String contains duplicate characters.");
}
}

issues compiler warnings

if s.contains_duplicates()

This is decided at run time; far after the compiler is involved. There may not even be a Rust compiler installed on the machine when the program is run.

I could see this being useful for macros, similar to compile_error

compile_warning! would be rust-lang/rust#57751 (→ Pre-RFC #9370)

Wouldn't this be better solved by a custom lint rule?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steveklabnik picture steveklabnik  ·  4Comments

3442853561 picture 3442853561  ·  3Comments

3442853561 picture 3442853561  ·  3Comments

3442853561 picture 3442853561  ·  4Comments

Diggsey picture Diggsey  ·  3Comments