Skip to content

c_import static inline: a field of a by-value struct parameter passed to a raw call emits a redundant nested unsafe prefix (warning on every such header) #1433

Closed as not planned

Description

@ehartford

Repro (seed at 8c859a7 / main 04e4934; also stage1 of modeled-c-stage5)

use c_import("void free(void *p);
typedef struct { int* n; } Counter;
static inline void counter_free(Counter c) { free(c.n); }
")
fn main:
    print("ok")

with check:

warning: redundant unsafe prefix inside unsafe context
 --> <c_import …>:44:27
44 |     unsafe { with_free((((unsafe *(&raw const __param_c as *const Counter)).n as *mut c_void) as *mut u8)) }

What happens

The translation of a static inline body that reads a field of a by-value struct parameter, when that field is passed to a raw call, emits an inner unsafe * prefix inside the unsafe { } that wraps the call.

Expected

The generated body is warning-free, like the migrator's output since the redundant-unsafe fix: the prefix is emitted only outside an unsafe context.

Every c_import test fixture that frees through a by-value struct parameter prints this warning. The stage 5 debug-alloc fixtures on #1426 hit it.

Activity

  1. ehartford commented on Sep 26, 2026

    @ehartford
    ContributorAuthor

    Duplicate of #1704 (the redundant unsafe prefix in translated code); fixed in #1707.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions