From e14e1a7148375499731f9549eadf5172050fd99a Mon Sep 17 00:00:00 2001 From: mcarton Date: Thu, 5 May 2016 21:32:48 +0200 Subject: [PATCH 1/3] Fix issue with `DOC_MARKDOWN` and punctuation --- src/doc.rs | 7 ++++--- tests/compile-fail/doc.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/doc.rs b/src/doc.rs index 6212a025c256..00c3e4398ea3 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -133,9 +133,6 @@ pub fn check_doc(cx: &EarlyContext, valid_idents: &[String], doc: &str, span: Sp match chars.next() { Some((_, c)) => { match c { - c if c.is_whitespace() => { - current_word_begin = jump_to!(@next_char, chars, len); - } '`' => { current_word_begin = jump_to!(chars, '`', len); } @@ -171,6 +168,10 @@ pub fn check_doc(cx: &EarlyContext, valid_idents: &[String], doc: &str, span: Sp None => return, } } + // anything that’s neither alphanumeric nor '_' is not part of an ident anyway + c if !c.is_alphanumeric() && c != '_' => { + current_word_begin = jump_to!(@next_char, chars, len); + } _ => { let end = match chars.find(|&(_, c)| !is_word_char(c)) { Some((end, _)) => end, diff --git a/tests/compile-fail/doc.rs b/tests/compile-fail/doc.rs index 7a150ba378dc..045174db78e4 100755 --- a/tests/compile-fail/doc.rs +++ b/tests/compile-fail/doc.rs @@ -107,3 +107,11 @@ fn main() { test_emphasis(); test_units(); } + +/// I am confused by brackets? (`x_y`) +/// I am confused by brackets? (foo `x_y`) +/// I am confused by brackets? (`x_y` foo) +/// be_sure_we_got_to_the_end_of_it +//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks +fn issue900() { +} From cc2774df60082031b6b21cfac562537cff8163e4 Mon Sep 17 00:00:00 2001 From: mcarton Date: Thu, 5 May 2016 21:34:42 +0200 Subject: [PATCH 2/3] Test previously reported false positive --- tests/compile-fail/doc.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/compile-fail/doc.rs b/tests/compile-fail/doc.rs index 045174db78e4..0c8d1d505329 100755 --- a/tests/compile-fail/doc.rs +++ b/tests/compile-fail/doc.rs @@ -115,3 +115,17 @@ fn main() { //~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks fn issue900() { } + +/// Diesel queries also have a similar problem to [Iterator][iterator], where +/// /// More talking +/// returning them from a function requires exposing the implementation of that +/// function. The [`helper_types`][helper_types] module exists to help with this, +/// but you might want to hide the return type or have it conditionally change. +/// Boxing can achieve both. +/// +/// [iterator]: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html +/// [helper_types]: ../helper_types/index.html +/// be_sure_we_got_to_the_end_of_it +//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks +fn issue883() { +} From 3ce60e973139e1c44ad4bf67d26498c4e6c42d04 Mon Sep 17 00:00:00 2001 From: mcarton Date: Thu, 5 May 2016 21:42:59 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Don=E2=80=99t=20warn=20in=20titles=20in=20D?= =?UTF-8?q?OC=5FMARKDOWN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/doc.rs | 6 ++++++ tests/compile-fail/doc.rs | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/doc.rs b/src/doc.rs index 00c3e4398ea3..cf32c1731fa3 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -126,6 +126,7 @@ pub fn check_doc(cx: &EarlyContext, valid_idents: &[String], doc: &str, span: Sp span } + let mut new_line = true; let len = doc.len(); let mut chars = doc.char_indices().peekable(); let mut current_word_begin = 0; @@ -133,6 +134,9 @@ pub fn check_doc(cx: &EarlyContext, valid_idents: &[String], doc: &str, span: Sp match chars.next() { Some((_, c)) => { match c { + '#' if new_line => { // don’t warn on titles + current_word_begin = jump_to!(chars, '\n', len); + } '`' => { current_word_begin = jump_to!(chars, '`', len); } @@ -182,6 +186,8 @@ pub fn check_doc(cx: &EarlyContext, valid_idents: &[String], doc: &str, span: Sp current_word_begin = jump_to!(@next_char, chars, len); } } + + new_line = c == '\n' || (new_line && c.is_whitespace()); } None => break, } diff --git a/tests/compile-fail/doc.rs b/tests/compile-fail/doc.rs index 0c8d1d505329..eca9d79354c9 100755 --- a/tests/compile-fail/doc.rs +++ b/tests/compile-fail/doc.rs @@ -108,6 +108,18 @@ fn main() { test_units(); } +/// ## CamelCaseThing +/// Talks about `CamelCaseThing`. Titles should be ignored, see issue #897. +/// +/// # CamelCaseThing +/// +/// Not a title #897 CamelCaseThing +//~^ ERROR: you should put `CamelCaseThing` between ticks +/// be_sure_we_got_to_the_end_of_it +//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks +fn issue897() { +} + /// I am confused by brackets? (`x_y`) /// I am confused by brackets? (foo `x_y`) /// I am confused by brackets? (`x_y` foo)