From f4b78e202a12672fbb209536c21996484e238e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=CC=81rpa=CC=81d=20Goretity?= Date: Thu, 8 Mar 2018 09:57:05 +0100 Subject: [PATCH] add a check for conflicting adjacent tags as well --- serde_derive_internals/src/check.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/serde_derive_internals/src/check.rs b/serde_derive_internals/src/check.rs index 9ab8e45b..229896cd 100644 --- a/serde_derive_internals/src/check.rs +++ b/serde_derive_internals/src/check.rs @@ -17,6 +17,7 @@ pub fn check(cx: &Ctxt, cont: &Container) { check_identifier(cx, cont); check_variant_skip_attrs(cx, cont); check_internal_tag_field_name_conflict(cx, cont); + check_adjacent_tag_conflict(cx, cont); } /// Getters are only allowed inside structs (not enums) with the `remote` @@ -217,3 +218,20 @@ fn check_internal_tag_field_name_conflict( } } } + +/// In the case of adjacently-tagged enums, the type and the +/// contents tag must differ, for the same reason. +fn check_adjacent_tag_conflict(cx: &Ctxt, cont: &Container) { + let (type_tag, content_tag) = match *cont.attrs.tag() { + EnumTag::Adjacent { ref tag, ref content } => (tag, content), + EnumTag::Internal { .. } | EnumTag::External | EnumTag::None => return, + }; + + if type_tag == content_tag { + let message = format!( + "Enum tags `{}` for type and content conflict with each other", + type_tag + ); + cx.error(message); + } +}