Skip to content

vec as_ptr/as_mut_ptr should have a deny lint #2637

Closed
@TheDan64

Description

@TheDan64

Hi!

Similarly to the temporary_cstring_as_ptr lint, a common mistake I've run into when dealing with FFI a bunch is immediately trying to get a raw pointer from an initialized vec:

let ptr = vec![0; 4].as_mut_ptr();

This is a really easy way to get a dangling pointer and can be easily overlooked. It would be great if we had a clippy lint for it and as_ptr as well.

There are quite a few ways to initialize a vec that should be also taken into consideration, for example:

let ptr = Vec::from_elem(0, 4).as_mut_ptr();

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-correctnessLint: Belongs in the correctness lint group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions