Skip to content

Commit bcaeab7

Browse files
authored
Merge pull request #2527 from topecongiro/issue-2526
Check whether '\\'' is char literal or lifetime
2 parents af5d3cc + 86a427f commit bcaeab7

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-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
@@ -32,6 +32,7 @@ cargo-fmt = []
3232
rustfmt-format-diff = []
3333

3434
[dependencies]
35+
itertools = "0.7"
3536
toml = "0.4"
3637
serde = "1.0"
3738
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;
@@ -693,7 +694,7 @@ where
693694
T: Iterator,
694695
T::Item: RichChar,
695696
{
696-
base: iter::Peekable<T>,
697+
base: MultiPeek<T>,
697698
status: CharClassesStatus,
698699
}
699700

@@ -785,7 +786,7 @@ where
785786
{
786787
pub fn new(base: T) -> CharClasses<T> {
787788
CharClasses {
788-
base: base.peekable(),
789+
base: multipeek(base),
789790
status: CharClassesStatus::Normal,
790791
}
791792
}
@@ -829,7 +830,21 @@ where
829830
char_kind = FullCodeCharKind::InString;
830831
CharClassesStatus::LitString
831832
}
832-
'\'' => CharClassesStatus::LitChar,
833+
'\'' => {
834+
// HACK: Work around mut borrow.
835+
match self.base.peek() {
836+
Some(next) if next.get_char() == '\\' => {
837+
self.status = CharClassesStatus::LitChar;
838+
return Some((char_kind, item));
839+
}
840+
_ => (),
841+
}
842+
843+
match self.base.peek() {
844+
Some(next) if next.get_char() == '\'' => CharClassesStatus::LitChar,
845+
_ => CharClassesStatus::Normal,
846+
}
847+
}
833848
'/' => match self.base.peek() {
834849
Some(next) if next.get_char() == '*' => {
835850
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;

tests/target/issue-2526.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Test that rustfmt will not warn about comments exceeding max width around lifetime.
2+
// See #2526.
3+
4+
// comment comment comment comment comment comment comment comment comment comment comment comment comment
5+
fn foo() -> F<'a> {
6+
bar()
7+
}
8+
// comment comment comment comment comment comment comment comment comment comment comment comment comment

0 commit comments

Comments
 (0)