Skip to content

Clippy warning about an almost complete ascii range #1070

@xamgore

Description

@xamgore

I am running cargo clippy over async-graphql crate which uses pest v2.7.11.

warning: almost complete ascii range
    --> parser/src/parse/generated.rs:2312:29
     |
2312 |           state.match_range('0'..'9')
     |                             ^^^--^^^
     |                                |
     |                                help: use an inclusive range: `..=`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_range
     = note: `#[warn(clippy::almost_complete_range)]` on by default

As we can see at vm.rs and generator.rs, range is included in fact.

// vm
"ASCII_DIGIT" => return state.match_range('0'..'9'),

// generated
insert_builtin!(builtins, ASCII_DIGIT, state.match_range('0'..'9'));

pub(crate) fn match_range(&mut self, range: Range<char>) -> bool {
    if let Some(c) = self.input[self.pos..].chars().next() {
        if range.start <= c && c <= range.end {   // <<<<<<<<<<< here
            self.pos += c.len_utf8();
            return true;
        }
    }

    false
}

As pest uses 0..9 just for expressiveness, I would either mute clippy at the generated code, or switched to 0..=9 (affects MSRV).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions