Skip to content

Commit f20a139

Browse files
committed
run rustfmt on syntax::parse::lexer
1 parent 4744472 commit f20a139

File tree

2 files changed

+764
-513
lines changed

2 files changed

+764
-513
lines changed

src/libsyntax/parse/lexer/comments.rs

Lines changed: 71 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ pub struct Comment {
4343
}
4444

4545
pub fn is_doc_comment(s: &str) -> bool {
46-
(s.starts_with("///") && super::is_doc_comment(s)) ||
47-
s.starts_with("//!") ||
48-
(s.starts_with("/**") && is_block_doc_comment(s)) ||
49-
s.starts_with("/*!")
46+
(s.starts_with("///") && super::is_doc_comment(s)) || s.starts_with("//!") ||
47+
(s.starts_with("/**") && is_block_doc_comment(s)) || s.starts_with("/*!")
5048
}
5149

5250
pub fn doc_comment_style(comment: &str) -> ast::AttrStyle {
@@ -64,18 +62,18 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
6462
let mut i = 0;
6563
let mut j = lines.len();
6664
// first line of all-stars should be omitted
67-
if !lines.is_empty() &&
68-
lines[0].chars().all(|c| c == '*') {
65+
if !lines.is_empty() && lines[0].chars().all(|c| c == '*') {
6966
i += 1;
7067
}
7168
while i < j && lines[i].trim().is_empty() {
7269
i += 1;
7370
}
7471
// like the first, a last line of all stars should be omitted
75-
if j > i && lines[j - 1]
76-
.chars()
77-
.skip(1)
78-
.all(|c| c == '*') {
72+
if j > i &&
73+
lines[j - 1]
74+
.chars()
75+
.skip(1)
76+
.all(|c| c == '*') {
7977
j -= 1;
8078
}
8179
while j > i && lines[j - 1].trim().is_empty() {
@@ -85,7 +83,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
8583
}
8684

8785
/// remove a "[ \t]*\*" block from each line, if possible
88-
fn horizontal_trim(lines: Vec<String> ) -> Vec<String> {
86+
fn horizontal_trim(lines: Vec<String>) -> Vec<String> {
8987
let mut i = usize::MAX;
9088
let mut can_trim = true;
9189
let mut first = true;
@@ -114,9 +112,9 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
114112
}
115113

116114
if can_trim {
117-
lines.iter().map(|line| {
118-
(&line[i + 1..line.len()]).to_string()
119-
}).collect()
115+
lines.iter()
116+
.map(|line| (&line[i + 1..line.len()]).to_string())
117+
.collect()
120118
} else {
121119
lines
122120
}
@@ -132,9 +130,9 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
132130

133131
if comment.starts_with("/*") {
134132
let lines = comment[3..comment.len() - 2]
135-
.lines()
136-
.map(|s| s.to_string())
137-
.collect::<Vec<String> >();
133+
.lines()
134+
.map(|s| s.to_string())
135+
.collect::<Vec<String>>();
138136

139137
let lines = vertical_trim(lines);
140138
let lines = horizontal_trim(lines);
@@ -154,8 +152,7 @@ fn push_blank_line_comment(rdr: &StringReader, comments: &mut Vec<Comment>) {
154152
});
155153
}
156154

157-
fn consume_whitespace_counting_blank_lines(rdr: &mut StringReader,
158-
comments: &mut Vec<Comment>) {
155+
fn consume_whitespace_counting_blank_lines(rdr: &mut StringReader, comments: &mut Vec<Comment>) {
159156
while is_whitespace(rdr.curr) && !rdr.is_eof() {
160157
if rdr.col == CharPos(0) && rdr.curr_is('\n') {
161158
push_blank_line_comment(rdr, &mut *comments);
@@ -165,19 +162,25 @@ fn consume_whitespace_counting_blank_lines(rdr: &mut StringReader,
165162
}
166163

167164

168-
fn read_shebang_comment(rdr: &mut StringReader, code_to_the_left: bool,
165+
fn read_shebang_comment(rdr: &mut StringReader,
166+
code_to_the_left: bool,
169167
comments: &mut Vec<Comment>) {
170168
debug!(">>> shebang comment");
171169
let p = rdr.last_pos;
172170
debug!("<<< shebang comment");
173171
comments.push(Comment {
174-
style: if code_to_the_left { Trailing } else { Isolated },
175-
lines: vec!(rdr.read_one_line_comment()),
176-
pos: p
172+
style: if code_to_the_left {
173+
Trailing
174+
} else {
175+
Isolated
176+
},
177+
lines: vec![rdr.read_one_line_comment()],
178+
pos: p,
177179
});
178180
}
179181

180-
fn read_line_comments(rdr: &mut StringReader, code_to_the_left: bool,
182+
fn read_line_comments(rdr: &mut StringReader,
183+
code_to_the_left: bool,
181184
comments: &mut Vec<Comment>) {
182185
debug!(">>> line comments");
183186
let p = rdr.last_pos;
@@ -195,9 +198,13 @@ fn read_line_comments(rdr: &mut StringReader, code_to_the_left: bool,
195198
debug!("<<< line comments");
196199
if !lines.is_empty() {
197200
comments.push(Comment {
198-
style: if code_to_the_left { Trailing } else { Isolated },
201+
style: if code_to_the_left {
202+
Trailing
203+
} else {
204+
Isolated
205+
},
199206
lines: lines,
200-
pos: p
207+
pos: p,
201208
});
202209
}
203210
}
@@ -220,8 +227,7 @@ fn all_whitespace(s: &str, col: CharPos) -> Option<usize> {
220227
return Some(cursor);
221228
}
222229

223-
fn trim_whitespace_prefix_and_push_line(lines: &mut Vec<String> ,
224-
s: String, col: CharPos) {
230+
fn trim_whitespace_prefix_and_push_line(lines: &mut Vec<String>, s: String, col: CharPos) {
225231
let len = s.len();
226232
let s1 = match all_whitespace(&s[..], col) {
227233
Some(col) => {
@@ -239,7 +245,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut Vec<String> ,
239245

240246
fn read_block_comment(rdr: &mut StringReader,
241247
code_to_the_left: bool,
242-
comments: &mut Vec<Comment> ) {
248+
comments: &mut Vec<Comment>) {
243249
debug!(">>> block comment");
244250
let p = rdr.last_pos;
245251
let mut lines: Vec<String> = Vec::new();
@@ -261,7 +267,7 @@ fn read_block_comment(rdr: &mut StringReader,
261267
rdr.bump();
262268
}
263269
if is_block_doc_comment(&curr_line[..]) {
264-
return
270+
return;
265271
}
266272
assert!(!curr_line.contains('\n'));
267273
lines.push(curr_line);
@@ -273,9 +279,7 @@ fn read_block_comment(rdr: &mut StringReader,
273279
panic!(rdr.fatal("unterminated block comment"));
274280
}
275281
if rdr.curr_is('\n') {
276-
trim_whitespace_prefix_and_push_line(&mut lines,
277-
curr_line,
278-
col);
282+
trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col);
279283
curr_line = String::new();
280284
rdr.bump();
281285
} else {
@@ -291,38 +295,46 @@ fn read_block_comment(rdr: &mut StringReader,
291295
rdr.bump();
292296
curr_line.push('/');
293297
level -= 1;
294-
} else { rdr.bump(); }
298+
} else {
299+
rdr.bump();
300+
}
295301
}
296302
}
297303
}
298304
if !curr_line.is_empty() {
299-
trim_whitespace_prefix_and_push_line(&mut lines,
300-
curr_line,
301-
col);
305+
trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col);
302306
}
303307
}
304308

305-
let mut style = if code_to_the_left { Trailing } else { Isolated };
309+
let mut style = if code_to_the_left {
310+
Trailing
311+
} else {
312+
Isolated
313+
};
306314
rdr.consume_non_eol_whitespace();
307315
if !rdr.is_eof() && !rdr.curr_is('\n') && lines.len() == 1 {
308316
style = Mixed;
309317
}
310318
debug!("<<< block comment");
311-
comments.push(Comment {style: style, lines: lines, pos: p});
319+
comments.push(Comment {
320+
style: style,
321+
lines: lines,
322+
pos: p,
323+
});
312324
}
313325

314326

315-
fn consume_comment(rdr: &mut StringReader,
316-
code_to_the_left: bool,
317-
comments: &mut Vec<Comment> ) {
327+
fn consume_comment(rdr: &mut StringReader, code_to_the_left: bool, comments: &mut Vec<Comment>) {
318328
debug!(">>> consume comment");
319329
if rdr.curr_is('/') && rdr.nextch_is('/') {
320330
read_line_comments(rdr, code_to_the_left, comments);
321331
} else if rdr.curr_is('/') && rdr.nextch_is('*') {
322332
read_block_comment(rdr, code_to_the_left, comments);
323333
} else if rdr.curr_is('#') && rdr.nextch_is('!') {
324334
read_shebang_comment(rdr, code_to_the_left, comments);
325-
} else { panic!(); }
335+
} else {
336+
panic!();
337+
}
326338
debug!("<<< consume comment");
327339
}
328340

@@ -337,7 +349,7 @@ pub struct Literal {
337349
pub fn gather_comments_and_literals(span_diagnostic: &errors::Handler,
338350
path: String,
339351
srdr: &mut Read)
340-
-> (Vec<Comment>, Vec<Literal>) {
352+
-> (Vec<Comment>, Vec<Literal>) {
341353
let mut src = Vec::new();
342354
srdr.read_to_end(&mut src).unwrap();
343355
let src = String::from_utf8(src).unwrap();
@@ -366,12 +378,15 @@ pub fn gather_comments_and_literals(span_diagnostic: &errors::Handler,
366378

367379
let bstart = rdr.last_pos;
368380
rdr.next_token();
369-
//discard, and look ahead; we're working with internal state
381+
// discard, and look ahead; we're working with internal state
370382
let TokenAndSpan { tok, sp } = rdr.peek();
371383
if tok.is_lit() {
372384
rdr.with_str_from(bstart, |s| {
373385
debug!("tok lit: {}", s);
374-
literals.push(Literal {lit: s.to_string(), pos: sp.lo});
386+
literals.push(Literal {
387+
lit: s.to_string(),
388+
pos: sp.lo,
389+
});
375390
})
376391
} else {
377392
debug!("tok: {}", pprust::token_to_string(&tok));
@@ -386,31 +401,36 @@ pub fn gather_comments_and_literals(span_diagnostic: &errors::Handler,
386401
mod tests {
387402
use super::*;
388403

389-
#[test] fn test_block_doc_comment_1() {
404+
#[test]
405+
fn test_block_doc_comment_1() {
390406
let comment = "/**\n * Test \n ** Test\n * Test\n*/";
391407
let stripped = strip_doc_comment_decoration(comment);
392408
assert_eq!(stripped, " Test \n* Test\n Test");
393409
}
394410

395-
#[test] fn test_block_doc_comment_2() {
411+
#[test]
412+
fn test_block_doc_comment_2() {
396413
let comment = "/**\n * Test\n * Test\n*/";
397414
let stripped = strip_doc_comment_decoration(comment);
398415
assert_eq!(stripped, " Test\n Test");
399416
}
400417

401-
#[test] fn test_block_doc_comment_3() {
418+
#[test]
419+
fn test_block_doc_comment_3() {
402420
let comment = "/**\n let a: *i32;\n *a = 5;\n*/";
403421
let stripped = strip_doc_comment_decoration(comment);
404422
assert_eq!(stripped, " let a: *i32;\n *a = 5;");
405423
}
406424

407-
#[test] fn test_block_doc_comment_4() {
425+
#[test]
426+
fn test_block_doc_comment_4() {
408427
let comment = "/*******************\n test\n *********************/";
409428
let stripped = strip_doc_comment_decoration(comment);
410429
assert_eq!(stripped, " test");
411430
}
412431

413-
#[test] fn test_line_doc_comment() {
432+
#[test]
433+
fn test_line_doc_comment() {
414434
let stripped = strip_doc_comment_decoration("/// test");
415435
assert_eq!(stripped, " test");
416436
let stripped = strip_doc_comment_decoration("///! test");

0 commit comments

Comments
 (0)