Skip to content

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

Closed
@Enselic

Description

@Enselic

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
}

Metadata

Metadata

Assignees

Labels

A-rustdoc-jsonArea: Rustdoc JSON backendC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions