rustdoc: Add [arg@name] intra-doc syntax for referencing function arguments#153734
rustdoc: Add [arg@name] intra-doc syntax for referencing function arguments#153734nik-rev wants to merge 1 commit intorust-lang:mainfrom
[arg@name] intra-doc syntax for referencing function arguments#153734Conversation
|
r? @notriddle rustbot has assigned @notriddle. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
cbe7b7b to
c709d3f
Compare
|
Mostly for me: the feature as of now checks if an argument exists and if so, replace the intra-doc link with the argument name, allowing to check that the docs are up to date. Not sure if it's worth generating IDs for all function arguments as it would increase quite a lot the HTML size. Maybe we could only generate IDs for arguments which are pointed by |
|
Considering what @kpreid said on zulip in (#t-rustdoc > Allow referencing function arguments in function docs? @ 💬):
I agree with this quite a lot, so I have pushed a new commit (edit: reverted, but can bring back if needed) that adds implicit function argument support. I will squash that if this PR gets merged, but also keeping it as a separate commit so it can be easily reverted if needed. |
|
I commented here why I don't think we should put the function arguments at the same level. |
This comment has been minimized.
This comment has been minimized.
483d7bf to
28f9bdf
Compare
This comment has been minimized.
This comment has been minimized.
|
All unrelated code changes have been removed |
This PR adds a feature that allows referencing function arguments using the intra-doc syntax
[arg@name].Example
You may not be able to tell at a first glance, but the above example actually contains a typo. The
img_dataargument does not exist; instead, the function author meant to refer to theimage_dataargument.Thankfully, because they explicitly referred to the argument with the intra-doc syntax
[`arg@img_data`],rustdocwill emit an error for the above example:Impact on generated HTML
In terms of the generated documentation,
arg@intra-doc "links" don't impact the HTML output at all. The links are stripped completely, and they are rendered equivalently to the following documentation:Exciting possibilities
if rustdoc gains an official syntax for referring to function arguments,
rust-analyzercould also implement that - so you could rename your function's arguments and they would automatically be renamed in the documentation, for example.Notes
Using the
arg@prefix is required. But if we are happy with it being inferred, I can make that happen.Relevant issue: #57525
Implementation
PageId(the field that says "where is this this item's documentation") is nowOption<DefId>instead ofDefId, because intra-doc argument references do not refer to any particular item (function arguments are not real items)RenderedLink'shreffield is nowOption<String>instead ofString. When it isNone, no link is generated in the HTML at all.Events, theEvent::Start(Link)is replaced with an empty text, andEvent::End(Link)is also. So there is no link in the output.Zulip discussion: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Allow.20referencing.20function.20arguments.20in.20function.20docs.3F/with/577839079