This can be done by using [`syn::Error::new_spanned`](https://docs.rs/syn/latest/syn/struct.Error.html#method.new_spanned) instead.