Skip to content

Commit e40ae08

Browse files
authored
Rollup merge of #77831 - LingMan:use_std, r=jonas-schievink
Use std methods on char instead of open coding them
2 parents 233319f + a56b0e9 commit e40ae08

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

compiler/rustc_builtin_macros/src/format_foreign.rs

+10-23
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ pub mod printf {
385385
if let Start = state {
386386
match c {
387387
'1'..='9' => {
388-
let end = at_next_cp_while(next, is_digit);
388+
let end = at_next_cp_while(next, char::is_ascii_digit);
389389
match end.next_cp() {
390390
// Yes, this *is* the parameter.
391391
Some(('$', end2)) => {
@@ -427,7 +427,7 @@ pub mod printf {
427427
move_to!(next);
428428
}
429429
'1'..='9' => {
430-
let end = at_next_cp_while(next, is_digit);
430+
let end = at_next_cp_while(next, char::is_ascii_digit);
431431
state = Prec;
432432
width = Some(Num::from_str(at.slice_between(end).unwrap(), None));
433433
move_to!(end);
@@ -441,7 +441,7 @@ pub mod printf {
441441
}
442442

443443
if let WidthArg = state {
444-
let end = at_next_cp_while(at, is_digit);
444+
let end = at_next_cp_while(at, char::is_ascii_digit);
445445
match end.next_cp() {
446446
Some(('$', end2)) => {
447447
state = Prec;
@@ -473,7 +473,7 @@ pub mod printf {
473473
if let PrecInner = state {
474474
match c {
475475
'*' => {
476-
let end = at_next_cp_while(next, is_digit);
476+
let end = at_next_cp_while(next, char::is_ascii_digit);
477477
match end.next_cp() {
478478
Some(('$', end2)) => {
479479
state = Length;
@@ -488,7 +488,7 @@ pub mod printf {
488488
}
489489
}
490490
'0'..='9' => {
491-
let end = at_next_cp_while(next, is_digit);
491+
let end = at_next_cp_while(next, char::is_ascii_digit);
492492
state = Length;
493493
precision = Some(Num::from_str(at.slice_between(end).unwrap(), None));
494494
move_to!(end);
@@ -563,12 +563,12 @@ pub mod printf {
563563

564564
fn at_next_cp_while<F>(mut cur: Cur<'_>, mut pred: F) -> Cur<'_>
565565
where
566-
F: FnMut(char) -> bool,
566+
F: FnMut(&char) -> bool,
567567
{
568568
loop {
569569
match cur.next_cp() {
570570
Some((c, next)) => {
571-
if pred(c) {
571+
if pred(&c) {
572572
cur = next;
573573
} else {
574574
return cur;
@@ -579,14 +579,7 @@ pub mod printf {
579579
}
580580
}
581581

582-
fn is_digit(c: char) -> bool {
583-
match c {
584-
'0'..='9' => true,
585-
_ => false,
586-
}
587-
}
588-
589-
fn is_flag(c: char) -> bool {
582+
fn is_flag(c: &char) -> bool {
590583
match c {
591584
'0' | '-' | '+' | ' ' | '#' | '\'' => true,
592585
_ => false,
@@ -723,17 +716,11 @@ pub mod shell {
723716
}
724717

725718
fn is_ident_head(c: char) -> bool {
726-
match c {
727-
'a'..='z' | 'A'..='Z' | '_' => true,
728-
_ => false,
729-
}
719+
c.is_ascii_alphabetic() || c == '_'
730720
}
731721

732722
fn is_ident_tail(c: char) -> bool {
733-
match c {
734-
'0'..='9' => true,
735-
c => is_ident_head(c),
736-
}
723+
c.is_ascii_alphanumeric() || c == '_'
737724
}
738725

739726
#[cfg(test)]

0 commit comments

Comments
 (0)