Skip to content

c2rust-refactor: Structurally match types more conservatively by comparing visibility#1474

Merged
ahomescu merged 1 commit into
masterfrom
ahomescu/structural_eq_tys_match_vis
Nov 25, 2025
Merged

c2rust-refactor: Structurally match types more conservatively by comparing visibility#1474
ahomescu merged 1 commit into
masterfrom
ahomescu/structural_eq_tys_match_vis

Conversation

@ahomescu
Copy link
Copy Markdown
Contributor

This fixes issues where reorganize_definitions would match internal structure definitions like statvfs against the types in libc which keep some fields as private:

    pub struct statvfs {
        pub f_bsize: c_ulong,
        pub f_frsize: c_ulong,
        pub f_blocks: crate::fsblkcnt_t,
        pub f_bfree: crate::fsblkcnt_t,
        pub f_bavail: crate::fsblkcnt_t,
        pub f_files: crate::fsfilcnt_t,
        pub f_ffree: crate::fsfilcnt_t,
        pub f_favail: crate::fsfilcnt_t,
        pub f_fsid: c_ulong,
        pub f_flag: c_ulong,
        pub f_namemax: c_ulong,
        __f_spare: [c_int; 6],
    }

@ahomescu ahomescu force-pushed the ahomescu/structural_eq_tys_match_vis branch 2 times, most recently from 0dc6b18 to baf7b17 Compare November 25, 2025 06:12
…aring visibility

This fixes issues where reorganize_definitions would match
internal structure definitions like statvfs against
the types in libc which keep some fields as private:

    pub struct statvfs {
        pub f_bsize: c_ulong,
        pub f_frsize: c_ulong,
        pub f_blocks: crate::fsblkcnt_t,
        pub f_bfree: crate::fsblkcnt_t,
        pub f_bavail: crate::fsblkcnt_t,
        pub f_files: crate::fsfilcnt_t,
        pub f_ffree: crate::fsfilcnt_t,
        pub f_favail: crate::fsfilcnt_t,
        pub f_fsid: c_ulong,
        pub f_flag: c_ulong,
        pub f_namemax: c_ulong,
        __f_spare: [c_int; 6],
    }
@ahomescu ahomescu force-pushed the ahomescu/structural_eq_tys_match_vis branch from baf7b17 to 20d4fb7 Compare November 25, 2025 07:03
Copy link
Copy Markdown
Contributor

@fw-immunant fw-immunant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was initially wondering how we translate definitions from libc into types that have some private fields when afaik c2rust always emits all fields as public. But I realize you mean that c2rust-refactor was comparing transpiled structs with definitions from the actual libc crate, which is not transpiled.

LGTM.

@ahomescu ahomescu merged commit a6119e7 into master Nov 25, 2025
5 checks passed
@ahomescu ahomescu deleted the ahomescu/structural_eq_tys_match_vis branch November 25, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants