diff --git a/src/de.rs b/src/de.rs index c4d65518..24249324 100644 --- a/src/de.rs +++ b/src/de.rs @@ -557,12 +557,14 @@ where } fn invalid_type(event: &Event, exp: &Expected) -> Error { + enum Void {} + struct InvalidType<'a> { exp: &'a Expected, } impl<'de, 'a> Visitor<'de> for InvalidType<'a> { - type Value = Error; + type Value = Void; fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { self.exp.fmt(formatter) @@ -573,7 +575,10 @@ fn invalid_type(event: &Event, exp: &Expected) -> Error { Event::Alias(_) => unreachable!(), Event::Scalar(ref v, style, ref tag) => { let get_type = InvalidType { exp: exp }; - visit_scalar(v, style, tag, get_type).unwrap() + match visit_scalar(v, style, tag, get_type) { + Ok(void) => match void {}, + Err(invalid_type) => invalid_type, + } } Event::SequenceStart => de::Error::invalid_type(Unexpected::Seq, exp), Event::MappingStart => de::Error::invalid_type(Unexpected::Map, exp), diff --git a/tests/test_error.rs b/tests/test_error.rs index 17405f34..796d9ba1 100644 --- a/tests/test_error.rs +++ b/tests/test_error.rs @@ -245,3 +245,15 @@ fn test_no_location() { assert_eq!(utf8_location.is_none(), true); } + +#[test] +fn test_invalid_scalar_type() { + #[derive(Deserialize, Debug)] + struct S { + x: [(); 1], + } + + let yaml = "x:\n"; + let expected = "x: invalid type: unit value, expected an array of length 1 at line 2 column 1"; + test_error::(yaml, expected); +}