Skip to content

Built in rule "no unsafe platform dependent ints" (perhaps no_unsafe_usize_isize) #103

@KurtWagner

Description

@KurtWagner

Needs thought, just quick brain dump

Add built-in lint rule to discourage potentially unsafe platform-dependent integer usage. e.g., serialising usize and isize where you can't guarantee the deserialising system will be 32 or 64 bit.

Safe usages would be like arithmetic on pointers, array lengths, allocating memory... 🤔

A simple start could be a configurable rule:

allow_usize_in_struct: bool = false,
allow_usize_in_public_api:bool = false,
allow_isize_in_struct: bool = false,
allow_isize_in_public_api:bool = false,

or could go for an allowlist approach to also restrict fixed width types if your project desires (in this case maybe no_unsafe_int would be a better rule name)

allow_in_struct: []const[]const int_type = &.{u8, u16, u32, u64, i32, i64 },
allow_in_public_api: []const[]const int_type = &.{u8, u16, u32, u64, i32, i64 },

Metadata

Metadata

Assignees

No one assigned

    Labels

    designSomething needing thoughtnew builtin ruleA brand new builtin rule

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions