Skip to content

type parameters expect camel case, but shouting case is also common #60570

Open
@ExpHP

Description

@ExpHP

I am not sure why type parameters are checked to be upper camel case.

Type parameter names are not part of public API. Shouting case for type parameters is a convention followed by such popular crates as rayon, and it is the only way I know of to make something like the following not look confusing:

#[derive(Debug, Clone, PartialEq)]
pub enum Data<
    INTEGER = Vec<i32>,
    CHARACTER = Vec<u8>,
    COMPLEX = Vec<(f64, f64)>,
> {
    Integer(INTEGER),
    Character(CHARACTER),
    Complex(COMPLEX),
}

Furthermore, due to limitations of the check for upper camel case, you could write a whole crate using shouting case and not even know about the lint, because it will only hit you when you write an underscore:

pub fn zip<
    INTEGER_1, CHARACTER_1, COMPLEX_1,
    INTEGER_2, CHARACTER_2, COMPLEX_2,
>(
    data_1: Data<INTEGER_1, CHARACTER_1, COMPLEX_1>,
    data_2: Data<INTEGER_2, CHARACTER_2, COMPLEX_2>,
) -> Data<
    (INTEGER_1, INTEGER_2),
    (CHARACTER_1, CHARACTER_2),
    (COMPLEX_1, COMPLEX_2),
> { unimplemented!() }
warning: type parameter `INTEGER_1` should have a camel case name
 --> lib.rs:3:9
  |
3 |         INTEGER_1, CHARACTER_1, COMPLEX_1,
  |         ^^^^^^^^^ help: convert the identifier to camel case: `Integer1`
  |
  = note: #[warn(non_camel_case_types)] on by default

Given how rarely underscores should be needed, it's tempting to just change this to INTEGER1 so that it slips by unnoticed like the rest of the crate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions