-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
rustdoc: show macro interface but not implementation #17616
Comments
Hi, i'm a bit new to rustdoc (but willing to learn ;) ) |
You would probably want to reverse the order of calls in item_macro in html/render.rs (http://mxr.mozilla.org/rust/source/src/librustdoc/html/render.rs#2183). (For the record, I determined this by grepping the librustdoc for the word 'macro') |
Thx :) But looking at other macros in std, it seems that the code beeing present before the doc is a recurring issue... Anyways, thaks a lot for the answer (you kinda fixed the issue yourself ^^) |
Switching the two function calls somehow works, yet the traits, methods and example stay after the implementation. Is that good eough @kmcallister ? |
May be better to also put the traits and methods before ... Closes rust-lang#17616
@kmcallister look at @alexcrichton comment on the PR, this issue can be closed |
If the rule is that definition always comes before docs, then it's a problem that we document macros like structs or enums rather than like functions. We certainly don't want to put the full source of every function before its description. And I think there will be plenty of macros as large as Maybe the simple fix is a |
While we don't put the full source of functions/items/etc, we do put their interface. The interface of a macro is how you invoke it, which is the bare minimum of what must be displayed, and currently it does this by displaying the whole macro. A better solution to that problem in my opinion would be to only show the arms of the macro that provide information about how to invoke it, not what it generates. |
Agreed. If we move some code around, we can parse into LHSes and RHSes on macro definition, and then have rustdoc display only the former. I think I can get this in place for 1.0-stable. |
Not going to have time to work on this for 1.0-final, sorry. |
FWIW I also had the exact same thought when looking at the documentation for macro_rules! bitflags {
($(#[$attr:meta])* flags $BitFlags:ident: $T:ty {
$($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr),+
}) => { ... },
($(#[$attr:meta])* flags $BitFlags:ident: $T:ty {
$($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr),+,
}) => { ... },
} A welcome change. |
I have a similar issue, though it cannot easily be solved by just showing the left arm of the macro since there are multiple internal rules and they refer to each other: https://github.com/m4rw3r/chomp/blob/60cb0fb111e079c472c02821cee5e82b0eef2b82/src/macros.rs#L71 If we just go with the left arm of the macro it will result in a lot of nonsensical entrypoints: macro_rules! parse {
( @RET($i:expr); @ $t_ty:ty , $e_ty:ty : $e:expr ) => { ... };
( @RET($i:expr); $e:expr ) => { ... };
( @ERR($i:expr); @ $t_ty:ty , $e_ty:ty : $e:expr ) => { ... };
// ...
( $i:expr ; err $($tail:tt)+ ) => { ... };
// ...
( $i:expr ) => { $i };
} And skipping the internal rules will make the macro even more incomprehensible since the entrypoints themselves just parse a bit of the tokens for each invocation. For my case I would think that just hiding the whole macro definition would solve the problem (maybe with some button to expand the definition), since I have to explain how the macro is used anyway since it by itself says nothing unless people are very experienced with rust macros. As a workaround I have defined a hidden macro which contains the actual definition: https://github.com/m4rw3r/chomp/blob/5016d0b9e636156927e514f430e33510d9fa94f7/src/macros.rs#L76 |
Fixes #17616 New docs for `panic!`: ```rust macro_rules! panic { () => { ... }; ($msg:expr) => { ... }; ($fmt:expr, $($arg:tt)+) => { ... }; } ``` New docs for `assert!`: ```rust macro_rules! assert { ( $ cond : expr ) => { ... }; ( $ cond : expr , $ ( $ arg : tt ) + ) => { ... }; } ``` <sup>not pretty, but at least it's not worse 😂
Fix incorrect generic parameter hint defaults Missed this in the review but we should show const param hints, not lifetime param hints by default
Fix incorrect generic parameter hint defaults Missed this in the review but we should show const param hints, not lifetime param hints by default
e.g. http://doc.rust-lang.org/std/macro.bitflags!.html has 120 lines of macro code before anything useful.
The text was updated successfully, but these errors were encountered: