Skip to content

Commit 8a27230

Browse files
committed
libsyntax: use char::is_whitespace instead of custom implementations
Fixes rust-lang#29590.
1 parent c12c42d commit 8a27230

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/libsyntax/parse/lexer/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1592,10 +1592,7 @@ impl<'a> StringReader<'a> {
15921592
}
15931593

15941594
pub fn is_whitespace(c: Option<char>) -> bool {
1595-
match c.unwrap_or('\x00') { // None can be null for now... it's not whitespace
1596-
' ' | '\n' | '\t' | '\r' => true,
1597-
_ => false,
1598-
}
1595+
c.map_or(false, char::is_whitespace)
15991596
}
16001597

16011598
fn in_range(c: Option<char>, lo: char, hi: char) -> bool {

src/libsyntax/util/parser_testing.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,8 @@ fn scan_for_non_ws_or_end(a : &str, idx: usize) -> usize {
140140
i
141141
}
142142

143-
/// Copied from lexer.
144143
pub fn is_whitespace(c: char) -> bool {
145-
return c == ' ' || c == '\t' || c == '\r' || c == '\n';
144+
c.is_whitespace()
146145
}
147146

148147
#[cfg(test)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
// Beware editing: it has numerous whitespace characters which are important
13+
pub fn main() {
14+
assert_eq!(4 +  7 * 2
15+
16+
17+
/ 3*2, 4 + 7 * 2 / 3 * 2);
18+
}

0 commit comments

Comments
 (0)