c2rust-refactor: reorganize_definitions needs to rewrite types in attributes
reorganize_definitions on curl fails because it needs to rewrite the ty attribute for all bitfields that use one of the moved types. This transform (and probably others) do not reach into attributes to look for Rust types, c2rust-bitfields encodes type names as strings. For example:
pub struct OutStruct {
pub filename: *mut ::core::ffi::c_char,
pub stream: *mut crate::stdlib::FILE,
pub bytes: crate::system_h::curl_off_t,
pub init: crate::system_h::curl_off_t,
#[bitfield(name = "alloc_filename", ty = "bit", bits = "0..=0")]
#[bitfield(name = "is_cd_filename", ty = "bit", bits = "1..=1")]
#[bitfield(name = "s_isreg", ty = "bit", bits = "2..=2")]
#[bitfield(name = "fopened", ty = "bit", bits = "3..=3")]
pub alloc_filename_is_cd_filename_s_isreg_fopened: [u8; 1],
#[bitfield(padding)]
pub c2rust_padding: [u8; 7],
}
In this structure we need to rewrite ty = "bit" into ty = "crate::curl_setup_once_h::bit" or import it into every submodule that has bitfields.
We could add a work-around to reorganize_definitions for this specific case, but it would be nice to do something more generic.
Is it necessary for this to be a string, or could it be a path in the attribute (#[ty = crate::item::whatever] with no quotes)? Replacing arbitrary bits of strings seems more worrisome than if we can limit this to references to actual Rust entities. I'm not sure if this is an actual thing that's doable in attributes, though.
@thedataking had an interesting idea if we want to enable reorganize_definitions by default: we could try to detect this (and inline assembly) in the transpiler, and call c2rust-refactor if none of those are present.
Another thought, maybe we could add self:: to the type name and only trigger this logic in the case of string values containing a double-colon?