From a285b5836883affe23e3d160013aaee0e74bd981 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 5 Aug 2020 00:26:23 +0300 Subject: [PATCH] Add some comments for magic numbers + Add tests --- clippy_lints/src/doc.rs | 3 ++- clippy_lints/src/tabs_in_doc_comments.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 94371b7d2..6ce36fd23 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -264,6 +264,7 @@ pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span: let mut doc = doc.to_owned(); doc.push('\n'); let len = doc.len(); + // +3 skips the opening delimiter return (doc, vec![(len, span.with_lo(span.lo() + BytePos(3)))]); } @@ -273,7 +274,7 @@ pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span: let offset = line.as_ptr() as usize - doc.as_ptr() as usize; debug_assert_eq!(offset as u32 as usize, offset); contains_initial_stars |= line.trim_start().starts_with('*'); - // +1 for the newline + // +1 adds the newline, +3 skips the opening delimiter sizes.push((line.len() + 1, span.with_lo(span.lo() + BytePos(3 + offset as u32)))); } if !contains_initial_stars { diff --git a/clippy_lints/src/tabs_in_doc_comments.rs b/clippy_lints/src/tabs_in_doc_comments.rs index d00114eed..74ccd9235 100644 --- a/clippy_lints/src/tabs_in_doc_comments.rs +++ b/clippy_lints/src/tabs_in_doc_comments.rs @@ -64,6 +64,7 @@ impl TabsInDocComments { let comment = comment.as_str(); for (lo, hi) in get_chunks_of_tabs(&comment) { + // +3 skips the opening delimiter let new_span = Span::new( attr.span.lo() + BytePos(3 + lo), attr.span.lo() + BytePos(3 + hi),