dtolnay / syn

Parser for Rust source code
Apache License 2.0
2.88k stars 311 forks source link

FieldMutability is missing Parse and ToTokens #1717

Open programmerjake opened 2 months ago

programmerjake commented 2 months ago

I'm trying to write future-proof code that asserts matches!(field.mutability, FieldMutability::None) and reports a nice error if it isn't None:

let Field { mutability, .. } = &mut field;
if !matches!(mutability, FieldMutability::None) {
    errors.push(syn::Error::new_spanned(mutability, "field mutability is not supported"));
    *mutability = FieldMutability::None;
}

but that doesn't work because FieldMutability doesn't implement ToTokens. Please add a ToTokens implementation. Adding a Parse implementation while you're at it would be nice.

Fancyflame commented 2 months ago

Have you considered using Span::call_site() as a temporary substitute, or the span of the whole field?