Skip to content

Commit 86a427f

Browse files
committed
Check whether '\\'' is char literal or lifetime
1 parent 9905c56 commit 86a427f

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ cargo-fmt = []
3535
rustfmt-format-diff = []
3636

3737
[dependencies]
38+
itertools = "0.7"
3839
toml = "0.4"
3940
serde = "1.0"
4041
serde_derive = "1.0"

src/comment.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use std::{self, iter, borrow::Cow};
1414

15+
use itertools::{multipeek, MultiPeek};
1516
use syntax::codemap::Span;
1617

1718
use config::Config;
@@ -684,7 +685,7 @@ where
684685
T: Iterator,
685686
T::Item: RichChar,
686687
{
687-
base: iter::Peekable<T>,
688+
base: MultiPeek<T>,
688689
status: CharClassesStatus,
689690
}
690691

@@ -776,7 +777,7 @@ where
776777
{
777778
pub fn new(base: T) -> CharClasses<T> {
778779
CharClasses {
779-
base: base.peekable(),
780+
base: multipeek(base),
780781
status: CharClassesStatus::Normal,
781782
}
782783
}
@@ -820,7 +821,21 @@ where
820821
char_kind = FullCodeCharKind::InString;
821822
CharClassesStatus::LitString
822823
}
823-
'\'' => CharClassesStatus::LitChar,
824+
'\'' => {
825+
// HACK: Work around mut borrow.
826+
match self.base.peek() {
827+
Some(next) if next.get_char() == '\\' => {
828+
self.status = CharClassesStatus::LitChar;
829+
return Some((char_kind, item));
830+
}
831+
_ => (),
832+
}
833+
834+
match self.base.peek() {
835+
Some(next) if next.get_char() == '\'' => CharClassesStatus::LitChar,
836+
_ => CharClassesStatus::Normal,
837+
}
838+
}
824839
'/' => match self.base.peek() {
825840
Some(next) if next.get_char() == '*' => {
826841
self.status = CharClassesStatus::BlockCommentOpening(1);

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#[macro_use]
1717
extern crate derive_new;
1818
extern crate diff;
19+
extern crate itertools;
1920
#[macro_use]
2021
extern crate log;
2122
extern crate regex;

0 commit comments

Comments
 (0)