diff options
author | Brian Olsen <brian@maven-group.org> | 2024-11-03T19·37+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-11-04T15·33+0000 |
commit | 6582fa69f15c8337cb3a16e74062037a7278020f (patch) | |
tree | 716173befab4f707a129d5d22a582c415af3471c /tvix/nix-compat-derive/src/de.rs | |
parent | cae3afc758eb7c4a24a77e03aae924c210ab7ffe (diff) |
fix(tvix/nix-compat-derive): Better errors for default r/8892
This adds a span to default handling so that any error message gives a more precise location as a hint for why the error occurred instead of just pointing to the type. Change-Id: I7bf6cf38e0284f9726d670ea50a94a6b1edd8a94 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12728 Reviewed-by: Vladimir Kryachko <v.kryachko@gmail.com> Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Autosubmit: Brian Olsen <me@griff.name>
Diffstat (limited to 'tvix/nix-compat-derive/src/de.rs')
-rw-r--r-- | tvix/nix-compat-derive/src/de.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tvix/nix-compat-derive/src/de.rs b/tvix/nix-compat-derive/src/de.rs index 8dac6964f612..2214254e2b32 100644 --- a/tvix/nix-compat-derive/src/de.rs +++ b/tvix/nix-compat-derive/src/de.rs @@ -111,7 +111,9 @@ fn nix_deserialize_struct(style: Style, fields: &[Field<'_>]) -> TokenStream { }; if let Some(version) = f.attrs.version.as_ref() { let default = match &f.attrs.default { - Default::Default => quote_spanned!(ty.span()=>::std::default::Default::default), + Default::Default(span) => { + quote_spanned!(span.span()=>::std::default::Default::default) + } Default::Path(path) => path.to_token_stream(), _ => panic!("No default for versioned field"), }; @@ -172,7 +174,9 @@ fn nix_deserialize_variant(variant: &Variant<'_>) -> TokenStream { }; if let Some(version) = f.attrs.version.as_ref() { let default = match &f.attrs.default { - Default::Default => quote_spanned!(ty.span()=>::std::default::Default::default), + Default::Default(span) => { + quote_spanned!(span.span()=>::std::default::Default::default) + } Default::Path(path) => path.to_token_stream(), _ => panic!("No default for versioned field"), }; |