Skip to content

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

Closed
@aDotInTheVoid

Description

@aDotInTheVoid
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rustdoc-jsonArea: Rustdoc JSON backendT-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions