Skip to content

Check whether '\\'' is char literal or lifetime #2527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ cargo-fmt = []
rustfmt-format-diff = []

[dependencies]
itertools = "0.7"
toml = "0.4"
serde = "1.0"
serde_derive = "1.0"
Expand Down
21 changes: 18 additions & 3 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

use itertools::{multipeek, MultiPeek};
use syntax::codemap::Span;

use config::Config;
Expand Down Expand Up @@ -684,7 +685,7 @@ where
T: Iterator,
T::Item: RichChar,
{
base: iter::Peekable<T>,
base: MultiPeek<T>,
status: CharClassesStatus,
}

Expand Down Expand Up @@ -776,7 +777,7 @@ where
{
pub fn new(base: T) -> CharClasses<T> {
CharClasses {
base: base.peekable(),
base: multipeek(base),
status: CharClassesStatus::Normal,
}
}
Expand Down Expand Up @@ -820,7 +821,21 @@ where
char_kind = FullCodeCharKind::InString;
CharClassesStatus::LitString
}
'\'' => CharClassesStatus::LitChar,
'\'' => {
// HACK: Work around mut borrow.
match self.base.peek() {
Some(next) if next.get_char() == '\\' => {
self.status = CharClassesStatus::LitChar;
return Some((char_kind, item));
}
_ => (),
}

match self.base.peek() {
Some(next) if next.get_char() == '\'' => CharClassesStatus::LitChar,
_ => CharClassesStatus::Normal,
}
}
'/' => match self.base.peek() {
Some(next) if next.get_char() == '*' => {
self.status = CharClassesStatus::BlockCommentOpening(1);
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#[macro_use]
extern crate derive_new;
extern crate diff;
extern crate itertools;
#[macro_use]
extern crate log;
extern crate regex;
Expand Down
8 changes: 8 additions & 0 deletions tests/target/issue-2526.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Test that rustfmt will not warn about comments exceeding max width around lifetime.
// See #2526.

// comment comment comment comment comment comment comment comment comment comment comment comment comment
fn foo() -> F<'a> {
bar()
}
// comment comment comment comment comment comment comment comment comment comment comment comment comment