Rollup merge of #54577 - QuietMisdreavus:docs-for-procs, r=GuillaumeGomez
rustdoc: give proc-macros their own pages related to https://github.com/rust-lang/rust/issues/49553 but i don't think it'll fix it Currently, rustdoc doesn't expose proc-macros all that well. In the source crate, only their definition function is exposed, but when re-exported, they're treated as a macro! This is an awkward situation in all accounts. This PR checks functions to see whether they have any of `#[proc_macro]`, `#[proc_macro_attribute]`, or `#[proc_macro_derive]`, and exposes them as macros instead. In addition, attributes and derives are exposed differently than other macros, getting their own item-type, CSS class, and module heading.  Function-like proc-macros are lumped in with `macro_rules!` macros, but they get a different declaration block (i'm open to tweaking this, it's just what i thought of given how function-proc-macros operate):  Proc-macro attributes and derives get their own pages, with a representative declaration block. Derive macros also show off their helper attributes:   There's one wrinkle which this PR doesn't address, which is why i didn't mark this as fixing the linked issue. Currently, proc-macros don't expose their attributes or source span across crates, so while rustdoc knows they exist, that's about all the information it gets. This leads to an "inlined" macro that has absolutely no docs on it, and no `[src]` link to show you where it was declared. The way i got around it was to keep proc-macro re-export disabled, since we do get enough information across crates to properly link to the source page:  Until we can get a proc-macro's docs (and ideally also its source span) across crates, i believe this is the best way forward.
This commit is contained in:
commit
def5f84fa6
13 changed files with 372 additions and 50 deletions
37
src/test/rustdoc/inline_cross/auxiliary/proc_macro.rs
Normal file
37
src/test/rustdoc/inline_cross/auxiliary/proc_macro.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type="proc-macro"]
|
||||
#![crate_name="some_macros"]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
/// a proc-macro that swallows its input and does nothing.
|
||||
#[proc_macro]
|
||||
pub fn some_proc_macro(_input: TokenStream) -> TokenStream {
|
||||
TokenStream::new()
|
||||
}
|
||||
|
||||
/// a proc-macro attribute that passes its item through verbatim.
|
||||
#[proc_macro_attribute]
|
||||
pub fn some_proc_attr(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
item
|
||||
}
|
||||
|
||||
/// a derive attribute that adds nothing to its input.
|
||||
#[proc_macro_derive(SomeDerive)]
|
||||
pub fn some_derive(_item: TokenStream) -> TokenStream {
|
||||
TokenStream::new()
|
||||
}
|
||||
|
||||
27
src/test/rustdoc/inline_cross/proc_macro.rs
Normal file
27
src/test/rustdoc/inline_cross/proc_macro.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-stage1
|
||||
// aux-build:proc_macro.rs
|
||||
// build-aux-docs
|
||||
|
||||
// FIXME: if/when proc-macros start exporting their doc attributes across crates, we can turn on
|
||||
// cross-crate inlining for them
|
||||
|
||||
extern crate some_macros;
|
||||
|
||||
// @has proc_macro/index.html
|
||||
// @has - '//a/@href' '../some_macros/macro.some_proc_macro.html'
|
||||
// @has - '//a/@href' '../some_macros/attr.some_proc_attr.html'
|
||||
// @has - '//a/@href' '../some_macros/derive.SomeDerive.html'
|
||||
// @!has proc_macro/macro.some_proc_macro.html
|
||||
// @!has proc_macro/attr.some_proc_attr.html
|
||||
// @!has proc_macro/derive.SomeDerive.html
|
||||
pub use some_macros::{some_proc_macro, some_proc_attr, SomeDerive};
|
||||
62
src/test/rustdoc/proc-macro.rs
Normal file
62
src/test/rustdoc/proc-macro.rs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-stage1
|
||||
|
||||
#![crate_type="proc-macro"]
|
||||
#![crate_name="some_macros"]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
// @has some_macros/index.html
|
||||
// @has - '//h2' 'Macros'
|
||||
// @has - '//h2' 'Attribute Macros'
|
||||
// @has - '//h2' 'Derive Macros'
|
||||
// @!has - '//h2' 'Functions'
|
||||
|
||||
// @has some_macros/all.html
|
||||
// @has - '//a[@href="macro.some_proc_macro.html"]' 'some_proc_macro'
|
||||
// @has - '//a[@href="attr.some_proc_attr.html"]' 'some_proc_attr'
|
||||
// @has - '//a[@href="derive.SomeDerive.html"]' 'SomeDerive'
|
||||
// @!has - '//a/@href' 'fn.some_proc_macro.html'
|
||||
// @!has - '//a/@href' 'fn.some_proc_attr.html'
|
||||
// @!has - '//a/@href' 'fn.some_derive.html'
|
||||
|
||||
// @has some_macros/index.html '//a/@href' 'macro.some_proc_macro.html'
|
||||
// @!has - '//a/@href' 'fn.some_proc_macro.html'
|
||||
// @has some_macros/macro.some_proc_macro.html
|
||||
// @!has some_macros/fn.some_proc_macro.html
|
||||
/// a proc-macro that swallows its input and does nothing.
|
||||
#[proc_macro]
|
||||
pub fn some_proc_macro(_input: TokenStream) -> TokenStream {
|
||||
TokenStream::new()
|
||||
}
|
||||
|
||||
// @has some_macros/index.html '//a/@href' 'attr.some_proc_attr.html'
|
||||
// @!has - '//a/@href' 'fn.some_proc_attr.html'
|
||||
// @has some_macros/attr.some_proc_attr.html
|
||||
// @!has some_macros/fn.some_proc_attr.html
|
||||
/// a proc-macro attribute that passes its item through verbatim.
|
||||
#[proc_macro_attribute]
|
||||
pub fn some_proc_attr(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
item
|
||||
}
|
||||
|
||||
// @has some_macros/index.html '//a/@href' 'derive.SomeDerive.html'
|
||||
// @!has - '//a/@href' 'fn.some_derive.html'
|
||||
// @has some_macros/derive.SomeDerive.html
|
||||
// @!has some_macros/fn.some_derive.html
|
||||
/// a derive attribute that adds nothing to its input.
|
||||
#[proc_macro_derive(SomeDerive)]
|
||||
pub fn some_derive(_item: TokenStream) -> TokenStream {
|
||||
TokenStream::new()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue