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
Use attribute syntax instead of magic comments #56
Comments
Yeah, I tried the first route and that basically broke all error messages. I thought of the second strategy but I am not versed in regular macros and it seemed hard. If this works and maintains good error messages I would be happy to switch to it. |
Do you have any details on how it broke error messages, or a script you can share to ensure it retains similar output that I can use to determine whether errors have been broken? |
Right now, code errors in the impl_web block are maintained. So you get line numbers and all that. When I mutated the actual code in the impl_web block all that was lost. |
I don't suppose you have that in the form of a ui test? (e.g. with compiletest-rs) |
Unfortunately not |
I'd love some guidance here, then. I'm still unclear on what exactly broke in your previous attempts, or how I can verify that I haven't caused the same problem |
@sgrif I believe (I could be wrong though) that modifying |
@cramertj I'm familiar with the current state of hygiene and span information. :) The relevant code is coming from pieces of a doc comment though, which should never be appearing in error messages either way. |
@sgrif I think the problem comes from having to strip the attributes away in the final result. Because custom attributes aren't stable, they have to be removed from the generated result, which breaks span information for the rest of the code inside the macro. |
I submitted #59 with a fix that does not disrupt error reporting. impl_web! {
impl JsonResource {
#[get("/")]
fn hello_world(&self) -> Result<serde_json::Value, ()> {
Ok(json!({ "message": "hello world" }))
}
}
} |
You'd asked me to open an issue to discuss strategy, so here we go. There are basically two options. Ultimately the whole thing is getting passed to a derive, so the simplest option is to not have
impl_web!
spit out the tokens its given unmodified, and instead havederive_resource!
spit out its input (with the recognized attributes stripped) in addition to what it spits out today.You mentioned you had a solution which works and messes up error messages, so I'm assuming it's the solution above. The second option would be to run the tokens passed to
impl_web!
through another macro before outputting them. This would be a basicmacro_rules!
macro, which strips out regonized meta items.Both of these options are pretty simple to implement. Diesel does both in multiple places (depending on whether our macro is fundamentally a
macro_rules!
or procedural macro). Would love to hear more about whether this would somehow affect your error messages.The text was updated successfully, but these errors were encountered: