Stream: rustdoc

Topic: intra-doc link to field


view this post on Zulip Noah Lev (Dec 22 2020 at 00:40):

How do I use intra-doc links to link to a field with the same name as a method? E.g.:

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 }
}

I tried using field@, but that doesn't seem to exist.

view this post on Zulip Joshua Nelson (Dec 22 2020 at 01:39):

I don't think there's a way to disambiguate that currently

view this post on Zulip Noah Lev (Dec 22 2020 at 02:20):

Ah, really?

view this post on Zulip Noah Lev (Dec 22 2020 at 02:25):

Opened an issue: #80283.

view this post on Zulip GuillaumeGomez (Dec 22 2020 at 10:34):

You can't use Foo::bar()?

view this post on Zulip Joshua Nelson (Dec 22 2020 at 13:44):

@GuillaumeGomez that will link to the method, not the field

view this post on Zulip GuillaumeGomez (Dec 22 2020 at 13:46):

Ah right, if you want the field I don't know how to enforce it...

view this post on Zulip GuillaumeGomez (Dec 22 2020 at 13:46):

Maybe Foo.bar?

view this post on Zulip Joshua Nelson (Dec 22 2020 at 13:48):

@GuillaumeGomez I closed that issue, remember? https://github.com/rust-lang/rust/issues/75437

view this post on Zulip GuillaumeGomez (Dec 22 2020 at 13:48):

Now I do

view this post on Zulip GuillaumeGomez (Dec 22 2020 at 13:48):

Funny haha

view this post on Zulip GuillaumeGomez (Dec 22 2020 at 13:48):

well, any item should have a way to be enforced somehow

view this post on Zulip GuillaumeGomez (Dec 22 2020 at 13:49):

instead of "punctuation", we could maybe add specification like in rustdoc search, for example field:Foo::bar

view this post on Zulip GuillaumeGomez (Dec 22 2020 at 13:49):

but same, need an rfc I guess

view this post on Zulip Joshua Nelson (Dec 22 2020 at 13:50):

I would rather make this consistent with the other disambiguators if we do it at all

view this post on Zulip Joshua Nelson (Dec 22 2020 at 13:51):

I don't think the syntax needs to be special

view this post on Zulip Joshua Nelson (Dec 22 2020 at 13:51):

but same, need an rfc I guess

I think an FCP would be fine since it's a small change

view this post on Zulip Noah Lev (Dec 22 2020 at 23:54):

Maybe we could have special-casing for [`field@Foo::bar`] so it renders as Foo.bar?

view this post on Zulip Noah Lev (Dec 22 2020 at 23:54):

That would save a lot of doing [`Foo.bar`][field@Foo::bar].

view this post on Zulip Noah Lev (Mar 27 2021 at 01:55):

I started working on this, and I just discovered that we treat fields as if they are in the value namespace. Why is that?


Last updated: Oct 11 2021 at 22:34 UTC