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: Support for &dyn for<'a> Trait<'a> #99118

Closed
Enselic opened this issue Jul 10, 2022 · 1 comment · Fixed by #99787
Closed

rustdoc JSON: Support for &dyn for<'a> Trait<'a> #99118

Enselic opened this issue Jul 10, 2022 · 1 comment · Fixed by #99787
Assignees
Labels
A-rustdoc-json Area: Rustdoc JSON backend C-enhancement Category: An issue proposing an enhancement or a PR with one. requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Enselic
Copy link
Member

Enselic commented Jul 10, 2022

If we generate rustdoc JSON for this lib.rs:

#![feature(no_core)]
#![no_core]
#![no_std]
pub trait Trait<'a> {}
pub fn f(_: &dyn for<'a> Trait<'a>) {}

with the command:

rustdoc +nightly-2022-07-10 -Z unstable-options --output-format json lib.rs

we will get this rustdoc JSON in doc/lib.json for the function input parameters:

"inputs": [
    [
        "_",
        {
            "kind": "borrowed_ref",
            "inner": {
                "lifetime": null,
                "mutable": false,
                "type": {
                    "kind": "resolved_path",
                    "inner": {
                        "name": "Trait",
                        "id": "0:1:1565",
                        "args": {
                            "angle_bracketed": {
                                "args": [
                                    {
                                        "lifetime": "'a"
                                    }
                                ],
                                "bindings": []
                            }
                        },
                        "param_names": []
                    }
                }
            }
        }
    ]
],

as can be seen, the for<'a> part is absent. Info about that the dyn keywoard is used is not present either, unless one looks up 0:1:1565, in which case I guess it can be deduced that dyn is used. But it would be nice if that was made clearer.

I think the best way to solve this would be to introduce a DynTrait object of some kind to rustdoc JSON, as was done for rustdoc HTML in 4ea2748.

@rustbot labels +A-rustdoc-json +T-rustdoc +C-enhancement +requires-nightly

For reference, the full rustdoc JSON output can be seen below.

Click to expand!
% cat doc/lib.json | python3 -m json.tool 
{
    "root": "0:0:782",
    "crate_version": null,
    "includes_private": false,
    "index": {
        "0:3:617": {
            "id": "0:3:617",
            "crate_id": 0,
            "name": "f",
            "span": {
                "filename": "lib.rs",
                "begin": [
                    5,
                    0
                ],
                "end": [
                    5,
                    38
                ]
            },
            "visibility": "public",
            "docs": null,
            "links": {},
            "attrs": [],
            "deprecation": null,
            "kind": "function",
            "inner": {
                "decl": {
                    "inputs": [
                        [
                            "_",
                            {
                                "kind": "borrowed_ref",
                                "inner": {
                                    "lifetime": null,
                                    "mutable": false,
                                    "type": {
                                        "kind": "resolved_path",
                                        "inner": {
                                            "name": "Trait",
                                            "id": "0:1:1565",
                                            "args": {
                                                "angle_bracketed": {
                                                    "args": [
                                                        {
                                                            "lifetime": "'a"
                                                        }
                                                    ],
                                                    "bindings": []
                                                }
                                            },
                                            "param_names": []
                                        }
                                    }
                                }
                            }
                        ]
                    ],
                    "output": null,
                    "c_variadic": false
                },
                "generics": {
                    "params": [],
                    "where_predicates": []
                },
                "header": {
                    "const": false,
                    "unsafe": false,
                    "async": false,
                    "abi": "Rust"
                }
            }
        },
        "0:0:782": {
            "id": "0:0:782",
            "crate_id": 0,
            "name": "lib",
            "span": {
                "filename": "lib.rs",
                "begin": [
                    1,
                    0
                ],
                "end": [
                    5,
                    38
                ]
            },
            "visibility": "public",
            "docs": null,
            "links": {},
            "attrs": [
                "#![feature(no_core)]",
                "#![no_core]",
                "#![no_std]"
            ],
            "deprecation": null,
            "kind": "module",
            "inner": {
                "is_crate": true,
                "items": [
                    "0:1:1565",
                    "0:3:617"
                ]
            }
        },
        "0:1:1565": {
            "id": "0:1:1565",
            "crate_id": 0,
            "name": "Trait",
            "span": {
                "filename": "lib.rs",
                "begin": [
                    4,
                    0
                ],
                "end": [
                    4,
                    22
                ]
            },
            "visibility": "public",
            "docs": null,
            "links": {},
            "attrs": [],
            "deprecation": null,
            "kind": "trait",
            "inner": {
                "is_auto": false,
                "is_unsafe": false,
                "items": [],
                "generics": {
                    "params": [
                        {
                            "name": "'a",
                            "kind": {
                                "lifetime": {
                                    "outlives": []
                                }
                            }
                        }
                    ],
                    "where_predicates": []
                },
                "bounds": [],
                "implementations": []
            }
        }
    },
    "paths": {
        "0:3:617": {
            "crate_id": 0,
            "path": [
                "lib",
                "f"
            ],
            "kind": "function"
        },
        "0:1:1565": {
            "crate_id": 0,
            "path": [
                "lib",
                "Trait"
            ],
            "kind": "trait"
        },
        "0:0:782": {
            "crate_id": 0,
            "path": [
                "lib"
            ],
            "kind": "module"
        }
    },
    "external_crates": {},
    "format_version": 15
}
@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend C-enhancement Category: An issue proposing an enhancement or a PR with one. requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jul 10, 2022
@aDotInTheVoid
Copy link
Member

@rustbot claim

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Aug 9, 2022
…triddle,GuillaumeGomez

Rustdoc-Json: Document HRTB's on DynTrait

Closes rust-lang#99118

Probably best reviewed commit by commit.

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

cc `@Enselic`

r? `@CraftSpider`
@bors bors closed this as completed in a856e57 Aug 9, 2022
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. requires-nightly This issue requires a nightly compiler in some way. 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