Skip to content

ptr_arg should ignore extern functions #11181

@david-monroe

Description

@david-monroe

Summary

There is usually no way for extern code to convert a &Vec<u8> to a &[u8] as the layout of the latter is unspecified.

Why this is bad

Requiring the argument to be of the specific size makes the function less useful for no benefit;

The benefit is that it can be used from extern code.

Lint Name

ptr_arg

Reproducer

I tried this code:

    #[no_mangle]
    pub extern "C" fn read_buffer(buffer: &Vec<u8>, len: usize) {
        
    }

I saw this happen:

  |
2 |     pub extern "C" fn read_buffer(buffer: &Vec<u8>, len: usize) {
  |                                           ^^^^^^^^ help: change this to: `&[u8]`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
  = note: `#[warn(clippy::ptr_arg)]` on by default

I expected to see this happen:

No warning.

Version

Playground

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't havegood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions