rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Add disallowed_fields lint

Open i509VCB opened this issue 3 years ago • 0 comments

What it does

Like disallowed_methods and disallowed_types, this lint warns when a field on a type is used.

Lint Name

disallowed_fields

Category

style

Advantage

  • Using some field on some type may be discouraged in some library.
    • For example, the ABI of some type in a library you depend on may make hiding a field impossible but using said field should be discouraged by code inside your implementation. The lint would allow a more obvious warning.

Drawbacks

  • Might be a niche lint.

Example

Could use a better type as an example:

# clippy.toml
disallowed-fields = [
    # Can use a string as the path of the disallowed field.
    "std::ops::Range::start",
    # Can also use an inline table with a `path` key.
    { path = "std::ops::Range::start" },
    # When using an inline table, can add a `reason` for why the field
    # is disallowed.
    { path = "std::ops::Range::start", reason = "The start of the range is not used" },
]

i509VCB avatar Aug 01 '22 21:08 i509VCB