Skip to content

Lint request: char_is_the_wrong_abstraction #6845

@SoniEx2

Description

@SoniEx2

What it does

We want a restriction lint that prevents using char and std::str::Chars. We want to discourage ppl contributing to our code from using char because we believe it's just the wrong abstraction, and would rather it just errored so we can explain to ppl that things like grapheme clusters and whatnot exist and they should be preferred. The std suggests you may want to look into grapheme clusters instead of using str.chars, which is a great suggestion but unfortunately it's just not made prominent enough, and this would fix that. Further, even the std documentation often passes the wrong idea about char-based APIs, leading to bugs in user code (this isn't meant to say those APIs should be deprecated, or those docs shouldn't be fixed. it's just mean to show that even std makes mistakes, so char is just a bad idea in general).

Categories (optional)

  • Kind: restriction
  • Internationalization

Drawbacks

Being able to use an fn(char)->bool as a Pattern is actually somewhat useful, but it's easy enough to slap an #[allow] on those so it's not a major drawback.

Example

char

Could be written as:

SmallString<[u8; 8]>

Motivation

See also https://github.com/kdeldycke/awesome-falsehood#internationalization and in particular https://eev.ee/blog/2015/09/12/dark-corners-of-unicode/ and https://manishearth.github.io/blog/2017/01/14/stop-ascribing-meaning-to-unicode-code-points/

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsS-needs-discussionStatus: Needs further discussion before merging or work can be started

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions