use syntax::ast;
use syntax::codemap::{Span, BytePos};
use syntax_pos::Pos;
-use utils::{span_lint, snippet_opt};
+use utils::span_lint;
/// **What it does:** Checks for the presence of `_`, `::` or camel-case words
/// outside ticks in documentation.
/// `syntax::parse::lexer::comments::strip_doc_comment_decoration` because we need to keep track of
/// the spans but this function is inspired from the later.
#[allow(cast_possible_truncation)]
-pub fn strip_doc_comment_decoration(comment: String, span: Span) -> (String, Vec<(usize, Span)>) {
+pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(usize, Span)>) {
// one-line comments lose their prefix
const ONELINERS: &'static [&'static str] = &["///!", "///", "//!", "//"];
for prefix in ONELINERS {
let offset = line.as_ptr() as usize - comment.as_ptr() as usize;
debug_assert_eq!(offset as u32 as usize, offset);
- sizes.push((line.len(), Span { lo: span.lo + BytePos(offset as u32), ..span }));
+ // +1 for the newline
+ sizes.push((line.len()+1, Span { lo: span.lo + BytePos(offset as u32), ..span }));
}
return (doc.to_string(), sizes);
if attr.is_sugared_doc {
if let Some(ref current) = attr.value_str() {
let current = current.to_string();
- let (current, current_spans) = strip_doc_comment_decoration(current, attr.span);
+ let (current, current_spans) = strip_doc_comment_decoration(¤t, attr.span);
spans.extend_from_slice(¤t_spans);
doc.push_str(¤t);
}
let y_offset = y.0;
match (x.1, y.1) {
- (Text(x), Text(y)) => Ok((x_offset, Text((x.into_owned() + &y).into()))),
+ (Text(x), Text(y)) => {
+ let mut x = x.into_owned();
+ x.push_str(&y);
+ Ok((x_offset, Text(x.into())))
+ }
(x, y) => Err(((x_offset, x), (y_offset, y))),
}
});
let mut in_code = false;
- println!("{:?}", spans);
for (offset, event) in docs {
- println!("{:?}, {:?}", offset, event);
match event {
Start(CodeBlock(_)) | Start(Code) => in_code = true,
End(CodeBlock(_)) | End(Code) => in_code = false,
Start(_tag) | End(_tag) => (), // We don't care about other tags
Html(_html) | InlineHtml(_html) => (), // HTML is weird, just ignore it
- FootnoteReference(footnote) => (), // TODO
SoftBreak => (),
HardBreak => (),
- Text(text) => {
+ FootnoteReference(text) | Text(text) => {
if !in_code {
let index = match spans.binary_search_by(|c| c.0.cmp(&offset)) {
Ok(o) => o,
let (begin, span) = spans[index];
- println!("raw: {:?}, {}, {}, {:?}", snippet_opt(cx, span), offset, begin, span);
-
// Adjust for the begining of the current `Event`
let span = Span {
lo: span.lo + BytePos::from_usize(offset - begin),
..span
};
- println!("adjusted: {:?}", snippet_opt(cx, span));
check_text(cx, valid_idents, &text, span);
}
},
|
= note: `-D doc-markdown` implied by `-D warnings`
-error: you should put `is::a::global:path` between ticks in the documentation
- --> doc.rs:11:13
+error: you should put `a::global:path` between ticks in the documentation
+ --> doc.rs:11:15
|
-11 | /// Here be ::is::a::global:path.
- | ^^^^^^^^^^^^^^^^^^^^
+11 | /// Here be ::a::global:path.
+ | ^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
error: you should put `NotInCodeBlock` between ticks in the documentation
- --> doc.rs:12:21
+ --> doc.rs:12:22
|
12 | /// That's not code ~NotInCodeBlock~.
- | ^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
|
= note: `-D doc-markdown` implied by `-D warnings`
-error: you should put `ß_foo` between ticks in the documentation
- --> doc.rs:57:5
+error: you should put `link_with_underscores` between ticks in the documentation
+ --> doc.rs:52:22
|
-57 | /// ß_foo
- | ^^^^^
+52 | /// This test has [a link_with_underscores][chunked-example] inside it. See #823.
+ | ^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
-error: you should put `ℝ_foo` between ticks in the documentation
- --> doc.rs:58:5
+error: you should put `inline_link2` between ticks in the documentation
+ --> doc.rs:55:21
|
-58 | /// ℝ_foo
- | ^^^^^
+55 | /// It can also be [inline_link2].
+ | ^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
-error: you should put `foo_ß` between ticks in the documentation
- --> doc.rs:61:5
+error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
+ --> doc.rs:65:5
|
-61 | /// foo_ß
- | ^^^^^
+65 | /// be_sure_we_got_to_the_end_of_it
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
-error: you should put `foo_ℝ` between ticks in the documentation
- --> doc.rs:62:5
+error: you should put `CamelCaseThing` between ticks in the documentation
+ --> doc.rs:73:8
|
-62 | /// foo_ℝ
- | ^^^^^
+73 | /// ## CamelCaseThing
+ | ^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
-error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
- --> doc.rs:77:5
+error: you should put `CamelCaseThing` between ticks in the documentation
+ --> doc.rs:76:7
|
-77 | /// be_sure_we_got_to_the_end_of_it
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+76 | /// # CamelCaseThing
+ | ^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
-error: you should put `link_with_underscores` between ticks in the documentation
- --> doc.rs:81:22
+error: you should put `CamelCaseThing` between ticks in the documentation
+ --> doc.rs:78:22
|
-81 | /// This test has [a link_with_underscores][chunked-example] inside it. See #823.
- | ^^^^^^^^^^^^^^^^^^^^^
+78 | /// Not a title #897 CamelCaseThing
+ | ^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
-error: you should put `inline_link2` between ticks in the documentation
- --> doc.rs:84:21
+error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
+ --> doc.rs:79:5
|
-84 | /// It can also be [inline_link2].
- | ^^^^^^^^^^^^
+79 | /// be_sure_we_got_to_the_end_of_it
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
- --> doc.rs:94:5
+ --> doc.rs:86:5
|
-94 | /// be_sure_we_got_to_the_end_of_it
+86 | /// be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
-error: you should put `CamelCaseThing` between ticks in the documentation
- --> doc.rs:107:22
- |
-107 | /// Not a title #897 CamelCaseThing
- | ^^^^^^^^^^^^^^
- |
- = note: `-D doc-markdown` implied by `-D warnings`
-
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
- --> doc.rs:108:5
- |
-108 | /// be_sure_we_got_to_the_end_of_it
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `-D doc-markdown` implied by `-D warnings`
-
-error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
- --> doc.rs:115:5
- |
-115 | /// be_sure_we_got_to_the_end_of_it
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `-D doc-markdown` implied by `-D warnings`
-
-error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
- --> doc.rs:128:5
- |
-128 | /// be_sure_we_got_to_the_end_of_it
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `-D doc-markdown` implied by `-D warnings`
+ --> doc.rs:99:5
+ |
+99 | /// be_sure_we_got_to_the_end_of_it
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D doc-markdown` implied by `-D warnings`
error: you should put `FooBar` between ticks in the documentation
- --> doc.rs:139:42
+ --> doc.rs:110:42
|
-139 | /** E.g. serialization of an empty list: FooBar
+110 | /** E.g. serialization of an empty list: FooBar
| ^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
error: you should put `BarQuz` between ticks in the documentation
- --> doc.rs:144:5
+ --> doc.rs:115:5
|
-144 | And BarQuz too.
+115 | And BarQuz too.
| ^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
- --> doc.rs:145:1
+ --> doc.rs:116:1
|
-145 | be_sure_we_got_to_the_end_of_it
+116 | be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
error: you should put `FooBar` between ticks in the documentation
- --> doc.rs:150:42
+ --> doc.rs:121:42
|
-150 | /** E.g. serialization of an empty list: FooBar
+121 | /** E.g. serialization of an empty list: FooBar
| ^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
error: you should put `BarQuz` between ticks in the documentation
- --> doc.rs:155:5
+ --> doc.rs:126:5
|
-155 | And BarQuz too.
+126 | And BarQuz too.
| ^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
- --> doc.rs:156:1
+ --> doc.rs:127:1
|
-156 | be_sure_we_got_to_the_end_of_it
+127 | be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
- --> doc.rs:167:5
+ --> doc.rs:138:5
|
-167 | /// be_sure_we_got_to_the_end_of_it
+138 | /// be_sure_we_got_to_the_end_of_it
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D doc-markdown` implied by `-D warnings`