Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking Issue: Procedural Macro Diagnostics (RFC 1566) #54140
Comments
SergioBenitez
referenced this issue
Sep 11, 2018
Closed
Tracking issue for RFC 1566: Procedural macros #38356
This comment has been minimized.
This comment has been minimized.
|
I'd argue that support for associating warnings with lints should be a separate RFC, and shouldn't block moving forward with unsilenceable warnings (with the expectation that anything to associate warnings with lints would need to be an additional API) |
This comment has been minimized.
This comment has been minimized.
|
Similarly, I'm not sure we actually need to address multi-span support before this API can be stabilized. The proposed change there involves changing some methods to be generic, which is considered a minor change under RFC #1105. It could also be done by changing |
This comment has been minimized.
This comment has been minimized.
|
@sgrif I suppose the question is: should unsilenceable warnings be allowed at all? I can't think of a reason to remove this control from the end-user. And, if we agree that they shouldn't be allowed, then we should fix the API before stabilizing anything to account for this. I'd really rather not have four warning methods:
Sure, but the change is so minor, so why not do it now? What's more, as much as I want this to stabilize as soon as possible, I don't think enough experience has been had with the current API to merit its stabilization. I think we should implement these two features, announce them broadly so others can play with them, gather feedback, and then stabilize.
Right, that works too. |
This comment has been minimized.
This comment has been minimized.
I think "having a thing we can ship" is a decent reason, but I also think an API that only supports
Because we have a perfectly workable API that's being used in the wild right now that we could focus on stabilizing instead. Typically we always trend towards the more conservative option on this sort of thing, shipping an MVP that's forward compatible with extensions we might want in the future.
So what needs to happen for that? Should we do a public call for testing? Definitely adding more docs is huge. I suppose it'd be good to see what serde looks like using this API as well. |
This comment has been minimized.
This comment has been minimized.
Yeah, that's exactly what I was thinking.
I don't think this is an eccentric proposal in any way. When folks play with this, they should have this feature. In any case, I'll be implementing this soon, unless someone beats me to it, as Rocket needs it. |
This comment has been minimized.
This comment has been minimized.
|
Should we be going through the RFC process for additions to the API here?
(I noticed that `Diagnostic` itself actually never got an RFC)
…On Tue, Sep 11, 2018 at 3:26 PM Sergio Benitez ***@***.***> wrote:
So what needs to happen for that? Should we do a public call for testing?
Definitely adding more docs is huge. I suppose it'd be good to see what
serde looks like using this API as well.
Yeah, that's exactly what I was thinking.
Because we have a perfectly workable API that's being used in the wild
right now that we could focus on stabilizing instead. Typically we always
trend towards the more conservative option on this sort of thing, shipping
an MVP that's forward compatible with extensions we might want in the
future.
I don't think this is an eccentric proposal in any way. When folks play
with this, they should have this feature. In any case, I'll be implementing
this soon, unless someone beats me to it, as Rocket needs it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#54140 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABdWK2Gpoc6vTWz8fKpJmVaGysf9w7-Uks5uaCpsgaJpZM4WkOKO>
.
|
This comment has been minimized.
This comment has been minimized.
|
Maybe it's too late (I'm lacking context here), but is there any hope of unifying proc-macro diagnostics with those emitted by the compiler itself? It seems sad and unmotivated to have two parallel implementations of diagnostics. (Rustc's diagnostics also have a suggestions API (albeit still somewhat in flux) that harbors a lot of promise given the new |
Havvy
added
A-diagnostics
A-macros-1.2
C-tracking-issue
labels
Sep 12, 2018
This comment has been minimized.
This comment has been minimized.
|
@zackmdavis The API being exposed by the diagnostics API in In general, |
alexcrichton
referenced this issue
Sep 12, 2018
Closed
Tracking issue for error messages from proc-macro implementations #50054
This comment has been minimized.
This comment has been minimized.
|
Maud also uses the diagnostic API. It would benefit from both features described in the summary:
|
This comment has been minimized.
This comment has been minimized.
macpp
commented
Sep 21, 2018
|
Is there any way to emit warning for arbitrary file? It could be usefull for macros that read additional data from external files (like derive(Template) in https://github.com/djc/askama ) . If it's not possible, how problematic it is to add to |
alexcrichton
added
B-unstable
T-lang
T-libs
labels
Oct 1, 2018
This comment has been minimized.
This comment has been minimized.
|
Something I find confusing about the current nightly API: does Currently I must use In my opinion:
|
This comment has been minimized.
This comment has been minimized.
|
@dhardy |
This comment has been minimized.
This comment has been minimized.
|
Okay, fair enough; not sure why I some panic messages sometimes and not others.
I guess |
This comment has been minimized.
This comment has been minimized.
|
Personally I'd prefer not exposing a The compiler will not proceed with type checking if your macro emits at least one error, so you can get away with returning nonsense (like |
This comment has been minimized.
This comment has been minimized.
|
@macpp It's not possible today. I agree that something like this should exist, but much thought needs to be given to the API that's exposed. The API you propose, for instance, puts the onus of tracking line and column information on the user, and makes it possible to produce a The API that I've considered is having a mechanism by which a impl TokenStream {
fn from_source_file<P: AsRef<Path>>(path: P) -> Result<TokenStream>;
}This would make it possible to get arbitrary (but "well-formed") spans anywhere in the file. As a bonus, it means you can reuse libraries that work with |
This comment has been minimized.
This comment has been minimized.
macpp
commented
Nov 4, 2018
|
Well, of course if you deal with .rs files, then panic("bad configuration in config.toml file: line X column Y")Unfortunately, i forgot about |
This comment has been minimized.
This comment has been minimized.
|
@macpp No, that would work for almost any kind of text file. A |
This comment has been minimized.
This comment has been minimized.
Arnavion
commented
Nov 4, 2018
And that strings inside single quotes must contain a single codepoint, which eliminates a lot more things (including TOML files) that have arbitrary strings in single quotes. Even the "delimiters must be balanced" requires that the file use the same idea of where a delimiter is and isn't valid. For example the source file must agree that a In short, I don't have a problem with having a |
SergioBenitez commentedSep 11, 2018
•
edited
This is a tracking issue for diagnostics for procedural macros spawned off from #38356.
Overview
Current Status
proc_macro_diagnostics(#44125).syn.Next Steps
Summary
The initial API was implemented in #44125 and is being used by crates like Rocket and Diesel to emit user-friendly diagnostics. Apart from thorough documentation, I see two blockers for stabilization:
Multi-Span Support
At present, it is not possible to create/emit a diagnostic via
proc_macrothat points to more than oneSpan. The internal diagnostics API makes this possible, and we should expose this as well.The changes necessary to support this are fairly minor: a
Diagnosticshould encapsulate aVec<Span>as opposed to aSpan, and thespan_methods should be made generic such that either aSpanor aVec<Span>(ideally also a&[Vec]) can be passed in. This makes it possible for a user to pass in an emptyVec, but this case can be handled as if noSpanwas explicitly set.Lint-Associated Warnings
At present, if a
proc_macroemits a warning, it is unconditional as it is not associated with a lint: the user can never silence the warning. I propose that we require proc-macro authors to associate every warning with a lint-level so that the consumer can turn it off.No API has been formally proposed for this feature. I informally proposed that we allow proc-macros to create lint-levels in an ad-hoc manner; this differs from what happens internally, where all lint-levels have to be known apriori. In code, such an API might look lIke:
The
lint!macro might check for uniqueness and generate a (hidden) structure for internal use. Alternatively, the proc-macro author could simply pass in a string:"unknown_media_type".