Skip to content

Add an intra-doc link disambiguator for fields #80283

Closed
@camelid

Description

@camelid

I have code like this:

struct Foo { bar: i32 }

impl Foo {
    /// Get a reference to [`Foo::bar`].
    //                            ^^^ I want this to link to the field. Currently it links to the method.
    fn bar(&self) -> i32 { self.bar }
}

This is a decently-common Rust "design pattern" where you have have a private
field but give public read-only access via a method of the same name. However,
there's no way in rustdoc currently to disambiguate between the function and the
field. Rustdoc seems to always link to the method in this case.

It would be good if we had a disambiguator for struct/enum fields: something
like field@Foo::bar. I don't think it's necessary to have a different one for
struct vs enum variant fields, but we should still decide that since intra-doc
links are now stable (and thus we can't remove things).

See the discussion on Zulip.

cc @jyn514

Metadata

Metadata

Assignees

Labels

A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.needs-fcpThis change is insta-stable, so needs a completed FCP to proceed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions