Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve item transformation with special characters #13

Closed
poliorcetics opened this issue Oct 7, 2020 · 2 comments
Closed

Improve item transformation with special characters #13

poliorcetics opened this issue Oct 7, 2020 · 2 comments

Comments

@poliorcetics
Copy link
Owner

For example macros can be suffixed with !, functions and methods with () and primitives can be prefixed primitive@.

See this PR for some background.

@jyn514
Copy link
Contributor

jyn514 commented Oct 7, 2020

I wrote this up already, so pasting here:

Currently, intraconv will replace all items with only their name:

-//! [instrument]: attr.instrument.html

This leads to ambiguity if the same name is present in multiple namespaces:

warning: `instrument` is both a function and an attribute macro
 --> tracing-attributes/src/lib.rs:5:23
  |
5 | //! [`#[instrument]`][instrument] procedural macro attribute.
  |                       ^^^^^^^^^^ ambiguous link

It would be great to add a disambiguator so these didn't have to be fixed manually. The following transformations should work:

"mod" => "mod@", // this one needs to be different because of primitives
"struct" | "enum" | "trait" | "union" | "type" |  => "type@", // technically these should use struct@, etc. but it's non-idiomatic to use a lowercase name so it shouldn't come up in practice
"const" | "static" | "value" => "value@",
"fn" => "()",
"derive" | "attr" => "macro@",
"macro" => "!",

There might be more I haven't thought of but this should hit the common cases. Places to look at in rustdoc:
https://github.com/rust-lang/rust/blob/master/src/librustdoc/passes/collect_intra_doc_links.rs#L1281-L1320
https://github.com/rust-lang/rust/blob/master/src/librustdoc/formats/item_type.rs#L127-L156

@poliorcetics
Copy link
Owner Author

I just pushed a fix for it, don't hesitate to open a new issue/reopen the existing one if you find failing cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants