Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug_warn! macro #2902

Open
deeprobin opened this issue Apr 7, 2020 · 6 comments
Open

debug_warn! macro #2902

deeprobin opened this issue Apr 7, 2020 · 6 comments

Comments

@deeprobin
Copy link

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.

@kennytm
Copy link
Member

kennytm commented Apr 7, 2020

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

@deeprobin
Copy link
Author

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.
pub fn new<T: AsRef<str>>(s: T) -> MyStruct {
    if s.contains_duplicates() { // yes that fn does not exist but you'll understand
        debug_warn!("String contains duplicate characters.");
    }
}

@shepmaster
Copy link
Member

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.

@RustyYato
Copy link

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

@kennytm
Copy link
Member

kennytm commented Apr 7, 2020

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

@matthew-mcallister
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants