-
Notifications
You must be signed in to change notification settings - Fork 14k
Description
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).