Skip to content

Delegation: It's impossible to reuse foreign fns #127412

Closed
@fmease

Description

@fmease
Member

Example:

#![feature(fn_delegation)]

extern "C" {
    fn f();
}

reuse f as g;
//~^ ERROR call to unsafe function `f` is unsafe and requires unsafe function or block

The synthesized fn g ought to be marked unsafe as f is implicitly unsafe1 but that doesn't happen.

Footnotes

  1. Unless marked safe under feature unsafe_extern_blocks, these are possible to reuse for obvious reasons.

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
on Jul 6, 2024
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jul 6, 2024
removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jul 6, 2024
fmease

fmease commented on Jul 6, 2024

@fmease
MemberAuthor

Tangentially related: We should probably start wrapping a delegation's target expr (→→ return expr) in an unsafe block to accommodate lint unsafe_op_in_unsafe_fn (allow-by-default in Rust <2024, warn-by-default in Rust 2024):

#![deny(unsafe_op_in_unsafe_fn)]
#![feature(fn_delegation)]

unsafe fn f() {}
reuse f as g; //~ ERROR call to unsafe function `f` is unsafe and requires unsafe block

Edit: Ah, not quite. Forgot about lint unused_unsafe for a sec. We're in a bit of pickle here unless we inspect the lint levels at that node which feels ... hacky?

Edit 2: Well, we could just skip delegation items in both lints.

fmease

fmease commented on Jul 6, 2024

@fmease
MemberAuthor

Ah, furthermore we don't seem to "inherit" the parameters of foreign fns. So it seems like we don't handle foreign fns correctly at all (dropping params and header (safety, ...)).

workingjubilee

workingjubilee commented on Jul 6, 2024

@workingjubilee
Member

awesome.

added 2 commits that reference this issue on Mar 13, 2025

Rollup merge of rust-lang#138399 - Bryanskiy:delegation-extern-fn, r=…

53d68e5

Rollup merge of rust-lang#138399 - Bryanskiy:delegation-extern-fn, r=…

41d6e6e
added a commit that references this issue on Mar 13, 2025
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

    C-bugCategory: This is a bug.F-fn_delegation`#![feature(fn_delegation)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-incomplete-featuresThis issue requires the use of incomplete features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @fmease@workingjubilee@rustbot

      Issue actions

        Delegation: It's impossible to `reuse` foreign fns · Issue #127412 · rust-lang/rust