Skip to content

unclear behaviour of missing_doc_code_examples #60664

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

Closed
Geal opened this issue May 9, 2019 · 10 comments
Closed

unclear behaviour of missing_doc_code_examples #60664

Geal opened this issue May 9, 2019 · 10 comments
Assignees
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Geal
Copy link
Contributor

Geal commented May 9, 2019

Hello,
consider this code example:

#![deny(missing_docs)]
#![deny(missing_doc_code_examples)]
//! crate level doc
//! ```
//! println!("hello"):
//! ```


/// doc
///
/// ```
/// println!("hello");
/// ```
fn test() {
}

// the allow() here works as expected, but missing_doc_code_examples still complains
#[allow(missing_docs)]
mod module1 {

  fn test() {}
}

// here we want some docs but no code examples, but missing_doc_code_examples still complains
#[allow(missing_doc_code_examples)]
/// doc
mod module2 {

  /// doc
  fn test() {}
}

/// doc
///
/// ```
/// println!("hello");
/// ```
mod module3 {

  // here we want some code examples but missing_doc_code_examples does not complain
  /// doc
  fn test() {}
}

Here I would expect the following behaviour when running cargo doc:

  • module1 has allow(missing_docs) so missing_doc_code_examples should be silent
  • module2 has allow(missing_doc_code_examples) yet we still get errors for missing docs on module2, I think we should not
  • module3 has a code example, but module3::test does not, we should get an error for the missing example on module3::test

cc @GuillaumeGomez

@GuillaumeGomez GuillaumeGomez self-assigned this May 9, 2019
@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label May 9, 2019
Geal added a commit to rust-bakery/nom that referenced this issue May 9, 2019
it does not work as expected right now (cf rust-lang/rust#60664)
@GuillaumeGomez
Copy link
Member

For module1, it's normal to get the error since both missing_doc_code_examples isn't bound to allow(missing_docs). However, for module3 it's very strange to not get anything. The strangest thing being that diagnostic is emitted there, we just don't see it.

Centril added a commit to Centril/rust that referenced this issue May 19, 2019
Fix lints handling in rustdoc

Part of rust-lang#60664: now lints are handled just like any other lints you would setup in rustc. Still remains to handle `missing code examples` and `missing_docs` as part of the same group.

r? @oli-obk
@danieleades
Copy link
Contributor

I feel like the title of this issue is slightly misleading. The behaviour is not simply unclear, it's totally broken.

@GuillaumeGomez
Copy link
Member

@danieleades The situation should have been improved since then. Do you still have a good example of where it's totally broken so we can continue to improve the whole situation?

@danieleades
Copy link
Contributor

yep.

steps to reproduce-

  1. make a new crate with the following lib.rs
#![deny(missing_doc_code_examples)]

/// this function has no code examples
pub fn some_function() {}
  1. build with nightly compiler

cargo +nightly build

  1. observe that there are no warnings

rust: 1.49.0-nightly

@GuillaumeGomez
Copy link
Member

It works as expected for me:

$ rustdoc --version
rustdoc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
$ rustdoc foo.rs 
error: missing code example in this documentation
 --> foo.rs:1:1
  |
1 | / #![deny(missing_doc_code_examples)]
2 | |
3 | | /// this function has no code examples
4 | | pub fn some_function() {}
  | |_________________________^
  |
note: the lint level is defined here
 --> foo.rs:1:9
  |
1 | #![deny(missing_doc_code_examples)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^

error: missing code example in this documentation
 --> foo.rs:3:1
  |
3 | /// this function has no code examples
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

@danieleades
Copy link
Contributor

It works as expected for me:

presumably that's because you didn't follow my reproduction steps.

Is it the intended behaviour that this lint only fire if you're building documentation with rustdoc? If so, that's inconsistent with all the other lints

@GuillaumeGomez
Copy link
Member

It's only supposed to be triggered by rustdoc indeed (my bad, didn't see you didn't use the doc command). I don't see how it's inconsistent though? It's marked as such in the lint documentation.

@danieleades
Copy link
Contributor

danieleades commented Nov 3, 2020

hmm i see after some digging that it's marked as 'rustdoc only' here - https://doc.rust-lang.org/beta/rustc/lints/listing/allowed-by-default.html#missing-doc-code-examples. Mea culpa.

Perhaps there are good historical or technical reasons why this is the case, but while i'm glad it's documented, simply describing the behaviour doesn't make it consistent.

this is inconsistent in the sense that out of ~120 or so rustc lints, there are how many that are 'rustdoc-only'? 2-3?

Given that the current behaviour is documented (though unexpected) I'm now in complete support of the issue title ;)

@GuillaumeGomez
Copy link
Member

You can see the list of the rustdoc lints there:

add_lint_group!(
"rustdoc",
BROKEN_INTRA_DOC_LINKS,
PRIVATE_INTRA_DOC_LINKS,
INVALID_CODEBLOCK_ATTRIBUTES,
MISSING_DOC_CODE_EXAMPLES,
PRIVATE_DOC_TESTS,
INVALID_HTML_TAGS
);

@GuillaumeGomez
Copy link
Member

Seems like this issue was fixed so closing. Don't hesitate to reopen if something is still missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants