-
Notifications
You must be signed in to change notification settings - Fork 2
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
Support emitting warning/help/note diagnostics #16
Comments
I see two approaches here:
|
Yeah, this is something I want to reconsider, especially due to this being hopefully stabilized at some point. One thing to consider would be to print the warning to |
#15 would be related for just improving errors using this as well. |
unsure about the api. Something like info!(span, "message")
warn!(span, "message")
not!(span, "message") matching |
I will at some point address this, but if someone wants to tackle this in the meantime, I'm open to suggestions and implementations. |
Something like this maybe? pub trait SpanDiagnostic {
fn warning<T: Into<String>>(self, message: T) -> Diagnostic;
// note, help ...
}
impl SpanDiagnostic for proc_macro2::Span {
#[cfg(feature = "proc_macro_diagnostic")]
fn warning<T: Into<String>>(self, message: T) -> Diagnostic {
self.unwrap().warning(message)
}
#[cfg(not(feature = "proc_macro_diagnostic"))]
fn warning<T: Into<String>>(self, message: T) -> Diagnostic {
// ?
}
} This could easily be dropped later if |
|
I think dtolnay will only add api to The trait can definitely be added, but I think something more capable, e.g., with string formatting should be added as macros on top. |
Sure, something like this could be added on top: Or, alternatively, something more complex (like I linked above or like proc_macro_error). I honestly don't care that much — simply having a facility for emitting warnings is the important part. Eventually all these approaches would probably want to be changed anyway: a proper lint API should have some system for disabling certain lints and possibly also support attaching suggestions for |
This is unfortunately requires an unstable feature: see rust-lang/rust#54140
In other crates:
proc-macro-error
emits such diagnostics onnightly
but silently ignores them onstable
proc-macro2-diagnostics
converts such diagnostics to errors when not onnightly
. (Unfortunately it has a poor design for emitting a non-fatal diagnostic and continuing macro parsing/expansion.)The text was updated successfully, but these errors were encountered: