Merge pull request #2558 from Mingun/correct-span
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Improve error reporting about mismatched signature in `with` and `default` attributes
authored by Oli Scherer · committed by GitHub · parents 8b0f482, 74b538b · Browse files · 27 files·+628 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
27 files+628 added−13 removed
- tests:+569 added−0 removed
- other:+59 added−13 removed
Provenance
- Commit
04bb76b- Tree
51cfe1d- Author
Oli Scherer <github35764891676564198441@oli-obk.de>- Committer
GitHub <noreply@github.com>- Parent 1
8b0f482- Parent 2
74b538b
27 files changed+628 added−13 removed
modified:serde_derive/src/internals/attr.rs+5 added-4 removed
6 unmodified lines7 use std::iter::FromIterator;8 use syn::meta::ParseNestedMeta;9 use syn::parse::ParseStream;10 use syn::punctuated::Punctuated;11+use syn::spanned::Spanned;12 use syn::{parse_quote, token, Ident, Lifetime, Token};13 14 // This module handles parsing of `#[serde(...)]` attributes. The entrypoints15 // are `attr::Container::from_ast`, `attr::Variant::from_ast`, and872 unmodified lines888 let mut ser_path = path.clone();889 ser_path890 .path891 .segments891- .push(Ident::new("serialize", Span::call_site()).into());892+ .push(Ident::new("serialize", ser_path.span()).into());893 serialize_with.set(&meta.path, ser_path);894 let mut de_path = path;895 de_path896 .path897 .segments897- .push(Ident::new("deserialize", Span::call_site()).into());898+ .push(Ident::new("deserialize", de_path.span()).into());899 deserialize_with.set(&meta.path, de_path);900 }901 } else if meta.path == SERIALIZE_WITH {902 // #[serde(serialize_with = "...")]267 unmodified lines1170 let mut ser_path = path.clone();1171 ser_path1172 .path1173 .segments1173- .push(Ident::new("serialize", Span::call_site()).into());1174+ .push(Ident::new("serialize", ser_path.span()).into());1175 serialize_with.set(&meta.path, ser_path);1176 let mut de_path = path;1177 de_path1178 .path1179 .segments1179- .push(Ident::new("deserialize", Span::call_site()).into());1180+ .push(Ident::new("deserialize", de_path.span()).into());1181 deserialize_with.set(&meta.path, de_path);1182 }1183 } else if meta.path == BOUND {1184 // #[serde(bound = "T: SomeBound")]688 unmodified linesmodified:serde_derive/src/de.rs+47 added-8 removed
369 unmodified lines370 quote!(#member: __transparent)371 } else {372 let value = match field.attrs.default() {373 attr::Default::Default => quote!(_serde::__private::Default::default()),374+ // If #path returns wrong type, error will be reported here (^^^^^).375+ // We attach span of the path to the function so it will be reported376+ // on the #[serde(default = "...")]377+ // ^^^^^374- attr::Default::Path(path) => quote!(#path()),378+ attr::Default::Path(path) => quote_spanned!(path.span()=> #path()),379 attr::Default::None => quote!(_serde::__private::PhantomData),380 };381 quote!(#member: #value)382 }377 unmodified lines760 let let_default = match cattrs.default() {761 attr::Default::Default => Some(quote!(762 let __default: Self::Value = _serde::__private::Default::default();763 )),764+ // If #path returns wrong type, error will be reported here (^^^^^).765+ // We attach span of the path to the function so it will be reported766+ // on the #[serde(default = "...")]767+ // ^^^^^760- attr::Default::Path(path) => Some(quote!(768+ attr::Default::Path(path) => Some(quote_spanned!(path.span()=>769 let __default: Self::Value = #path();770 )),771 attr::Default::None => {772 // We don't need the default value, to prevent an unused variable warning73 unmodified lines846 let let_default = match cattrs.default() {847 attr::Default::Default => Some(quote!(848 let __default: #this_type #ty_generics = _serde::__private::Default::default();849 )),850+ // If #path returns wrong type, error will be reported here (^^^^^).851+ // We attach span of the path to the function so it will be reported852+ // on the #[serde(default = "...")]853+ // ^^^^^842- attr::Default::Path(path) => Some(quote!(854+ attr::Default::Path(path) => Some(quote_spanned!(path.span()=>855 let __default: #this_type #ty_generics = #path();856 )),857 attr::Default::None => {858 // We don't need the default value, to prevent an unused variable warning25 unmodified lines884 #func(__e)?885 }886 }887 Some(path) => {876- quote! {888+ // If #path returns wrong type, error will be reported here (^^^^^).889+ // We attach span of the path to the function so it will be reported890+ // on the #[serde(with = "...")]891+ // ^^^^^892+ quote_spanned! {path.span()=>893 #path(__e)?894 }895 }896 };1765 unmodified lines2662 let let_default = match cattrs.default() {2663 attr::Default::Default => Some(quote!(2664 let __default: Self::Value = _serde::__private::Default::default();2665 )),2666+ // If #path returns wrong type, error will be reported here (^^^^^).2667+ // We attach span of the path to the function so it will be reported2668+ // on the #[serde(default = "...")]2669+ // ^^^^^2650- attr::Default::Path(path) => Some(quote!(2670+ attr::Default::Path(path) => Some(quote_spanned!(path.span()=>2671 let __default: Self::Value = #path();2672 )),2673 attr::Default::None => {2674 // We don't need the default value, to prevent an unused variable warning161 unmodified lines2836 let let_default = match cattrs.default() {2837 attr::Default::Default => Some(quote!(2838 let __default: #this_type #ty_generics = _serde::__private::Default::default();2839 )),2840+ // If #path returns wrong type, error will be reported here (^^^^^).2841+ // We attach span of the path to the function so it will be reported2842+ // on the #[serde(default = "...")]2843+ // ^^^^^2820- attr::Default::Path(path) => Some(quote!(2844+ attr::Default::Path(path) => Some(quote_spanned!(path.span()=>2845 let __default: #this_type #ty_generics = #path();2846 )),2847 attr::Default::None => {2848 // We don't need the default value, to prevent an unused variable warning30 unmodified lines2879 let (de_impl_generics, de_ty_generics, ty_generics, where_clause) =2880 split_with_de_lifetime(params);2881 let delife = params.borrowed.de_lifetime();2882 2883+ // If #deserialize_with returns wrong type, error will be reported here (^^^^^).2884+ // We attach span of the path to the function so it will be reported2885+ // on the #[serde(with = "...")]2886+ // ^^^^^2887+ let value = quote_spanned! {deserialize_with.span()=>2888+ #deserialize_with(__deserializer)?2889+ };2890 let wrapper = quote! {2891 #[doc(hidden)]2892 struct __DeserializeWith #de_impl_generics #where_clause {2893 value: #value_ty,6 unmodified lines2900 where2901 __D: _serde::Deserializer<#delife>,2902 {2903 _serde::__private::Ok(__DeserializeWith {2873- value: #deserialize_with(__deserializer)?,2904+ value: #value,2905 phantom: _serde::__private::PhantomData,2906 lifetime: _serde::__private::PhantomData,2907 })2908 }82 unmodified lines2991 let func = quote_spanned!(span=> _serde::__private::Default::default);2992 return quote_expr!(#func());2993 }2994 attr::Default::Path(path) => {2964- return quote_expr!(#path());2995+ // If #path returns wrong type, error will be reported here (^^^^^).2996+ // We attach span of the path to the function so it will be reported2997+ // on the #[serde(default = "...")]2998+ // ^^^^^2999+ return Fragment::Expr(quote_spanned!(path.span()=> #path()));3000 }3001 attr::Default::None => { /* below */ }3002 }3003 34 unmodified lines3038 let span = field.original.span();3039 return quote_spanned!(span=> #assign_to _serde::__private::Default::default());3040 }3041 attr::Default::Path(path) => {3042+ // If #path returns wrong type, error will be reported here (^^^^^).3043+ // We attach span of the path to the function so it will be reported3044+ // on the #[serde(default = "...")]3045+ // ^^^^^3046 return quote_spanned!(path.span()=> #assign_to #path());3047 }3048 attr::Default::None => { /* below */ }3049 }162 unmodified linesmodified:serde_derive/src/ser.rs+7 added-1 removed
1218 unmodified lines1219 span: Span::call_site(),1220 })1221 });1222 1223- quote!({1223+ // If #serialize_with returns wrong type, error will be reported on here.1224+ // We attach span of the path to this piece so error will be reported1225+ // on the #[serde(with = "...")]1226+ // ^^^^^1227+ quote_spanned!(serialize_with.span()=> {1228 #[doc(hidden)]1229 struct __SerializeWith #wrapper_impl_generics #where_clause {1230+ // If #field_tys is empty, `values` does not used1231+ #[allow(dead_code)]1232 values: (#(&'__a #field_tys, )*),1233 phantom: _serde::__private::PhantomData<#this_type #ty_generics>,1234 }1235 121 unmodified linesadded:test_suite/tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs+22 added
1+//! Ensures that error message points to the path in attribute2+use serde_derive::Deserialize;3+4+#[derive(Deserialize)]5+#[serde(tag = "tag", content = "content")]6+enum Enum {7+ // Newtype variants does not use the provided path, so it is forbidden here8+ // Newtype(#[serde(default = "main")] u8),9+ Tuple(10+ u8,11+ #[serde(default = "main")] i8,12+ ),13+ Struct {14+ #[serde(default = "main")]15+ f1: u8,16+ f2: u8,17+ #[serde(default = "main")]18+ f3: i8,19+ },20+}21+22+fn main() {}added:test_suite/tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.stderr+35 added
1+error[E0308]: `match` arms have incompatible types2+ --> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:11:273+ |4+4 | #[derive(Deserialize)]5+ | -----------6+ | |7+ | this is found to be of type `i8`8+ | `match` arms have incompatible types9+...10+11 | #[serde(default = "main")] i8,11+ | ^^^^^^ expected `i8`, found `()`12+13+error[E0308]: `match` arms have incompatible types14+ --> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:14:2715+ |16+4 | #[derive(Deserialize)]17+ | -----------18+ | |19+ | this is found to be of type `u8`20+ | `match` arms have incompatible types21+...22+14 | #[serde(default = "main")]23+ | ^^^^^^ expected `u8`, found `()`24+25+error[E0308]: `match` arms have incompatible types26+ --> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:17:2727+ |28+4 | #[derive(Deserialize)]29+ | -----------30+ | |31+ | this is found to be of type `i8`32+ | `match` arms have incompatible types33+...34+17 | #[serde(default = "main")]35+ | ^^^^^^ expected `i8`, found `()`added:test_suite/tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs+21 added
1+//! Ensures that error message points to the path in attribute2+use serde_derive::Deserialize;3+4+#[derive(Deserialize)]5+enum Enum {6+ // Newtype variants does not use the provided path, so it is forbidden here7+ // Newtype(#[serde(default = "main")] u8),8+ Tuple(9+ u8,10+ #[serde(default = "main")] i8,11+ ),12+ Struct {13+ #[serde(default = "main")]14+ f1: u8,15+ f2: u8,16+ #[serde(default = "main")]17+ f3: i8,18+ },19+}20+21+fn main() {}added:test_suite/tests/ui/default-attribute/incorrect_type_enum_externally_tagged.stderr+35 added
1+error[E0308]: `match` arms have incompatible types2+ --> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:10:273+ |4+4 | #[derive(Deserialize)]5+ | -----------6+ | |7+ | this is found to be of type `i8`8+ | `match` arms have incompatible types9+...10+10 | #[serde(default = "main")] i8,11+ | ^^^^^^ expected `i8`, found `()`12+13+error[E0308]: `match` arms have incompatible types14+ --> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:13:2715+ |16+4 | #[derive(Deserialize)]17+ | -----------18+ | |19+ | this is found to be of type `u8`20+ | `match` arms have incompatible types21+...22+13 | #[serde(default = "main")]23+ | ^^^^^^ expected `u8`, found `()`24+25+error[E0308]: `match` arms have incompatible types26+ --> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:16:2727+ |28+4 | #[derive(Deserialize)]29+ | -----------30+ | |31+ | this is found to be of type `i8`32+ | `match` arms have incompatible types33+...34+16 | #[serde(default = "main")]35+ | ^^^^^^ expected `i8`, found `()`added:test_suite/tests/ui/default-attribute/incorrect_type_enum_internally_tagged.rs+19 added
1+//! Ensures that error message points to the path in attribute2+use serde_derive::Deserialize;3+4+#[derive(Deserialize)]5+#[serde(tag = "tag")]6+enum Enum {7+ // Newtype variants does not use the provided path, so it is forbidden here8+ // Newtype(#[serde(default = "main")] u8),9+ // Tuple variants does not supported in internally tagged enums10+ Struct {11+ #[serde(default = "main")]12+ f1: u8,13+ f2: u8,14+ #[serde(default = "main")]15+ f3: i8,16+ },17+}18+19+fn main() {}added:test_suite/tests/ui/default-attribute/incorrect_type_enum_internally_tagged.stderr+23 added
1+error[E0308]: `match` arms have incompatible types2+ --> tests/ui/default-attribute/incorrect_type_enum_internally_tagged.rs:11:273+ |4+4 | #[derive(Deserialize)]5+ | -----------6+ | |7+ | this is found to be of type `u8`8+ | `match` arms have incompatible types9+...10+11 | #[serde(default = "main")]11+ | ^^^^^^ expected `u8`, found `()`12+13+error[E0308]: `match` arms have incompatible types14+ --> tests/ui/default-attribute/incorrect_type_enum_internally_tagged.rs:14:2715+ |16+4 | #[derive(Deserialize)]17+ | -----------18+ | |19+ | this is found to be of type `i8`20+ | `match` arms have incompatible types21+...22+14 | #[serde(default = "main")]23+ | ^^^^^^ expected `i8`, found `()`added:test_suite/tests/ui/default-attribute/incorrect_type_enum_untagged.rs+22 added
1+//! Ensures that error message points to the path in attribute2+use serde_derive::Deserialize;3+4+#[derive(Deserialize)]5+#[serde(untagged)]6+enum Enum {7+ // Newtype variants does not use the provided path, so it is forbidden here8+ // Newtype(#[serde(default = "main")] u8),9+ Tuple(10+ u8,11+ #[serde(default = "main")] i8,12+ ),13+ Struct {14+ #[serde(default = "main")]15+ f1: u8,16+ f2: u8,17+ #[serde(default = "main")]18+ f3: i8,19+ },20+}21+22+fn main() {}added:test_suite/tests/ui/default-attribute/incorrect_type_enum_untagged.stderr+35 added
1+error[E0308]: `match` arms have incompatible types2+ --> tests/ui/default-attribute/incorrect_type_enum_untagged.rs:11:273+ |4+4 | #[derive(Deserialize)]5+ | -----------6+ | |7+ | this is found to be of type `i8`8+ | `match` arms have incompatible types9+...10+11 | #[serde(default = "main")] i8,11+ | ^^^^^^ expected `i8`, found `()`12+13+error[E0308]: `match` arms have incompatible types14+ --> tests/ui/default-attribute/incorrect_type_enum_untagged.rs:14:2715+ |16+4 | #[derive(Deserialize)]17+ | -----------18+ | |19+ | this is found to be of type `u8`20+ | `match` arms have incompatible types21+...22+14 | #[serde(default = "main")]23+ | ^^^^^^ expected `u8`, found `()`24+25+error[E0308]: `match` arms have incompatible types26+ --> tests/ui/default-attribute/incorrect_type_enum_untagged.rs:17:2727+ |28+4 | #[derive(Deserialize)]29+ | -----------30+ | |31+ | this is found to be of type `i8`32+ | `match` arms have incompatible types33+...34+17 | #[serde(default = "main")]35+ | ^^^^^^ expected `i8`, found `()`added:test_suite/tests/ui/default-attribute/incorrect_type_newtype.rs+8 added
1+//! Ensures that error message points to the path in attribute2+use serde_derive::Deserialize;3+4+#[derive(Deserialize)]5+#[serde(default = "main")]6+struct Newtype(#[serde(default = "main")] u8);7+8+fn main() {}added:test_suite/tests/ui/default-attribute/incorrect_type_newtype.stderr+37 added
1+error[E0308]: mismatched types2+ --> tests/ui/default-attribute/incorrect_type_newtype.rs:5:193+ |4+5 | #[serde(default = "main")]5+ | ^^^^^^6+ | |7+ | expected `Newtype`, found `()`8+ | expected due to this9+10+error[E0308]: `match` arms have incompatible types11+ --> tests/ui/default-attribute/incorrect_type_newtype.rs:6:3412+ |13+4 | #[derive(Deserialize)]14+ | -----------15+ | |16+ | this is found to be of type `u8`17+ | `match` arms have incompatible types18+5 | #[serde(default = "main")]19+6 | struct Newtype(#[serde(default = "main")] u8);20+ | ^^^^^^ expected `u8`, found `()`21+22+error[E0308]: mismatched types23+ --> tests/ui/default-attribute/incorrect_type_newtype.rs:5:1924+ |25+5 | #[serde(default = "main")]26+ | ^^^^^^ expected `Newtype`, found `()`27+6 | struct Newtype(#[serde(default = "main")] u8);28+ | ------- expected due to this29+30+error[E0308]: mismatched types31+ --> tests/ui/default-attribute/incorrect_type_newtype.rs:6:3432+ |33+4 | #[derive(Deserialize)]34+ | ----------- expected due to the type of this binding35+5 | #[serde(default = "main")]36+6 | struct Newtype(#[serde(default = "main")] u8);37+ | ^^^^^^ expected `u8`, found `()`added:test_suite/tests/ui/default-attribute/incorrect_type_struct.rs+14 added
1+//! Ensures that error message points to the path in attribute2+use serde_derive::Deserialize;3+4+#[derive(Deserialize)]5+#[serde(default = "main")]6+struct Struct {7+ #[serde(default = "main")]8+ f1: u8,9+ f2: u8,10+ #[serde(default = "main")]11+ f3: i8,12+}13+14+fn main() {}added:test_suite/tests/ui/default-attribute/incorrect_type_struct.stderr+58 added
1+error[E0308]: mismatched types2+ --> tests/ui/default-attribute/incorrect_type_struct.rs:5:193+ |4+5 | #[serde(default = "main")]5+ | ^^^^^^6+ | |7+ | expected `Struct`, found `()`8+ | expected due to this9+10+error[E0308]: `match` arms have incompatible types11+ --> tests/ui/default-attribute/incorrect_type_struct.rs:7:2312+ |13+4 | #[derive(Deserialize)]14+ | -----------15+ | |16+ | this is found to be of type `u8`17+ | `match` arms have incompatible types18+...19+7 | #[serde(default = "main")]20+ | ^^^^^^ expected `u8`, found `()`21+22+error[E0308]: `match` arms have incompatible types23+ --> tests/ui/default-attribute/incorrect_type_struct.rs:10:2324+ |25+4 | #[derive(Deserialize)]26+ | -----------27+ | |28+ | this is found to be of type `i8`29+ | `match` arms have incompatible types30+...31+10 | #[serde(default = "main")]32+ | ^^^^^^ expected `i8`, found `()`33+34+error[E0308]: mismatched types35+ --> tests/ui/default-attribute/incorrect_type_struct.rs:5:1936+ |37+5 | #[serde(default = "main")]38+ | ^^^^^^ expected `Struct`, found `()`39+6 | struct Struct {40+ | ------ expected due to this41+42+error[E0308]: mismatched types43+ --> tests/ui/default-attribute/incorrect_type_struct.rs:7:2344+ |45+4 | #[derive(Deserialize)]46+ | ----------- expected due to the type of this binding47+...48+7 | #[serde(default = "main")]49+ | ^^^^^^ expected `u8`, found `()`50+51+error[E0308]: mismatched types52+ --> tests/ui/default-attribute/incorrect_type_struct.rs:10:2353+ |54+4 | #[derive(Deserialize)]55+ | ----------- expected due to the type of this binding56+...57+10 | #[serde(default = "main")]58+ | ^^^^^^ expected `i8`, found `()`added:test_suite/tests/ui/default-attribute/incorrect_type_tuple.rs+11 added
1+//! Ensures that error message points to the path in attribute2+use serde_derive::Deserialize;3+4+#[derive(Deserialize)]5+#[serde(default = "main")]6+struct Tuple(7+ u8,8+ #[serde(default = "main")] i8,9+);10+11+fn main() {}added:test_suite/tests/ui/default-attribute/incorrect_type_tuple.stderr+37 added
1+error[E0308]: mismatched types2+ --> tests/ui/default-attribute/incorrect_type_tuple.rs:5:193+ |4+5 | #[serde(default = "main")]5+ | ^^^^^^6+ | |7+ | expected `Tuple`, found `()`8+ | expected due to this9+10+error[E0308]: `match` arms have incompatible types11+ --> tests/ui/default-attribute/incorrect_type_tuple.rs:8:2312+ |13+4 | #[derive(Deserialize)]14+ | -----------15+ | |16+ | this is found to be of type `i8`17+ | `match` arms have incompatible types18+...19+8 | #[serde(default = "main")] i8,20+ | ^^^^^^ expected `i8`, found `()`21+22+error[E0308]: mismatched types23+ --> tests/ui/default-attribute/incorrect_type_tuple.rs:5:1924+ |25+5 | #[serde(default = "main")]26+ | ^^^^^^ expected `Tuple`, found `()`27+6 | struct Tuple(28+ | ----- expected due to this29+30+error[E0308]: mismatched types31+ --> tests/ui/default-attribute/incorrect_type_tuple.rs:8:2332+ |33+4 | #[derive(Deserialize)]34+ | ----------- expected due to the type of this binding35+...36+8 | #[serde(default = "main")] i8,37+ | ^^^^^^ expected `i8`, found `()`added:test_suite/tests/ui/default-attribute/union_path.rs+9 added
1+use serde_derive::Deserialize;2+3+#[derive(Deserialize)]4+#[serde(default = "default_u")]5+union Union {6+ f: u8,7+}8+9+fn main() {}added:test_suite/tests/ui/default-attribute/union_path.stderr+14 added
1+error: #[serde(default = "...")] can only be used on structs2+ --> tests/ui/default-attribute/union_path.rs:4:93+ |4+4 | #[serde(default = "default_u")]5+ | ^^^^^^^^^^^^^^^^^^^^^6+7+error: Serde does not support derive for unions8+ --> tests/ui/default-attribute/union_path.rs:4:19+ |10+4 | / #[serde(default = "default_u")]11+5 | | union Union {12+6 | | f: u8,13+7 | | }14+ | |_^added:test_suite/tests/ui/default-attribute/union.rs+9 added
1+use serde_derive::Deserialize;2+3+#[derive(Deserialize)]4+#[serde(default)]5+union Union {6+ f: u8,7+}8+9+fn main() {}added:test_suite/tests/ui/default-attribute/union.stderr+14 added
1+error: #[serde(default)] can only be used on structs2+ --> tests/ui/default-attribute/union.rs:4:93+ |4+4 | #[serde(default)]5+ | ^^^^^^^6+7+error: Serde does not support derive for unions8+ --> tests/ui/default-attribute/union.rs:4:19+ |10+4 | / #[serde(default)]11+5 | | union Union {12+6 | | f: u8,13+7 | | }14+ | |_^added:test_suite/tests/ui/default-attribute/unit_path.rs+7 added
1+use serde_derive::Deserialize;2+3+#[derive(Deserialize)]4+#[serde(default = "default_u")]5+struct Unit;6+7+fn main() {}added:test_suite/tests/ui/default-attribute/unit_path.stderr+5 added
1+error: #[serde(default = "...")] can only be used on structs that have fields2+ --> tests/ui/default-attribute/unit_path.rs:4:93+ |4+4 | #[serde(default = "default_u")]5+ | ^^^^^^^^^^^^^^^^^^^^^added:test_suite/tests/ui/default-attribute/unit.rs+7 added
1+use serde_derive::Deserialize;2+3+#[derive(Deserialize)]4+#[serde(default)]5+struct Unit;6+7+fn main() {}added:test_suite/tests/ui/default-attribute/unit.stderr+7 added
1+error: #[serde(default)] can only be used on structs that have fields2+ --> tests/ui/default-attribute/unit.rs:3:103+ |4+3 | #[derive(Deserialize)]5+ | ^^^^^^^^^^^6+ |7+ = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)added:test_suite/tests/ui/with/incorrect_type.rs+23 added
1+use serde_derive::{Deserialize, Serialize};2+3+mod w {4+ use serde::{Deserializer, Serializer};5+6+ pub fn deserialize<'de, D: Deserializer<'de>>(_: D) -> Result<(), D::Error> {7+ unimplemented!()8+ }9+ pub fn serialize<T, S: Serializer>(_: S) -> Result<S::Ok, S::Error> {10+ unimplemented!()11+ }12+}13+14+#[derive(Serialize, Deserialize)]15+struct W(#[serde(with = "w")] u8, u8);16+17+#[derive(Serialize, Deserialize)]18+struct S(#[serde(serialize_with = "w::serialize")] u8, u8);19+20+#[derive(Serialize, Deserialize)]21+struct D(#[serde(deserialize_with = "w::deserialize")] u8, u8);22+23+fn main() {}added:test_suite/tests/ui/with/incorrect_type.stderr+97 added
1+error[E0277]: the trait bound `&u8: Serializer` is not satisfied2+ --> tests/ui/with/incorrect_type.rs:14:103+ |4+14 | #[derive(Serialize, Deserialize)]5+ | ^^^^^^^^^ the trait `Serializer` is not implemented for `&u8`6+15 | struct W(#[serde(with = "w")] u8, u8);7+ | --- required by a bound introduced by this call8+ |9+ = help: the following other types implement trait `Serializer`:10+ &'a mut Formatter<'b>11+ FlatMapSerializer<'a, M>12+ _::_serde::__private::ser::content::ContentSerializer<E>13+note: required by a bound in `w::serialize`14+ --> tests/ui/with/incorrect_type.rs:9:2815+ |16+9 | pub fn serialize<T, S: Serializer>(_: S) -> Result<S::Ok, S::Error> {17+ | ^^^^^^^^^^ required by this bound in `serialize`18+19+error[E0061]: this function takes 1 argument but 2 arguments were supplied20+ --> tests/ui/with/incorrect_type.rs:15:2521+ |22+15 | struct W(#[serde(with = "w")] u8, u8);23+ | ^^^ unexpected argument #2 of type `__S`24+ |25+note: function defined here26+ --> tests/ui/with/incorrect_type.rs:9:1227+ |28+9 | pub fn serialize<T, S: Serializer>(_: S) -> Result<S::Ok, S::Error> {29+ | ^^^^^^^^^ ----30+31+error[E0277]: the trait bound `&u8: Serializer` is not satisfied32+ --> tests/ui/with/incorrect_type.rs:15:2533+ |34+15 | struct W(#[serde(with = "w")] u8, u8);35+ | ^^^ the trait `Serializer` is not implemented for `&u8`36+ |37+ = help: the following other types implement trait `Serializer`:38+ &'a mut Formatter<'b>39+ FlatMapSerializer<'a, M>40+ _::_serde::__private::ser::content::ContentSerializer<E>41+42+error[E0308]: `?` operator has incompatible types43+ --> tests/ui/with/incorrect_type.rs:15:2544+ |45+15 | struct W(#[serde(with = "w")] u8, u8);46+ | ^^^ expected `u8`, found `()`47+ |48+ = note: `?` operator cannot convert from `()` to `u8`49+50+error[E0277]: the trait bound `&u8: Serializer` is not satisfied51+ --> tests/ui/with/incorrect_type.rs:17:1052+ |53+17 | #[derive(Serialize, Deserialize)]54+ | ^^^^^^^^^ the trait `Serializer` is not implemented for `&u8`55+18 | struct S(#[serde(serialize_with = "w::serialize")] u8, u8);56+ | -------------- required by a bound introduced by this call57+ |58+ = help: the following other types implement trait `Serializer`:59+ &'a mut Formatter<'b>60+ FlatMapSerializer<'a, M>61+ _::_serde::__private::ser::content::ContentSerializer<E>62+note: required by a bound in `w::serialize`63+ --> tests/ui/with/incorrect_type.rs:9:2864+ |65+9 | pub fn serialize<T, S: Serializer>(_: S) -> Result<S::Ok, S::Error> {66+ | ^^^^^^^^^^ required by this bound in `serialize`67+68+error[E0061]: this function takes 1 argument but 2 arguments were supplied69+ --> tests/ui/with/incorrect_type.rs:18:3570+ |71+18 | struct S(#[serde(serialize_with = "w::serialize")] u8, u8);72+ | ^^^^^^^^^^^^^^ unexpected argument #2 of type `__S`73+ |74+note: function defined here75+ --> tests/ui/with/incorrect_type.rs:9:1276+ |77+9 | pub fn serialize<T, S: Serializer>(_: S) -> Result<S::Ok, S::Error> {78+ | ^^^^^^^^^ ----79+80+error[E0277]: the trait bound `&u8: Serializer` is not satisfied81+ --> tests/ui/with/incorrect_type.rs:18:3582+ |83+18 | struct S(#[serde(serialize_with = "w::serialize")] u8, u8);84+ | ^^^^^^^^^^^^^^ the trait `Serializer` is not implemented for `&u8`85+ |86+ = help: the following other types implement trait `Serializer`:87+ &'a mut Formatter<'b>88+ FlatMapSerializer<'a, M>89+ _::_serde::__private::ser::content::ContentSerializer<E>90+91+error[E0308]: `?` operator has incompatible types92+ --> tests/ui/with/incorrect_type.rs:21:3793+ |94+21 | struct D(#[serde(deserialize_with = "w::deserialize")] u8, u8);95+ | ^^^^^^^^^^^^^^^^ expected `u8`, found `()`96+ |97+ = note: `?` operator cannot convert from `()` to `u8`