From 1265f4bb674a8d79cf8bbe2da085979c57730514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Sat, 29 Jun 2024 16:53:27 +0200 Subject: [PATCH] xso-proc: fix warnings when struct names end on `_` --- xso-proc/src/structs.rs | 14 ++++++++++++-- xso/ChangeLog | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/xso-proc/src/structs.rs b/xso-proc/src/structs.rs index 9106ffee..e9233800 100644 --- a/xso-proc/src/structs.rs +++ b/xso-proc/src/structs.rs @@ -64,6 +64,16 @@ pub(crate) struct StructDef { debug: bool, } +fn concat_camel_case(lhs: &Ident, suffix: &str) -> Ident { + let span = lhs.span(); + let mut s = lhs.to_string(); + while s.ends_with('_') { + s.pop(); + } + s.push_str(suffix); + Ident::new(&s, span) +} + impl StructDef { /// Create a new struct from its name, meta, and fields. pub(crate) fn new(ident: &Ident, meta: XmlCompoundMeta, fields: &Fields) -> Result { @@ -80,8 +90,8 @@ impl StructDef { name, inner: Compound::from_fields(fields)?, target_ty_ident: ident.clone(), - builder_ty_ident: quote::format_ident!("{}FromXmlBuilder", ident), - item_iter_ty_ident: quote::format_ident!("{}AsXmlIterator", ident), + builder_ty_ident: concat_camel_case(ident, "FromXmlBuilder"), + item_iter_ty_ident: concat_camel_case(ident, "AsXmlIterator"), debug: meta.debug.is_set(), }) } diff --git a/xso/ChangeLog b/xso/ChangeLog index 354086de..ec84dc57 100644 --- a/xso/ChangeLog +++ b/xso/ChangeLog @@ -1,3 +1,19 @@ +Version NEXT: +0000-00-00 Jonas Schäfer + * Breaking + - We now strip trailing underscores from identifiers before constructing + any type names we declare from derive macros. That means that it is + not possible to derive the traits on `Foo` and `Foo_` if both live + in the same scope. + + As a workaround, you can put either of these types into a `mod` and + reexport them from the outer module. The types generated by the derive + macro will then be scoped inside the `mod` and cannot conflict with + the derived types on the other type. + + All this is to avoid triggering the camel case lint on the types we + generate. + Version 0.1.2: 2024-07-26 Jonas Schäfer * Added