Skip to content

extern functions considered safe even though they are not "rust-intrinsic" #6334

Closed
@frazar

Description

@frazar

After PR #6307, all functions coming from extern blocks are considered safe if their name is found in this list. However, only functions defined in extern "rust-instrinsic" blocks should get this treatment.

Expected outcome:

extern "rust-intrinsic" {
    pub fn likely(b: bool) -> bool; // <- Safe to call since it comes from rust-intrinsic
}

extern "foo" {
    pub fn bitreverse(x: u32) -> u32; // <- Unsafe to call as it doesn't come from rust-intrinsic
}

fn main() {
    let _ = likely(true);
    let _ = bitreverse(12);
          //^^^^^^^^^^^^^^ This operation is unsafe and requires an unsafe function or block
}

As discussed in the comments to PR #6307, this should be simply a matter of checking the ABI node of the extern block.

Possible solution strategy:

  1. Solve Design string tokens #6308
  2. Add a way to access the name of the ABI node
  1. Modify this line so that functions are marked as safe if they come from an extern "rust-intrinsic" blocks AND their name matches the whitelist

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-has-instructionsIssue has some instructions and pointers to code to get startedE-mediumS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions