Make Clippy happy with is_ascii_* methods (#1159)

This commit is contained in:
Chris 2023-04-04 05:11:10 -04:00 committed by GitHub
parent 91064e9554
commit 42ad693fcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 15 deletions

View file

@ -515,15 +515,15 @@ fn is_source_char(c: char) -> bool {
}
fn is_name_start(c: char) -> bool {
c == '_' || ('A'..='Z').contains(&c) || ('a'..='z').contains(&c)
c == '_' || c.is_ascii_alphabetic()
}
fn is_name_cont(c: char) -> bool {
is_name_start(c) || ('0'..='9').contains(&c)
is_name_start(c) || c.is_ascii_digit()
}
fn is_number_start(c: char) -> bool {
c == '-' || ('0'..='9').contains(&c)
c == '-' || c.is_ascii_digit()
}
impl fmt::Display for LexerError {

View file

@ -5,24 +5,13 @@ use std::{
str::FromStr,
};
// Helper functions until the corresponding AsciiExt methods
// stabilise (https://github.com/rust-lang/rust/issues/39658).
fn is_ascii_alphabetic(c: char) -> bool {
('a'..='z').contains(&c) || ('A'..='Z').contains(&c)
}
fn is_ascii_digit(c: char) -> bool {
('0'..='9').contains(&c)
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Name(String);
impl Name {
pub fn is_valid(input: &str) -> bool {
for (i, c) in input.chars().enumerate() {
let is_valid = is_ascii_alphabetic(c) || c == '_' || (i > 0 && is_ascii_digit(c));
let is_valid = c.is_ascii_alphabetic() || c == '_' || (i > 0 && c.is_ascii_digit());
if !is_valid {
return false;
}