improve error reporting if outer delimiters are available#194
Conversation
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
ahl
left a comment
There was a problem hiding this comment.
- Nice find!
- Do we want to update the main lib.rs info and/or README? In particular to guide users who may encounter a similar situation as you did.
- This may be somewhere in the dumb-to-optimistic range, but given the input
TokenStreamcould we construct aSpanthat encompasses its entirety and use that by default? - ... Or was this just the wrong interface and we should have had users pass in the outer, braced tokenstream??
There was a problem hiding this comment.
let's delete this file? I probably shouldn't have added it in the first place. I bet we no longer need the nightly rustfmt?
| /// This is useful with nested attributes inside annotations, where | ||
| /// `serde_tokenstream` is used to parse an attribute inside a top-level macro. |
There was a problem hiding this comment.
| /// This is useful with nested attributes inside annotations, where | |
| /// `serde_tokenstream` is used to parse an attribute inside a top-level macro. | |
| /// This is useful with nested attributes inside annotations, when | |
| /// parsing an attribute nested inside an outer macro. |
maybe?
| /// | ||
| /// ```rust,ignore | ||
| /// #[derive(Record)] | ||
| /// #[record { worker = "Homer J. Simpson", floor = 7, region = "G" }] |
There was a problem hiding this comment.
Created using spr 1.3.6-beta.1
Done.
We could, but that would cause an inconsistency where only the part inside the braces would be included, not the braces themselves. I think the current approach is probably fine -- it complains about the whole macro.
Ah sadly the outer TokenStream isn't available with top-level attributes. |
Created using spr 1.3.6-beta.1
|
In v0.2.1 now on crates.io |
This is a bit of a basic/elementary test but I realized we didn't have coverage for it. (And it's actually important for server traits -- specifically, without oxidecomputer/serde_tokenstream#194, incorrect span information is produced.)
Currently, if there's a top-level error in the macro (e.g. a top-level missing
field), then we always get a call_site error. That is because we don't have the
span information corresponding to the outer braces.
This isn't a huge problem if serde_tokenstream is used for the top-level
attribute, but does become one for nested attributes. Trait-based Dropshot
servers are one such case --
endpointannotations are nested under thetop-level and can be pretty far from the call site.
Address this by providing an alternative API that also accepts delimiter spans.
Also remove the
.vscode/settings.jsonthat's no longer required,and allow the
targetgitignore rule to match a symlink (all my targetdirectories are symlinks to a non-btrfs-snapshotted store).