Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc_link_with_quotes false postive for code inside code block #8961

Closed
dtolnay opened this issue Jun 7, 2022 · 8 comments · Fixed by #9567
Closed

doc_link_with_quotes false postive for code inside code block #8961

dtolnay opened this issue Jun 7, 2022 · 8 comments · Fixed by #9567
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@dtolnay
Copy link
Member

dtolnay commented Jun 7, 2022

Summary

The doc_link_with_quotes lint is documented as:

Detects the syntax ['foo'] in documentation comments (notice quotes instead of backticks) outside of code blocks

However it is incorrectly triggering on code inside of code blocks.

Lint Name

doc_link_with_quotes

Reproducer

/// This is a code block:
///
/// ```
/// let _ = vec!['w', 'a', 't'];
/// ```
fn main() {}
error: possible intra-doc link using quotes instead of backticks
 --> src/main.rs:4:1
  |
4 | /// let _ = vec!['w', 'a', 't'];
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `-D clippy::doc-link-with-quotes` implied by `-D clippy::pedantic`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes

It is indeed a code block though.

Screenshot from 2022-06-07 00-27-18

Mentioning @cameron1024 since this lint was recently added in #8385.

Version

rustc 1.63.0-nightly (50b00252a 2022-06-06)
binary: rustc
commit-hash: 50b00252aeb77b10db04d65dc9e12ce758def4b5
commit-date: 2022-06-06
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.5

Additional Labels

No response

@dtolnay dtolnay added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jun 7, 2022
dtolnay added a commit to dtolnay/path-to-error that referenced this issue Jun 7, 2022
rust-lang/rust-clippy#8961

    error: possible intra-doc link using quotes instead of backticks
      --> src/ser.rs:76:1
       |
    76 | /// inner_map.insert(vec!['w', 'a', 't'], 0);
       | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: `-D clippy::doc-link-with-quotes` implied by `-D clippy::pedantic`
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes
dtolnay added a commit to serde-rs/serde that referenced this issue Jun 7, 2022
rust-lang/rust-clippy#8961

    error: possible intra-doc link using quotes instead of backticks
       --> serde_test/src/token.rs:277:5
        |
    277 |     /// let vec = vec!['a', 'b', 'c'];
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = note: `-D clippy::doc-link-with-quotes` implied by `-D clippy::pedantic`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes
@cameron1024
Copy link
Contributor

Hmm this looks pretty bad, I'll have a look at this. I'm pretty new to clippy so I'm not sure how long it will take 😅

@cameron1024
Copy link
Contributor

Hmm this looks pretty bad, I'll have a look at this. I'm pretty new to clippy though so I'm not sure how long it will take 😅

@tamaroning
Copy link
Contributor

tamaroning commented Jun 12, 2022

@cameron1024
Hi, this lint seems not to deal with code blocks (``` ... ```) for now.
You should

  1. add in_code_block: bool field to DocLinkWithQuotes struct by manually declaring the struct (See this)
  2. add a logic which change its value when bumping into ```.
  3. add tests

If you do not tackle with this, it is ok and I am going to assign this to me😀

@Alexendoo
Copy link
Member

doc.rs contains code that reassembles + parses markdown from doc comments, the lint could be down by replacing fake_broken_link_callback with a closure that checks if the link is enclosed in '. That would also avoid any weird behaviour with backticks appearing in code blocks

let mut cb = fake_broken_link_callback;
let parser =
pulldown_cmark::Parser::new_with_broken_link_callback(&doc, Options::empty(), Some(&mut cb)).into_offset_iter();

@ikopysov
Copy link

@rustbot claim

@ikopysov ikopysov removed their assignment Sep 25, 2022
@ikopysov
Copy link

Sorry, came here because #9321 tagged as "good-first-issue" but this markdown parser seems too complex for me to understand how it should be implemented.
Maybe it was tagged as such with first change in ming (ignoring everything in the ``` code block), but with parser I don't believe it's actually good issue to start with.

@Alexendoo
Copy link
Member

That's fair, I'll close that one as a duplicate

@llogiq
Copy link
Contributor

llogiq commented Sep 27, 2022

I've written some of the code in that module, I can take it.

@rustbot claim

@bors bors closed this as completed in 8da2429 Oct 1, 2022
dtolnay added a commit to serde-deprecated/test that referenced this issue Jul 26, 2023
rust-lang/rust-clippy#8961

    error: possible intra-doc link using quotes instead of backticks
       --> serde_test/src/token.rs:277:5
        |
    277 |     /// let vec = vec!['a', 'b', 'c'];
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = note: `-D clippy::doc-link-with-quotes` implied by `-D clippy::pedantic`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants