Skip to content

Lint suggestion: Suggest separating (or combining) attributes which accept a list of parameters #11331

Open
@clarfonthey

Description

@clarfonthey

What it does

Common practice in a lot of Rust code is to separate #![feature(...)], #![allow(...)], #![deny(...)], and #![warn(...)] attributes so that each item is a separate attribute, rather than a list of several. The proposal would be, for some potentially configurable list of attributes, suggest to either separate these attributes or combine them when applied to an item.

Advantage

Generally, separating onto multiple lines makes it easier to not "miss" items where a list is included on a single line. So, having a lint to enforce (and automatically fix) these cases would be very helpful.

However, because some people might also like the alternative method, and it's possible to format the attributes so that the list items are still on their own lines if the list is sufficiently large, I'm proposing to also add the ability to format in that way too.

Drawbacks

It might be too good.

Example

Valid combined:

#![allow(clippy::cursed_rust_patterns, live_code, rustc::eating_laundry)]
#![feature(cursed_types, java_style_inheritance, return_position_type_alias_impl_trait_in_struct)]

Valid separated:

#![allow(clippy::cursed_rust_patterns)]
#![allow(live_code)]
#![allow(rustc::eating_laundry)]
#![feature(cursed_types)]
#![feature(java_style_inheritance)]
#![feature(return_position_type_alias_impl_trait_in_struct)]

Invalid in both cases:

#![allow(clippy::cursed_rust_patterns, rustc::eating_laundry)]
#![allow(live_code)]
#![feature(cursed_types, return_position_type_alias_impl_trait_in_struct)]
#![feature(java_style_inheritance)]

Prior Art

This would have been helpful when working on rust-lang/rust#114766.

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