Macro Not Implemented in Rust Doc

Hello. I am new to Rust and I am confused about Rust macro documentation. For example, when looking at the implementation of println! macro, all I get is this ...

macro_rules! println {
    () => { ... };
    ($($arg : tt) *) => { ... };

It seems I am only getting the signature or interface. Where is the actual implementation? Am I missing something?
Please advsie.

If you click the [src] link in the documentation, it shows:

macro_rules! println {
    () => ($crate::print!("\n"));
    ($($arg:tt)*) => ({

But the really interesting parts are in that format_args_nl!, which is a compiler built-in macro here:


rustdoc never reveals code that is part of the implementation (function/macro bodies, private fields and items, etc.) rather than the interface (function/macro signatures, public fields, etc.), except through the [src] links.

The reason you see a partial macro_rules declaration is because there isn't a particularly better way to show what the allowed input syntax of the macro is — at least, nobody's designed and implemented one.

1 Like

It's not perfect (there are some idioms that aren't handled), but this can be quite helpful when dealing with complex macros.


Not quite on-topic, but I think it would be extremely useful if such railroad diagrams were a standard part of the API docs for at least macro_rules! macros.

ATM the option to generate one yourself kind of disappears into the background due to the non-trivial URL involved. At least that's how it went for me, as I've seen this before.

1 Like

Thank you everyone for your responds. I get it now!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.