Skip to content

Suggest using is_ascii_lowercase / is_ascii_uppercase #9290

@leonardo-m

Description

@leonardo-m

What it does

This simple lint suggests to replace matches!() on full upper/lower case ranges with the built-in methods.

Lint Name

use_is_ascii_lower_upper_case

Category

style

Advantage

The code is simpler, it contains less tokens.

Drawbacks

None, I think.

Example

#![warn(clippy::all)]
#![warn(clippy::nursery)]
#![warn(clippy::pedantic)]
fn main() {
    assert!(matches!('x', 'a' ..= 'z'));
    assert!(matches!('X', 'A' ..= 'Z'));
    assert!(matches!(b'x', b'a' ..= b'z'));
    assert!(matches!(b'X', b'A' ..= b'Z'));
}

Could be written as:

#![warn(clippy::all)]
#![warn(clippy::nursery)]
#![warn(clippy::pedantic)]
fn main() {
    assert!('x'.is_ascii_lowercase());
    assert!(b'x'.is_ascii_lowercase());
    assert!('X'.is_ascii_uppercase());
    assert!(b'X'.is_ascii_uppercase());    
}

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