syn
syn copied to clipboard
Add ability to strip doc / attributes info from the Span
I'm working on and PR for fixing https://github.com/serde-rs/serde/issues/2105 and the related stuff and making compiletests for them. For the piece
#[derive(Serialize)]
#[serde(tag = "type")]
enum Serializable {
/// Error should be reported
Tuple2(u8, u8),
}
the error span would cover several lines:
error: #[serde(tag = "...")] cannot be used with tuple variants
--> tests/ui/enum-representation/internal-tuple-variant.rs:10:5
|
10 | / /// Error should be reported
11 | | Tuple2(u8, u8),
| |__________________^
Because doc comments can be very long, it is impractical to bring them into error messages. I would like to get the following message:
error: #[serde(tag = "...")] cannot be used with tuple variants
--> tests/ui/enum-representation/internal-tuple-variant.rs:10:5
|
10 | /// Error should be reported
11 | Tuple2(u8, u8),
| ^^^^^^^^^^^^^^
That error is generated by the following code in serde (here in action):
// variant.original is a `&syn::Variant`
cx.error_spanned_by(
variant.original,
"#[serde(tag = \"...\")] cannot be used with tuple variants",
);
Is there any way to strip span that related to doc comments (and probably to all other attributes) and keep only code span of syn::Variant
, syn::Field
, etc?