Skip to content

Doc comments on modules are included twice in AST #12646

Closed
@zslayton

Description

@zslayton

Following up on an issue first discovered in #12386. ///-style Doc comments placed on pub mod lines appear twice in the AST.

In this minimal example, there are two files: mod.rs and test.rs.

mod.rs contains:

/// The 'test' module is elegant in its minimalism. 
pub mod test;

test.rs contains:

/*! This summary statement describes the 'test' module */
pub fn print_test_message() {
   println!("I am a test message.");
}

Compiling with rustc -Z ast-json mod.rs produces the following AST fragment:

    "items": [
      {
        "ident": "test",
        "attrs": [
          {
            "node": {
              "style": "AttrOuter",
              "value": {
                "node": [
                  "MetaNameValue",
                  "doc",
                  {
                    "node": [
                      "LitStr",
                      "/// The 'test' module is elegant in its minimalism. ",
                      "CookedStr"
                    ],
                    "span": null
                  }
                ],
                "span": null
              },
              "is_sugared_doc": true
            },
            "span": null
          },
          {
            "node": {
              "style": "AttrOuter",
              "value": {
                "node": [
                  "MetaNameValue",
                  "doc",
                  {
                    "node": [
                      "LitStr",
                      "/// The 'test' module is elegant in its minimalism. ",
                      "CookedStr"
                    ],
                    "span": null
                  }
                ],
                "span": null
              },
              "is_sugared_doc": true
            },
            "span": null
          }
// .... remainder of AST follows

The complete AST can be found here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions