Skip to content

rustdoc: Source code pages & code blocks should be highlighted according to the requested / ambient edition #148221

@fmease

Description

@fmease

rustdoc currently unconditionally highlights keywords according to Rust 2024 (the latest stable edition at the time of writing). However, ideally, rustdoc would consult the "requested" / "ambient" edition instead.

In the case of code blocks / doctests, the "requested" edition would be found in the code block attributes (e.g., edition2018). If there's no "requested" edition, we should fall back to the ("ambient") edition of the local crate (indeed, we should not look at the Span (!) for consistency with doctest building/running).

In the case of source code pages, we should determine the "ambient" edition from the relevant Span. It can indeed differ from edition of the local crate if the sources contain invocations of macros defined in a crate with a differing edition. Under the unstable --generate-macro-expansion (tracking issue: #148222), the user can click to expand the invocation in which case the expansion should be highlighted according to the correct ambient edition.

Finally, we currently only care about keywords when it comes to edition sensitivity. However, there are other lexical/syntactic things that need to be accounted for (e.g., 2021 prefixes).


TODO: Add examples (will do so later, I've got other things to work on).

Metadata

Metadata

Assignees

Labels

A-editionsArea: Related to editions collectively or in general (i.e., the mechanism itself).A-rustdoc-uiArea: Rustdoc UI (generated HTML)C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions