]> git.lizzy.rs Git - rust.git/blobdiff - src/comment.rs
Cargo clippy
[rust.git] / src / comment.rs
index 5903323f2f47c2df561089a24e0a9f8a86f9fa27..439a7f6a05f32c1cfea3d19c4f117f89fbb8c575 100644 (file)
@@ -332,7 +332,11 @@ fn rewrite_comment_inner(
             inside_code_block = !inside_code_block;
         }
         if inside_code_block {
-            result.push_str(line);
+            if line.is_empty() && result.ends_with(' ') {
+                result.pop();
+            } else {
+                result.push_str(line);
+            }
             continue;
         }
 
@@ -581,7 +585,7 @@ pub fn remove_trailing_white_spaces(text: &str) -> String {
     buffer
 }
 
-struct CharClasses<T>
+pub struct CharClasses<T>
 where
     T: Iterator,
     T::Item: RichChar,
@@ -590,7 +594,7 @@ struct CharClasses<T>
     status: CharClassesStatus,
 }
 
-trait RichChar {
+pub trait RichChar {
     fn get_char(&self) -> char;
 }
 
@@ -606,6 +610,12 @@ fn get_char(&self) -> char {
     }
 }
 
+impl RichChar for (char, usize) {
+    fn get_char(&self) -> char {
+        self.0
+    }
+}
+
 #[derive(PartialEq, Eq, Debug, Clone, Copy)]
 enum CharClassesStatus {
     Normal,
@@ -635,7 +645,7 @@ pub enum CodeCharKind {
 /// describing opening and closing of comments for ease when chunking
 /// code from tagged characters
 #[derive(PartialEq, Eq, Debug, Clone, Copy)]
-enum FullCodeCharKind {
+pub enum FullCodeCharKind {
     Normal,
     /// The first character of a comment, there is only one for a comment (always '/')
     StartComment,
@@ -649,7 +659,7 @@ enum FullCodeCharKind {
 }
 
 impl FullCodeCharKind {
-    fn is_comment(&self) -> bool {
+    pub fn is_comment(&self) -> bool {
         match *self {
             FullCodeCharKind::StartComment
             | FullCodeCharKind::InComment
@@ -658,6 +668,10 @@ fn is_comment(&self) -> bool {
         }
     }
 
+    pub fn is_string(&self) -> bool {
+        *self == FullCodeCharKind::InString
+    }
+
     fn to_codecharkind(&self) -> CodeCharKind {
         if self.is_comment() {
             CodeCharKind::Comment
@@ -672,7 +686,7 @@ impl<T> CharClasses<T>
     T: Iterator,
     T::Item: RichChar,
 {
-    fn new(base: T) -> CharClasses<T> {
+    pub fn new(base: T) -> CharClasses<T> {
         CharClasses {
             base: base.peekable(),
             status: CharClassesStatus::Normal,
@@ -916,9 +930,9 @@ pub fn recover_comment_removed(
     context: &RewriteContext,
 ) -> Option<String> {
     let snippet = context.snippet(span);
-    if snippet != new && changed_comment_content(&snippet, &new) {
+    if snippet != new && changed_comment_content(snippet, &new) {
         // We missed some comments. Keep the original text.
-        Some(snippet)
+        Some(snippet.to_owned())
     } else {
         Some(new)
     }