]> git.lizzy.rs Git - rust.git/commitdiff
Fix spans in all cases in `doc_markdown`
authormcarton <cartonmartin+git@gmail.com>
Tue, 30 May 2017 17:28:44 +0000 (19:28 +0200)
committermcarton <cartonmartin+git@gmail.com>
Sat, 17 Jun 2017 16:23:37 +0000 (18:23 +0200)
clippy_lints/src/doc.rs
clippy_tests/examples/doc.stderr

index ed6b3a978a6f8fb937b895c037e9c1e1184707a6..ff502819ffc5fed39ce4972b8d109a74069af00a 100644 (file)
@@ -4,7 +4,7 @@
 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.
@@ -81,7 +81,7 @@ fn next(&mut self) -> Option<Self::Item> {
 /// `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 {
@@ -104,7 +104,8 @@ pub fn strip_doc_comment_decoration(comment: String, span: Span) -> (String, Vec
             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);
@@ -121,7 +122,7 @@ pub fn check_attrs<'a>(cx: &EarlyContext, valid_idents: &[String], attrs: &'a [a
         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(&current, attr.span);
                 spans.extend_from_slice(&current_spans);
                 doc.push_str(&current);
             }
@@ -144,7 +145,11 @@ pub fn check_attrs<'a>(cx: &EarlyContext, valid_idents: &[String], attrs: &'a [a
             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))),
             }
         });
@@ -163,18 +168,15 @@ fn check_doc<'a, Events: Iterator<Item=(usize, pulldown_cmark::Event<'a>)>>(
 
     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,
@@ -183,15 +185,12 @@ fn check_doc<'a, Events: Iterator<Item=(usize, pulldown_cmark::Event<'a>)>>(
 
                     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);
                 }
             },
index 669c0946b56aaae9825283b89552d8f69957abad..7e23de55da1e70f39dfb24619d2f94b62a241be4 100644 (file)
@@ -30,19 +30,19 @@ error: you should put `Foo::some_fun` between ticks in the documentation
   |
   = 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`
 
@@ -78,154 +78,130 @@ error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the doc
    |
    = 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`