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

Incorrect missing docs lint for proc-macro-lib crates #42008

Closed
mthebridge opened this issue May 15, 2017 · 9 comments · Fixed by #60562
Closed

Incorrect missing docs lint for proc-macro-lib crates #42008

mthebridge opened this issue May 15, 2017 · 9 comments · Fixed by #60562
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug.

Comments

@mthebridge
Copy link

proc-macro-lib crates, when compiled with -W missing-docs, generate invalid warnings about missing documentation.

The following simple crate demonstrates the error.

src/lib.rs:

//! Custom derive module
extern crate proc_macro;

use proc_macro::TokenStream;

/// Derive IntoIterator
#[proc_macro_derive(IntoIterator)]
pub fn into_iterator(_input: TokenStream) -> TokenStream {
    unimplemented!()
}

Cargo.toml:

[package]
name = "tmp"
version = "0.1.0"

[lib]
proc-macro = true

I expect this to compile cleanly since there is a crate-level doc comment and a doc comment for the public function.

Instead, compiling gives:

warning: missing documentation for a module [-W missing-docs]
 --> src/lib.rs:1:1
  |
1 | //! Custom derive module
  | ^

warning: missing documentation for a function [-W missing-docs]
 --> src/lib.rs:1:1
  |
1 | //! Custom derive module
  | ^

which makes no sense since line 1 is a comment.

Compiler version - latest stable, but fails on yesterday's nightly (2017-05-14) too:

rustc --version --verbose:

rustc 1.17.0 (56124baa9 2017-04-24)
binary: rustc
commit-hash: 56124baa9e73f28c0709e59e74783cf234a978cf
commit-date: 2017-04-24
host: x86_64-unknown-linux-gnu
release: 1.17.0
LLVM version: 3.9
@Mark-Simulacrum
Copy link
Member

cc #38356 (tracking issue)

@Mark-Simulacrum Mark-Simulacrum added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros-2.0 Area: Declarative macros 2.0 (#39412) labels Jun 23, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 27, 2017
@d-e-s-o
Copy link
Contributor

d-e-s-o commented Mar 8, 2018

I am hitting the same problem. This issue is preventing #![deny(missing_docs)] for proc-macro crates (I haven't found a work around). That's pretty annoying :-/ Rust 1.24.1.

@H2CO3
Copy link

H2CO3 commented Apr 10, 2018

Same here. Is there a fix for this?

@JeanMertz
Copy link

Seems to still be happening.

JeanMertz added a commit to rustic-games/rust that referenced this issue Oct 2, 2018
@repnop
Copy link
Contributor

repnop commented Nov 17, 2018

Fails on stable, beta, and nightly still.

@dbeckwith
Copy link

On a proc-macro crate in nightly-2019-01-02, I'm getting two warnings: missing documentation for a module and missing documentation for a static with no line numbers.

@iliekturtles
Copy link
Contributor

cargo +nightly expand shows that the compiler is inserting a pub mod with a pub static. I didn't find the code that does the insertion in a very brief search.

//your proc_macro's mod.rs code...

pub mod decls {
    extern crate proc_macro;
    #[rustc_proc_macro_decls]
    pub static _DECLS: &[proc_macro::bridge::client::ProcMacro] =
        &[proc_macro::bridge::client::ProcMacro::bang(
            "your_proc_macro",
            crate::your_proc_macro,
        )];
}

@remexre
Copy link
Contributor

remexre commented May 3, 2019

So I guess the low-effort fix here is slapping #[doc(hidden)] on that mod?

EDIT: Looks like the code that generates that is

fn mk_decls(
cx: &mut ExtCtxt<'_>,
custom_derives: &[ProcMacroDerive],
custom_attrs: &[ProcMacroDef],
custom_macros: &[ProcMacroDef],
) -> P<ast::Item> {
?

@iliekturtles
Copy link
Contributor

Thanks @remexre! Turns out my working copy wasn't updated like I thought so searching through it didn't work. PR #60562 just submitted.

iliekturtles added a commit to iliekturtles/rust that referenced this issue May 11, 2019
Stops unavoidable `missing_docs` warning/error on proc-macro crates.
Resolves rust-lang#42008.
Centril added a commit to Centril/rust that referenced this issue May 13, 2019
…s, r=alexcrichton

Add #[doc(hidden)] attribute on compiler generated module.

Resolves unavoidable `missing_docs` warning/error on proc-macro crates.
Resolves rust-lang#42008.

Changes not yet tested locally, however I wanted to submit first since `rustc` takes forever to compile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants