Skip to content

Commit

Permalink
Rollup merge of rust-lang#77831 - LingMan:use_std, r=jonas-schievink
Browse files Browse the repository at this point in the history
Use std methods on char instead of open coding them
  • Loading branch information
JohnTitor authored Oct 12, 2020
2 parents b1fa955 + a56b0e9 commit 58542c2
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions compiler/rustc_builtin_macros/src/format_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub mod printf {
if let Start = state {
match c {
'1'..='9' => {
let end = at_next_cp_while(next, is_digit);
let end = at_next_cp_while(next, char::is_ascii_digit);
match end.next_cp() {
// Yes, this *is* the parameter.
Some(('$', end2)) => {
Expand Down Expand Up @@ -427,7 +427,7 @@ pub mod printf {
move_to!(next);
}
'1'..='9' => {
let end = at_next_cp_while(next, is_digit);
let end = at_next_cp_while(next, char::is_ascii_digit);
state = Prec;
width = Some(Num::from_str(at.slice_between(end).unwrap(), None));
move_to!(end);
Expand All @@ -441,7 +441,7 @@ pub mod printf {
}

if let WidthArg = state {
let end = at_next_cp_while(at, is_digit);
let end = at_next_cp_while(at, char::is_ascii_digit);
match end.next_cp() {
Some(('$', end2)) => {
state = Prec;
Expand Down Expand Up @@ -473,7 +473,7 @@ pub mod printf {
if let PrecInner = state {
match c {
'*' => {
let end = at_next_cp_while(next, is_digit);
let end = at_next_cp_while(next, char::is_ascii_digit);
match end.next_cp() {
Some(('$', end2)) => {
state = Length;
Expand All @@ -488,7 +488,7 @@ pub mod printf {
}
}
'0'..='9' => {
let end = at_next_cp_while(next, is_digit);
let end = at_next_cp_while(next, char::is_ascii_digit);
state = Length;
precision = Some(Num::from_str(at.slice_between(end).unwrap(), None));
move_to!(end);
Expand Down Expand Up @@ -563,12 +563,12 @@ pub mod printf {

fn at_next_cp_while<F>(mut cur: Cur<'_>, mut pred: F) -> Cur<'_>
where
F: FnMut(char) -> bool,
F: FnMut(&char) -> bool,
{
loop {
match cur.next_cp() {
Some((c, next)) => {
if pred(c) {
if pred(&c) {
cur = next;
} else {
return cur;
Expand All @@ -579,14 +579,7 @@ pub mod printf {
}
}

fn is_digit(c: char) -> bool {
match c {
'0'..='9' => true,
_ => false,
}
}

fn is_flag(c: char) -> bool {
fn is_flag(c: &char) -> bool {
match c {
'0' | '-' | '+' | ' ' | '#' | '\'' => true,
_ => false,
Expand Down Expand Up @@ -723,17 +716,11 @@ pub mod shell {
}

fn is_ident_head(c: char) -> bool {
match c {
'a'..='z' | 'A'..='Z' | '_' => true,
_ => false,
}
c.is_ascii_alphabetic() || c == '_'
}

fn is_ident_tail(c: char) -> bool {
match c {
'0'..='9' => true,
c => is_ident_head(c),
}
c.is_ascii_alphanumeric() || c == '_'
}

#[cfg(test)]
Expand Down

0 comments on commit 58542c2

Please sign in to comment.