Skip to content
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

Doc comments on modules are included twice in AST #12646

Closed
zslayton opened this issue Mar 2, 2014 · 3 comments
Closed

Doc comments on modules are included twice in AST #12646

zslayton opened this issue Mar 2, 2014 · 3 comments

Comments

@zslayton
Copy link
Contributor

zslayton commented Mar 2, 2014

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.

@huonw
Copy link
Member

huonw commented Mar 2, 2014

A minimal test seems to be:

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

with an empty test.rs, and it doesn't trigger with an inline mod test {}, i.e. it's caused by having multiple files.

@zslayton
Copy link
Contributor Author

I retried the minimal test cases described here and the problem appears to have been resolved at some point. Shall I close the ticket or is there some additional procedure to consider?

@steveklabnik
Copy link
Member

Nope, that's it.

fasterthanlime pushed a commit to fasterthanlime/rust that referenced this issue Jul 22, 2022
fix: escape receiver texts in completion

This PR fixes rust-lang#11897 by escaping '\\' and '$' in the text of the receiver position expression. See [here](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#snippet_syntax) for the specification of the snippet syntax (especially [this section](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#grammar) discusses escaping).

Although not all occurrences of '\\' and '$' have to be replaced, I chose to replace all as that's simpler and easier to understand. There *are* more clever ways to implement it, but I thought they were premature optimization for the time being (maybe I should put FIXME notes?).
flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 18, 2024
… r=blyxyas

Turn `duplicated_attributes` into a late lint

Fixes rust-lang#12537.

changelog: Turn `duplicated_attributes` into a late lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants