Skip to content

Commit

Permalink
review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jan 26, 2018
1 parent d0bd090 commit fa7767e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,18 +598,16 @@ impl CodeMap {
/// If `sp` points to `"let mut x"`, then a span pointing at `"let "` will be returned.
pub fn span_until_non_whitespace(&self, sp: Span) -> Span {
if let Ok(snippet) = self.span_to_snippet(sp) {
let mut offset = 0;
let mut pos = 0;
let mut offset = 1;
// get the bytes width of all the non-whitespace characters
for (i, c) in snippet.chars().take_while(|c| !c.is_whitespace()).enumerate() {
for c in snippet.chars().take_while(|c| !c.is_whitespace()) {
offset += c.len_utf8();
pos = i + 1;
}
// get the bytes width of all the whitespace characters after that
for c in snippet[pos..].chars().take_while(|c| c.is_whitespace()) {
for c in snippet[offset..].chars().take_while(|c| c.is_whitespace()) {
offset += c.len_utf8();
}
if offset != 0 {
if offset > 1 {
return sp.with_hi(BytePos(sp.lo().0 + offset as u32));
}
}
Expand Down

0 comments on commit fa7767e

Please sign in to comment.