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.
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
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?
Most helpful comment
compile_warning!would be rust-lang/rust#57751 (→ Pre-RFC #9370)