Skip to content

Add disallowed_fields lint #9278

@i509VCB

Description

@i509VCB

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" },
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions