@@ -1422,8 +1422,10 @@ impl<'a> Iterator for LineClasses<'a> {
1422
1422
None => unreachable ! ( ) ,
1423
1423
} ;
1424
1424
1425
+ let mut prev_kind = FullCodeCharKind :: Normal ;
1425
1426
while let Some ( ( kind, c) ) = self . base . next ( ) {
1426
1427
// needed to set the kind of the ending character on the last line
1428
+ prev_kind = self . kind ;
1427
1429
self . kind = kind;
1428
1430
if c == '\n' {
1429
1431
self . kind = match ( start_kind, kind) {
@@ -1439,6 +1441,9 @@ impl<'a> Iterator for LineClasses<'a> {
1439
1441
( FullCodeCharKind :: InStringCommented , FullCodeCharKind :: InComment ) => {
1440
1442
FullCodeCharKind :: EndStringCommented
1441
1443
}
1444
+ ( _, FullCodeCharKind :: Normal ) if prev_kind == FullCodeCharKind :: EndComment => {
1445
+ FullCodeCharKind :: EndComment
1446
+ }
1442
1447
_ => kind,
1443
1448
} ;
1444
1449
break ;
@@ -1993,12 +1998,28 @@ fn main() {
1993
1998
}
1994
1999
"# ;
1995
2000
assert_eq ! ( s, filter_normal_code( s) ) ;
1996
- let s_with_comment = r#"
2001
+ let s_with_line_comment = r#"
1997
2002
fn main() {
1998
2003
// hello, world
1999
2004
println!("hello, world");
2000
2005
}
2001
2006
"# ;
2002
- assert_eq ! ( s, filter_normal_code( s_with_comment) ) ;
2007
+ assert_eq ! ( s, filter_normal_code( s_with_line_comment) ) ;
2008
+ let s_with_block_comment = r#"
2009
+ fn main() {
2010
+ /* hello, world */
2011
+ println!("hello, world");
2012
+ }
2013
+ "# ;
2014
+ assert_eq ! ( s, filter_normal_code( s_with_block_comment) ) ;
2015
+ let s_with_multi_line_comment = r#"
2016
+ fn main() {
2017
+ /* hello,
2018
+ * world
2019
+ */
2020
+ println!("hello, world");
2021
+ }
2022
+ "# ;
2023
+ assert_eq ! ( s, filter_normal_code( s_with_multi_line_comment) ) ;
2003
2024
}
2004
2025
}
0 commit comments