Skip to content

Commit fd70ea3

Browse files
authored
Merge pull request #2285 from Manishearth/intra-rustdoc-links-update
Update the disambiguation handling in RFC 1946 (intra-rustdoc-links) to match impl concerns
2 parents 6166408 + 0b17ddf commit fd70ea3

File tree

1 file changed

+44
-23
lines changed

1 file changed

+44
-23
lines changed

text/1946-intra-rustdoc-links.md

+44-23
Original file line numberDiff line numberDiff line change
@@ -284,29 +284,51 @@ To be able to link to each item,
284284
we'll need a way to disambiguate the namespaces.
285285
Our proposal is this:
286286

287-
- Links to types are written as described earlier,
288-
with no pre- or suffix,
289-
e.g., `Look at the [FOO] trait`.
290-
For consistency,
291-
it is also possible to prefix the type with the concrete item type:
292-
- Links to `struct`s can be prefixed with `struct `,
293-
e.g., `See [struct Foo]`.
294-
- Links to `enum`s can be prefixed with `enum `,
295-
e.g., `See [enum foo]`.
296-
- Links to type aliases can be prefixed with `type `,
297-
e.g., `See [type foo]`.
298-
- Links to modules can be prefixed with `mod `,
299-
e.g., `See [mod foo]`.
287+
- In unambiguous cases paths can be written as described earlier,
288+
with no pre- or suffix, e.g., `Look at the [FOO] trait`. This also
289+
applies to modules and tuple structs which exist in both namespaces.
290+
Rustdoc will throw an error if you use a non-disambiguated path in
291+
the case of there being a value in both the type and value namespace.
292+
- Links to types can be disambiguated by prefixing them with the concrete
293+
item type:
294+
- Links to any type-namespace object can be prefixed with `type@`,
295+
e.g., `See [type@foo]`. This will work for structs, enums, mods, traits,
296+
and unions.
297+
- Links to `struct`s can be prefixed with `struct@`,
298+
e.g., `See [struct@Foo]`.
299+
- Links to `enum`s can be prefixed with `enum@`,
300+
e.g., `See [enum@foo]`.
301+
- Links to modules can be prefixed with `mod@`,
302+
e.g., `See [mod@foo]`.
303+
- Links to traits can be prefixed with `trait@`,
304+
e.g., `See [trait@foo]`.
305+
- Links to unions can be prefixed with `union@`,
306+
e.g., `See [union@foo]`.
307+
- It is possible that disambiguators for one kind of type-namespace object
308+
will work for the other (i.e. you can use `struct@` to refer to an enum),
309+
but do not rely on this.
310+
- Modules exist in both the type and value namespace and can be disambiguated
311+
with a `mod@` or `module@`, e.g. `[module@foo]`
300312
- In links to macros,
301-
the link label must end with a `!`,
302-
e.g., `Look at the [FOO!] macro`.
303-
- For links to values, we differentiate three cases:
304-
- Links to functions are written with a `()` suffix,
305-
e.g., `Also see the [foo()] function`.
306-
- Links to constants are prefixed with `const `,
307-
e.g., `As defined in [const FOO].`
308-
- Links to statics are prefixed with `static `,
309-
e.g., `See [static FOO]`.
313+
the link label can end with a `!`,
314+
e.g., `Look at the [FOO!] macro`. You can alternatively use a `macro@` prefix,
315+
e.g. `[macro@foo]`
316+
- For disambiguating links to values, we differentiate three cases:
317+
- Links to any kind of value (function, const, static) can be prefixed with `value@`,
318+
e.g., `See [value@foo]`.
319+
- Links to functions and methods can be written with a `()` suffix,
320+
e.g., `Also see the [foo()] function`. You can also use `function@`, `fn@`,
321+
or `method@`.
322+
- Links to constants are prefixed with `const@`,
323+
e.g., `As defined in [const@FOO].`
324+
- Links to statics are prefixed with `static@`,
325+
e.g., `See [static@FOO]`.
326+
- It is possible that disambiguators for one kind of type-namespace object
327+
will work for the other (i.e. you can use `static@` to refer to a const),
328+
329+
For disambiguation markers using an `@`, in implied shortcut links
330+
you can use a space instead of the `@`. In other words, `[struct Foo]`
331+
is fine (and preferred).
310332

311333
It should be noted that in the RFC discussion it was determined
312334
that exact knowledge of the item type
@@ -317,7 +339,6 @@ with the wrong prefix that is in the same namespace.
317339
E.g., given an `struct Foo`, it may be possible to link to it using `[enum Foo]`,
318340
or, given a `mod bar`, it may be possible to link to that using `[struct bar]`.
319341

320-
321342
## Errors
322343
[errors]: #errors
323344

0 commit comments

Comments
 (0)