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

Rustdoc-Json: async fn foo() -> T return type is given as impl Future<Output=T> not T #101199

Closed
aDotInTheVoid opened this issue Aug 30, 2022 · 3 comments · Fixed by #101204
Closed
Labels
A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@aDotInTheVoid
Copy link
Member

pub async fn foo() {}

produces:

    "0:4:1568": {
      "attrs": [],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": "0:4:1568",
      "inner": {
        "decl": {
          "c_variadic": false,
          "inputs": [],
          "output": {
            "inner": [
              {
                "trait_bound": {
                  "generic_params": [],
                  "modifier": "none",
                  "trait": {
                    "args": {
                      "angle_bracketed": {
                        "args": [],
                        "bindings": [
                          {
                            "args": {"angle_bracketed": {"args": [], "bindings": []}},
                            "binding": {"equality": {"type": {"inner": [], "kind": "tuple"}}},
                            "name": "Output"
                          }
                        ]
                      }
                    },
                    "id": "1:14043:139",
                    "name": "Future"
                  }
                }
              }
            ],
            "kind": "impl_trait"
          }
        },
        "generics": {"params": [], "where_predicates": []},
        "header": {"abi": "Rust", "async": true, "const": false, "unsafe": false}
      },
      "kind": "function",
      "links": {},
      "name": "foo",
      "span": {"begin": [4, 0], "end": [4, 21], "filename": "/home/nixon/dev/rust/rust/src/test/rustdoc-json/async_orphan.rs"},
      "visibility": "public"
    }

But I think it should be.

    "0:4:1568": {
      "attrs": [],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": "0:4:1568",
      "inner": {
        "decl": {
          "c_variadic": false,
          "inputs": [],
          "output": {
            "inner": [],
            "kind": "tuple"
          }
        },
        "generics": {"params": [], "where_predicates": []},
        "header": {"abi": "Rust", "async": true, "const": false, "unsafe": false}
      },
      "kind": "function",
      "links": {},
      "name": "foo",
      "span": {"begin": [4, 0], "end": [4, 21], "filename": "/home/nixon/dev/rust/rust/src/test/rustdoc-json/async_orphan.rs"},
      "visibility": "public"
    }

For the HTML backend, rustdoc "resugars" the return type to get the T from impl Future<Output=T>

let arrow = if let hir::IsAsync::Async = asyncness {
let output = self.sugared_async_return_type();
arrow_plain = format!("{:#}", output.print(cx));
if f.alternate() { arrow_plain.clone() } else { format!("{}", output.print(cx)) }
} else {
arrow_plain = format!("{:#}", self.output.print(cx));
if f.alternate() { arrow_plain.clone() } else { format!("{}", self.output.print(cx)) }
};

I think we should move this to a clean pass.

cc @CraftSpider @GuillaumeGomez @Enselic, does this change seem like a good idea.

@rustbot modify labels: +T-rustdoc +A-rustdoc-json

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Aug 30, 2022
@GuillaumeGomez
Copy link
Member

I'm not sure if it's worth adding a pass for this... Maybe handling this into a specific function shared between both formats could be a better idea?

@aDotInTheVoid
Copy link
Member Author

aDotInTheVoid commented Aug 30, 2022

We could call sugared_async_return_type in json::conversions. Or we could move this to when constructing clean. I'm not sure which makes most sense.

@GuillaumeGomez
Copy link
Member

In clean directly seems like a good approach.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Aug 31, 2022
…an, r=GuillaumeGomez

rustdoc: Resugar async fn return type in `clean`, not `html`

This way it also happens for json output.

Fixes rust-lang#101199

r? `@GuillaumeGomez`
RalfJung added a commit to RalfJung/rust that referenced this issue Aug 31, 2022
…an, r=GuillaumeGomez

rustdoc: Resugar async fn return type in `clean`, not `html`

This way it also happens for json output.

Fixes rust-lang#101199

r? ``@GuillaumeGomez``
@bors bors closed this as completed in 6099d17 Aug 31, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Sep 15, 2022
…aumeGomez

Replace `check_missing_items.py` with `jsondoclint`

[zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/check_missing_items.2Epy.20Replacement.2E)

check_missing_items.py was a python script that checked rustdoc json output to make sure all the Id's referenced existed in the JSON index. This PR replaces that with a rust binary (`jsondoclint`) that does the same thing.

### Motivation

1. Easier to change when `rustdoc-json-types` changes, as `jsondoclint` uses the types directly.
2. Better Errors:
    - Multiple Errors can be emited for a single crate
    - Errors can say where in JSON they occored
        ```
        2:2889:408 not in index or paths, but refered to at '.index."2:2888:104".inner.items[0]'
        2:2890:410 not in index or paths, but refered to at '.index."2:2888:104".inner.items[1]'
        ```
3. Catches more bugs.
    - Because matches are exaustive, all posible variants considered for enums
    - All Id's checked
    - Has already found rust-lang#101770, rust-lang#101199 and rust-lang#100973
    - Id type is also checked, so the Id's in a structs fields can only be field items.
4. Allows the possibility of running from `rustdoc::json`, which we should do in a crator run at some point.

cc `@CraftSpider`

r? `@GuillaumeGomez`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Sep 15, 2022
…aumeGomez

Replace `check_missing_items.py` with `jsondoclint`

[zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/check_missing_items.2Epy.20Replacement.2E)

check_missing_items.py was a python script that checked rustdoc json output to make sure all the Id's referenced existed in the JSON index. This PR replaces that with a rust binary (`jsondoclint`) that does the same thing.

### Motivation

1. Easier to change when `rustdoc-json-types` changes, as `jsondoclint` uses the types directly.
2. Better Errors:
    - Multiple Errors can be emited for a single crate
    - Errors can say where in JSON they occored
        ```
        2:2889:408 not in index or paths, but refered to at '.index."2:2888:104".inner.items[0]'
        2:2890:410 not in index or paths, but refered to at '.index."2:2888:104".inner.items[1]'
        ```
3. Catches more bugs.
    - Because matches are exaustive, all posible variants considered for enums
    - All Id's checked
    - Has already found rust-lang#101770, rust-lang#101199 and rust-lang#100973
    - Id type is also checked, so the Id's in a structs fields can only be field items.
4. Allows the possibility of running from `rustdoc::json`, which we should do in a crator run at some point.

cc `@CraftSpider`

r? `@GuillaumeGomez`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Sep 16, 2022
…aumeGomez

Replace `check_missing_items.py` with `jsondoclint`

[zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/check_missing_items.2Epy.20Replacement.2E)

check_missing_items.py was a python script that checked rustdoc json output to make sure all the Id's referenced existed in the JSON index. This PR replaces that with a rust binary (`jsondoclint`) that does the same thing.

### Motivation

1. Easier to change when `rustdoc-json-types` changes, as `jsondoclint` uses the types directly.
2. Better Errors:
    - Multiple Errors can be emited for a single crate
    - Errors can say where in JSON they occored
        ```
        2:2889:408 not in index or paths, but refered to at '.index."2:2888:104".inner.items[0]'
        2:2890:410 not in index or paths, but refered to at '.index."2:2888:104".inner.items[1]'
        ```
3. Catches more bugs.
    - Because matches are exaustive, all posible variants considered for enums
    - All Id's checked
    - Has already found rust-lang#101770, rust-lang#101199 and rust-lang#100973
    - Id type is also checked, so the Id's in a structs fields can only be field items.
4. Allows the possibility of running from `rustdoc::json`, which we should do in a crator run at some point.

cc ``@CraftSpider``

r? ``@GuillaumeGomez``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants