Stream: t-compiler/help

Topic: Doc comment AST?


lzutao (Jul 09 2020 at 13:21, on Zulip):

I am trying to improve doc comment parsing in rustc but I don't quite understand how the
parser would pass the input of doc comment to helpers?

What would be the AST for this block doc comment?

pub mod foo {
    /**
     * this is insane
     *************/
    pub fn bar() {}
}
lzutao (Jul 09 2020 at 13:30, on Zulip):

Ping @simulacrum

simulacrum (Jul 09 2020 at 13:31, on Zulip):

I don't know :)

lzutao (Jul 09 2020 at 13:33, on Zulip):

Sorry. Ping other rustdoc folks @GuillaumeGomez @Joshua Nelson

Joshua Nelson (Jul 09 2020 at 13:35, on Zulip):

I wonder if rustdoc has some -Z unpretty option that would show it

Joshua Nelson (Jul 09 2020 at 13:36, on Zulip):

I don't know off the top of my head

lzutao (Jul 09 2020 at 13:37, on Zulip):

cargo expand make block comment to line comment?

pub mod foo {
    ////**
    ///     * this is insane
    ///     *************/
    pub fn bar() {}
}
Joshua Nelson (Jul 09 2020 at 13:38, on Zulip):

Seems odd, wouldn't that include the *?

Joshua Nelson (Jul 09 2020 at 13:38, on Zulip):

Do those show up if you run cargo doc?

lzutao (Jul 09 2020 at 13:40, on Zulip):

You mean the old one or the one after expanded by cargo-expand?

Joshua Nelson (Jul 09 2020 at 13:44, on Zulip):

Either

lzutao (Jul 09 2020 at 13:48, on Zulip):

The old one: image.png
The expanded one: image.png

Joshua Nelson (Jul 09 2020 at 14:21, on Zulip):

Cargo expand is lying to you then, that's fun

lzutao (Jul 09 2020 at 14:31, on Zulip):

That's the same output if you pass -Z unpretty=hir to rustc.

Eric Huss (Jul 09 2020 at 14:32, on Zulip):

maybe I'm misunderstanding the question, but you can use -Zast-json or -Zast-json-noexpand to see the AST. Or are you asking about how rustdoc parses the comment itself?

lzutao (Jul 09 2020 at 14:34, on Zulip):

I'm mostly asking about this file: https://github.com/rust-lang/rust/blob/master/src/librustc_ast/util/comments.rs

lzutao (Jul 09 2020 at 14:34, on Zulip):

which is belong to ast I think

lzutao (Jul 09 2020 at 14:35, on Zulip):

The function like https://github.com/rust-lang/rust/blob/5db778affee7c6600c8e7a177c48282dab3f6292/src/librustc_ast/util/comments.rs#L48
I am not clear about its input form

Eric Huss (Jul 09 2020 at 14:39, on Zulip):

In your example, I think it would be "/**\n * this is insane\n *************/" from the #[doc] attribute.

lzutao (Jul 09 2020 at 14:41, on Zulip):

thank you. I will investigate more.

Last update: Jan 22 2021 at 13:30UTC