Skip to content

Commit 6bfc843

Browse files
bors[bot]theli-ua
andauthored
Merge #491
491: Fix type paths for arrays of nested clusters r=burrbull a=theli-ua This is a followup to #489 , this time for arrays Co-authored-by: Anton Romanov <theli.ua@gmail.com>
2 parents cc45313 + ad0f3f9 commit 6bfc843

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/generate/peripheral.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -892,15 +892,15 @@ fn convert_svd_cluster(cluster: &Cluster, name: Option<&str>) -> Result<syn::Fie
892892
new_syn_field(&info.name.to_sanitized_snake_case(), ty)
893893
}
894894
Cluster::Array(info, array_info) => {
895-
let name = util::replace_suffix(&info.name, "");
895+
let ty_name = util::replace_suffix(&info.name, "");
896896

897897
let ty = syn::Type::Array(parse_str::<syn::TypeArray>(&format!(
898898
"[{};{}]",
899-
&name.to_sanitized_upper_case(),
899+
name_to_ty_str(&ty_name, name),
900900
u64::from(array_info.dim)
901901
))?);
902902

903-
new_syn_field(&name.to_sanitized_snake_case(), ty)
903+
new_syn_field(&ty_name.to_sanitized_snake_case(), ty)
904904
}
905905
})
906906
}
@@ -918,8 +918,8 @@ fn new_syn_field(ident: &str, ty: syn::Type) -> syn::Field {
918918
}
919919
}
920920

921-
fn name_to_ty(name: &str, ns: Option<&str>) -> Result<syn::Type, syn::Error> {
922-
let ident = if let Some(ns) = ns {
921+
fn name_to_ty_str<'a, 'b>(name: &'a str, ns: Option<&'b str>) -> Cow<'a, str> {
922+
if let Some(ns) = ns {
923923
Cow::Owned(
924924
String::from("self::")
925925
+ &ns.to_sanitized_snake_case()
@@ -928,7 +928,11 @@ fn name_to_ty(name: &str, ns: Option<&str>) -> Result<syn::Type, syn::Error> {
928928
)
929929
} else {
930930
name.to_sanitized_upper_case()
931-
};
931+
}
932+
}
933+
934+
fn name_to_ty(name: &str, ns: Option<&str>) -> Result<syn::Type, syn::Error> {
935+
let ident = name_to_ty_str(&name, ns);
932936
Ok(syn::Type::Path(parse_str::<syn::TypePath>(&ident)?))
933937
}
934938

0 commit comments

Comments
 (0)