diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2016-09-12 13:03:21 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2016-09-12 16:15:52 +1000 |
| commit | 4c274b6aea00c2327211e8295f4d97ee6e624a2b (patch) | |
| tree | a75df25da6b130d26a2fa1b163f45e5da666dcfc /src/libsyntax/parse | |
| parent | ea45edf0ee39fd7f25e0ba7258023c81b53b3a0d (diff) | |
| download | rust-4c274b6aea00c2327211e8295f4d97ee6e624a2b.tar.gz rust-4c274b6aea00c2327211e8295f4d97ee6e624a2b.zip | |
Avoid an unnecessary intermediate value in char_lit().
This makes the function more concise and easier to understand.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index af95e44a567..31fa2cda5db 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -287,26 +287,21 @@ pub fn char_lit(lit: &str) -> (char, isize) { use std::char; let mut chars = lit.chars(); - let c = match (chars.next(), chars.next()) { + match (chars.next(), chars.next()) { (Some(c), None) if c != '\\' => return (c, 1), (Some('\\'), Some(c)) => match c { - '"' => Some('"'), - 'n' => Some('\n'), - 'r' => Some('\r'), - 't' => Some('\t'), - '\\' => Some('\\'), - '\'' => Some('\''), - '0' => Some('\0'), - _ => { None } + '"' => return ('"', 2), + 'n' => return ('\n', 2), + 'r' => return ('\r', 2), + 't' => return ('\t', 2), + '\\' => return ('\\', 2), + '\'' => return ('\'', 2), + '0' => return ('\0', 2), + _ => {} }, _ => panic!("lexer accepted invalid char escape `{}`", lit) }; - match c { - Some(x) => return (x, 2), - None => { } - } - let msg = format!("lexer should have rejected a bad character escape {}", lit); let msg2 = &msg[..]; |
