Skip to content

Commit a7eabec

Browse files
committed
Add some comments for magic numbers + Add tests
1 parent 6b25c50 commit a7eabec

File tree

5 files changed

+84
-1
lines changed

5 files changed

+84
-1
lines changed

src/librustc_parse/lexer/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ impl<'a> StringReader<'a> {
172172
let string = self.str_from(start);
173173
if let Some(attr_style) = comments::line_doc_comment_style(string) {
174174
self.forbid_bare_cr(start, string, "bare CR not allowed in doc-comment");
175+
// Opening delimiter of the length 3 is not included into the symbol.
175176
token::DocComment(CommentKind::Line, attr_style, Symbol::intern(&string[3..]))
176177
} else {
177178
token::Comment
@@ -201,6 +202,8 @@ impl<'a> StringReader<'a> {
201202

202203
if let Some(attr_style) = attr_style {
203204
self.forbid_bare_cr(start, string, "bare CR not allowed in block doc-comment");
205+
// Opening delimiter of the length 3 and closing delimiter of the length 2
206+
// are not included into the symbol.
204207
token::DocComment(
205208
CommentKind::Block,
206209
attr_style,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
// aux-build:test-macros.rs
3+
4+
// Anonymize unstable non-dummy spans while still showing dummy spans `0..0`.
5+
// normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)"
6+
// normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)"
7+
8+
#[macro_use]
9+
extern crate test_macros;
10+
11+
print_bang! {
12+
13+
/**
14+
*******
15+
* DOC *
16+
* DOC *
17+
* DOC *
18+
*******
19+
*/
20+
pub struct S;
21+
22+
}
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
PRINT-BANG INPUT (DISPLAY): /**
2+
*******
3+
* DOC *
4+
* DOC *
5+
* DOC *
6+
*******
7+
*/
8+
pub struct S ;
9+
PRINT-BANG RE-COLLECTED (DISPLAY): #[doc = "\n*******\n* DOC *\n* DOC *\n* DOC *\n*******\n"] pub struct S ;
10+
PRINT-BANG INPUT (DEBUG): TokenStream [
11+
Punct {
12+
ch: '#',
13+
spacing: Alone,
14+
span: #0 bytes(LO..HI),
15+
},
16+
Group {
17+
delimiter: Bracket,
18+
stream: TokenStream [
19+
Ident {
20+
ident: "doc",
21+
span: #0 bytes(LO..HI),
22+
},
23+
Punct {
24+
ch: '=',
25+
spacing: Alone,
26+
span: #0 bytes(LO..HI),
27+
},
28+
Literal {
29+
kind: Str,
30+
symbol: "\n*******\n* DOC *\n* DOC *\n* DOC *\n*******\n",
31+
suffix: None,
32+
span: #0 bytes(LO..HI),
33+
},
34+
],
35+
span: #0 bytes(LO..HI),
36+
},
37+
Ident {
38+
ident: "pub",
39+
span: #0 bytes(LO..HI),
40+
},
41+
Ident {
42+
ident: "struct",
43+
span: #0 bytes(LO..HI),
44+
},
45+
Ident {
46+
ident: "S",
47+
span: #0 bytes(LO..HI),
48+
},
49+
Punct {
50+
ch: ';',
51+
spacing: Alone,
52+
span: #0 bytes(LO..HI),
53+
},
54+
]

src/tools/clippy/clippy_lints/src/doc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span:
264264
let mut doc = doc.to_owned();
265265
doc.push('\n');
266266
let len = doc.len();
267+
// +3 skips the opening delimiter
267268
return (doc, vec![(len, span.with_lo(span.lo() + BytePos(3)))]);
268269
}
269270

@@ -273,7 +274,7 @@ pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span:
273274
let offset = line.as_ptr() as usize - doc.as_ptr() as usize;
274275
debug_assert_eq!(offset as u32 as usize, offset);
275276
contains_initial_stars |= line.trim_start().starts_with('*');
276-
// +1 for the newline
277+
// +1 adds the newline, +3 skips the opening delimiter
277278
sizes.push((line.len() + 1, span.with_lo(span.lo() + BytePos(3 + offset as u32))));
278279
}
279280
if !contains_initial_stars {

src/tools/clippy/clippy_lints/src/tabs_in_doc_comments.rs

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ impl TabsInDocComments {
6464
let comment = comment.as_str();
6565

6666
for (lo, hi) in get_chunks_of_tabs(&comment) {
67+
// +3 skips the opening delimiter
6768
let new_span = Span::new(
6869
attr.span.lo() + BytePos(3 + lo),
6970
attr.span.lo() + BytePos(3 + hi),

0 commit comments

Comments
 (0)