-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a callback to rename field names #2524
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1296,6 +1296,7 @@ | |||||
fields: &mut F, | ||||||
methods: &mut M, | ||||||
extra: Self::Extra, | ||||||
parent_name: &str, | ||||||
) where | ||||||
F: Extend<proc_macro2::TokenStream>, | ||||||
M: Extend<proc_macro2::TokenStream>; | ||||||
|
@@ -1315,6 +1316,7 @@ | |||||
fields: &mut F, | ||||||
methods: &mut M, | ||||||
_: (), | ||||||
parent_name: &str, | ||||||
) where | ||||||
F: Extend<proc_macro2::TokenStream>, | ||||||
M: Extend<proc_macro2::TokenStream>, | ||||||
|
@@ -1331,6 +1333,7 @@ | |||||
fields, | ||||||
methods, | ||||||
(), | ||||||
parent_name, | ||||||
); | ||||||
} | ||||||
Field::Bitfields(ref unit) => { | ||||||
|
@@ -1344,6 +1347,7 @@ | |||||
fields, | ||||||
methods, | ||||||
(), | ||||||
parent_name, | ||||||
); | ||||||
} | ||||||
} | ||||||
|
@@ -1393,6 +1397,7 @@ | |||||
fields: &mut F, | ||||||
methods: &mut M, | ||||||
_: (), | ||||||
parent_name: &str, | ||||||
) where | ||||||
F: Extend<proc_macro2::TokenStream>, | ||||||
M: Extend<proc_macro2::TokenStream>, | ||||||
|
@@ -1438,9 +1443,15 @@ | |||||
|
||||||
let field_name = self | ||||||
.name() | ||||||
.map(|name| ctx.rust_mangle(name).into_owned()) | ||||||
.map(|name| { | ||||||
let name = ctx.rust_mangle(name); | ||||||
ctx.options() | ||||||
.process_field_name(&parent_name, &name) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clippy says
can you remove the |
||||||
.map(|name| Cow::Owned(name)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
.unwrap_or(name.to_owned()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Per clippy
|
||||||
}) | ||||||
.expect("Each field should have a name in codegen!"); | ||||||
let field_ident = ctx.rust_ident_raw(field_name.as_str()); | ||||||
let field_ident = ctx.rust_ident_raw(&field_name); | ||||||
|
||||||
if let Some(padding_field) = | ||||||
struct_layout.saw_field(&field_name, field_ty, self.offset()) | ||||||
|
@@ -1641,6 +1652,7 @@ | |||||
fields: &mut F, | ||||||
methods: &mut M, | ||||||
_: (), | ||||||
parent_name: &str, | ||||||
) where | ||||||
F: Extend<proc_macro2::TokenStream>, | ||||||
M: Extend<proc_macro2::TokenStream>, | ||||||
|
@@ -1720,6 +1732,7 @@ | |||||
fields, | ||||||
methods, | ||||||
(&unit_field_name, &mut bitfield_representable_as_int), | ||||||
parent_name, | ||||||
); | ||||||
|
||||||
// Generating a constructor requires the bitfield to be representable as an integer. | ||||||
|
@@ -1800,6 +1813,7 @@ | |||||
_fields: &mut F, | ||||||
methods: &mut M, | ||||||
(unit_field_name, bitfield_representable_as_int): (&'a str, &mut bool), | ||||||
_parent_name: &str, | ||||||
) where | ||||||
F: Extend<proc_macro2::TokenStream>, | ||||||
M: Extend<proc_macro2::TokenStream>, | ||||||
|
@@ -2002,6 +2016,7 @@ | |||||
&mut fields, | ||||||
&mut methods, | ||||||
(), | ||||||
&canonical_name, | ||||||
); | ||||||
} | ||||||
// Check whether an explicit padding field is needed | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you specify what
parent_name
is? Assuming it's the struct type, something liketype_name
may be better, since usually parent/child refer to nested types or modules (rather than fields).