From 0025ef9aba5449065c7e0649280e4158b5e5736a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 7 May 2018 11:22:20 -0700 Subject: [PATCH] Detect deserialize on a struct ending in dynamically sized slice --- serde_derive/src/de.rs | 15 +++++++++++++-- .../compile-fail/precondition/deserialize_dst.rs | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test_suite/tests/compile-fail/precondition/deserialize_dst.rs diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index 42dbe386..b0953450 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -15,15 +15,16 @@ use syn::{self, Ident, Index, Member}; use bound; use fragment::{Expr, Fragment, Match, Stmts}; use internals::ast::{Container, Data, Field, Style, Variant}; -use internals::{self, attr}; +use internals::{attr, Ctxt}; use pretend; use try; use std::collections::BTreeSet; pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result { - let ctxt = internals::Ctxt::new(); + let ctxt = Ctxt::new(); let cont = Container::from_ast(&ctxt, input); + precondition(&ctxt, &cont); try!(ctxt.check()); let ident = cont.ident; @@ -80,6 +81,16 @@ pub fn expand_derive_deserialize(input: &syn::DeriveInput) -> Result or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[macro_use] +extern crate serde_derive; + +#[derive(Deserialize)] //~ ERROR: proc-macro derive panicked +struct S { + string: String, + slice: [u8], //~^^^ HELP: cannot deserialize a dynamically sized struct +}