Skip to content

Commit 1d53369

Browse files
committed
use instead of type alias for writer
1 parent c19ce32 commit 1d53369

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

src/generate/register.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,10 @@ pub fn fields(
616616
// information in enumeratedValues;
617617
// if it's not enumeratedValues, always derive the read proxy as we do not need to re-export
618618
// it again from BitReader or FieldReader.
619-
let should_derive_reader = match lookup_filter(&lookup_results, Usage::Read) {
620-
Some((_evs, Some(_base))) => false,
621-
Some((_evs, None)) => true,
622-
None => true,
623-
};
619+
let should_derive_reader = matches!(
620+
lookup_filter(&lookup_results, Usage::Read),
621+
Some((_, None)) | None
622+
);
624623

625624
// derive the read proxy structure if necessary.
626625
if should_derive_reader {
@@ -932,11 +931,10 @@ pub fn fields(
932931

933932
// derive writer. We derive writer if the write proxy is in current register module,
934933
// or writer in different register have different _SPEC structures
935-
let should_derive_writer = match lookup_filter(&lookup_results, Usage::Write) {
936-
Some((_evs, Some(base))) => base.register() != fpath.register(),
937-
Some((_evs, None)) => true,
938-
None => true,
939-
};
934+
let should_derive_writer = matches!(
935+
lookup_filter(&lookup_results, Usage::Write),
936+
Some((_, None)) | None
937+
);
940938

941939
// derive writer structure by type alias to generic write proxy structure.
942940
if should_derive_writer {
@@ -1006,6 +1004,22 @@ pub fn fields(
10061004
}
10071005

10081006
if let Some((evs, Some(base))) = lookup_filter(&lookup_results, Usage::Write) {
1007+
// if base.register == None, derive write from the same module. This is allowed because both
1008+
// the generated and source write proxy are in the same module.
1009+
// we never reuse writer for writer in different module does not have the same _SPEC strcuture,
1010+
// thus we cannot write to current register using re-exported write proxy.
1011+
1012+
// generate pub use field_1 writer as field_2 writer
1013+
let base_field = util::replace_suffix(&base.field.name, "");
1014+
let base_w = (base_field + "_W").to_constant_case_ident(span);
1015+
if !writer_derives.contains(&writer_ty) {
1016+
let base_path = base_syn_path(base, &fpath, &base_w)?;
1017+
mod_items.extend(quote! {
1018+
#[doc = #field_writer_brief]
1019+
pub use #base_path as #writer_ty;
1020+
});
1021+
writer_derives.insert(writer_ty.clone());
1022+
}
10091023
// if base.register == None, it emits pub use structure from same module.
10101024
if base.register() != fpath.register() {
10111025
let writer_reader_different_enum = evs_r != Some(evs);
@@ -1020,23 +1034,6 @@ pub fn fields(
10201034
writer_enum_derives.insert(value_write_ty.clone());
10211035
}
10221036
}
1023-
} else {
1024-
// if base.register == None, derive write from the same module. This is allowed because both
1025-
// the generated and source write proxy are in the same module.
1026-
// we never reuse writer for writer in different module does not have the same _SPEC strcuture,
1027-
// thus we cannot write to current register using re-exported write proxy.
1028-
1029-
// generate pub use field_1 writer as field_2 writer
1030-
let base_field = util::replace_suffix(&base.field.name, "");
1031-
let base_w = (base_field + "_W").to_constant_case_ident(span);
1032-
if !writer_derives.contains(&writer_ty) {
1033-
let base_path = base_syn_path(base, &fpath, &base_w)?;
1034-
mod_items.extend(quote! {
1035-
#[doc = #field_writer_brief]
1036-
pub use #base_path as #writer_ty;
1037-
});
1038-
writer_derives.insert(writer_ty.clone());
1039-
}
10401037
}
10411038
}
10421039

0 commit comments

Comments
 (0)