about summary refs log tree commit diff
path: root/src/librustdoc/passes/mod.rs
AgeCommit message (Collapse)AuthorLines
2025-09-29Move doc cfg propagation pass before items stripping passesGuillaume Gomez-2/+2
2025-05-29Rework `#[doc(cfg(..))]` checks as distinct pass in rustdocUrgau-0/+5
2024-10-14Delay ambiguous intra-doc link resolution after `Cache` has been populatedGuillaume Gomez-1/+1
2024-09-30rustdoc: rewrite stability inheritance as a passLukas Markeffsky-0/+5
2024-06-01Auto merge of #124577 - ↵bors-5/+0
GuillaumeGomez:stabilize-custom_code_classes_in_docs, r=rustdoc Stabilize `custom_code_classes_in_docs` feature Fixes #79483. This feature has been around for quite some time now, I think it's fine to stabilize it now. ## Summary ## What is the feature about? In short, this PR changes two things, both related to codeblocks in doc comments in Rust documentation: * Allow to disable generation of `language-*` CSS classes with the `custom` attribute. * Add your own CSS classes to a code block so that you can use other tools to highlight them. #### The `custom` attribute Let's start with the new `custom` attribute: it will disable the generation of the `language-*` CSS class on the generated HTML code block. For example: ```rust /// ```custom,c /// int main(void) { /// return 0; /// } /// ``` ``` The generated HTML code block will not have `class="language-c"` because the `custom` attribute has been set. The `custom` attribute becomes especially useful with the other thing added by this feature: adding your own CSS classes. #### Adding your own CSS classes The second part of this feature is to allow users to add CSS classes themselves so that they can then add a JS library which will do it (like `highlight.js` or `prism.js`), allowing to support highlighting for other languages than Rust without increasing burden on rustdoc. To disable the automatic `language-*` CSS class generation, you need to use the `custom` attribute as well. This allow users to write the following: ```rust /// Some code block with `{class=language-c}` as the language string. /// /// ```custom,{class=language-c} /// int main(void) { /// return 0; /// } /// ``` fn main() {} ``` This will notably produce the following HTML: ```html <pre class="language-c"> int main(void) { return 0; }</pre> ``` Instead of: ```html <pre class="rust rust-example-rendered"> <span class="ident">int</span> <span class="ident">main</span>(<span class="ident">void</span>) { <span class="kw">return</span> <span class="number">0</span>; } </pre> ``` To be noted, we could have written `{.language-c}` to achieve the same result. `.` and `class=` have the same effect. One last syntax point: content between parens (`(like this)`) is now considered as comment and is not taken into account at all. In addition to this, I added an `unknown` field into `LangString` (the parsed code block "attribute") because of cases like this: ```rust /// ```custom,class:language-c /// main; /// ``` pub fn foo() {} ``` Without this `unknown` field, it would generate in the DOM: `<pre class="language-class:language-c language-c">`, which is quite bad. So instead, it now stores all unknown tags into the `unknown` field and use the first one as "language". So in this case, since there is no unknown tag, it'll simply generate `<pre class="language-c">`. I added tests to cover this. EDIT(camelid): This description is out-of-date. Using `custom,class:language-c` will generate the output `<pre class="language-class:language-c">` as would be expected; it treats `class:language-c` as just the name of a language (similar to the langstring `c` or `js` or what have you) since it does not use the designed class syntax. Finally, I added a parser for the codeblock attributes to make it much easier to maintain. It'll be pretty easy to extend. As to why this syntax for adding attributes was picked: it's [Pandoc's syntax](https://pandoc.org/MANUAL.html#extension-fenced_code_attributes). Even if it seems clunkier in some cases, it's extensible, and most third-party Markdown renderers are smart enough to ignore Pandoc's brace-delimited attributes (from [this comment](https://github.com/rust-lang/rust/pull/110800#issuecomment-1522044456)). r? `@notriddle`
2024-05-11Always hide private fields in aliased typeUrgau-0/+5
2024-05-01Stabilize `custom_code_classes_in_docs` featureGuillaume Gomez-5/+0
2023-09-15Implement custom classes for rustdoc code blocks with ↵Guillaume Gomez-0/+5
`custom_code_classes_in_docs` feature
2023-09-08Reuse rustdoc's doc comment handling in ClippyAlex Macleod-91/+0
2023-02-10Resolve documentation links in rustc and store the results in metadataVadim Petrochenkov-1/+2
This commit implements MCP https://github.com/rust-lang/compiler-team/issues/584 It also removes code that is no longer used, and that includes code cloning resolver, so issue #83761 is fixed.
2022-11-22Consolidate rustdoc's lint passes into a single passNoah Lev-14/+4
This should improve performance and simplify the code.
2022-05-21Remove `crate` visibility modifier in libs, testsJacob Pratt-29/+29
2022-04-21rustdoc: Unindent doc fragments on `Attributes` constructionVadim Petrochenkov-5/+0
2022-03-01Fix panic when intra-doc link comes from a generated doc commentGuillaume Gomez-1/+1
2021-12-15rustdoc: remove `--passes` and `--no-defaults`Peter Jaszkowiak-20/+2
- flags no longer function, see #44136 - adjust tests to match new behavior - removed test issue-42875 (covered regression with --no-defaults) - moved input-format to removed flags - move all removed flags to bottom - note flag removal in command help - remove DefaultPassOption enum (now redundant with `show_coverage`)
2021-10-02rustdoc: Improve doctest pass's name and module's nameNoah Lev-4/+4
As the docs at the top of the file say, it is an overloaded pass and actually runs two lints.
2021-08-22Revert "Revert "Don't load all extern crates unconditionally""Joshua Nelson-1/+1
This reverts commit 5f0c54db4e595a6a77048f2b0605138ffa49a326.
2021-07-01Revert "Don't load all extern crates unconditionally"Guillaume Gomez-1/+1
2021-04-09Auto merge of #84030 - jyn514:no-blanket-impls, r=GuillaumeGomezbors-1/+0
rustdoc: Don't generate blanket impls when running --show-coverage `get_blanket_impls` is the slowest part of rustdoc, and the coverage pass completely ignores blanket impls. This stops running it at all, and also removes some unnecessary checks in `calculate_doc_coverage` that ignored the impl anyway. We don't currently measure --show-coverage in perf.rlo, but I tested this locally on cargo and it brought the time down from 2.9 to 1.6 seconds. This also adds back a commented-out test; Rustdoc has been able to deal with `impl trait` for almost a year now. r? `@GuillaumeGomez`
2021-04-09rustdoc: Don't generate blanket impls when running --show-coverageJoshua Nelson-1/+0
get_blanket_impls is the slowest part of rustdoc, and the coverage pass completely ignores blanket impls. This stops running it at all, and also removes some unnecessary checks in `calculate_doc_coverage` that ignored the impl anyway. We don't currently measure --show-coverage in perf.rlo, but I tested this locally on cargo and it brought the time down from 2.9 to 1.6 seconds.
2021-04-05Rename non_autolinks -> bare_urlsJoshua Nelson-4/+4
2021-04-02Don't load all extern crates unconditionallyJoshua Nelson-1/+1
Instead, only load the crates that are linked to with intra-doc links. This doesn't help very much with any of rustdoc's fundamental issues with freezing the resolver, but it at least fixes a stable-to-stable regression, and makes the crate loading model somewhat more consistent with rustc's.
2021-03-04Don't require a `DocContext` for `report_diagnostic`Joshua Nelson-2/+3
This is needed for the next commit, which needs access to the `cx` from within the `decorate` closure. - Change `as_local_hir_id` to an associated function, since it only needs a `TyCtxt` - Change `source_span_for_markdown_range` to only take a `TyCtxt`
2021-02-16Take `&mut DocContext` in passesJoshua Nelson-1/+1
This should hopefully allow for less interior mutability.
2021-01-02Remove unused collapse passGuillaume Gomez-5/+0
2020-11-15Make all rustdoc functions and structs crate-privateJoshua Nelson-30/+30
This gives warnings about dead code.
2020-11-05Rename lint to non_autolinksGuillaume Gomez-4/+4
2020-11-05Rename automatic_links to url_improvementsGuillaume Gomez-4/+4
2020-11-05Add new lint for automatic_links improvementsGuillaume Gomez-0/+5
2020-10-13Clean up rustdoc passesGuillaume Gomez-170/+4
2020-10-07Auto merge of #77119 - GuillaumeGomez:unclosed-html-tag-lint, r=jyn514bors-0/+5
Unclosed html tag lint Part of #67799. I think `@ollie27` will be interested (`@Manishearth` too since they opened the issue ;) ). r? `@jyn514`
2020-10-03Change DocFragments from enum variant fields to structs with a nested enumJoshua Nelson-7/+5
This makes the code a lot easier to work with. It also makes it easier to add new fields without updating each variant and `match` individually. - Name the `Kind` variant after `DocFragmentKind` from `collapse_docs` - Remove unneeded impls
2020-10-03Fix visitor for invalid_html_tag lintGuillaume Gomez-1/+1
2020-10-03Add `unclosed_html_tags` lintGuillaume Gomez-0/+5
2020-08-31Fix strings indentGuillaume Gomez-2/+1
2020-07-27private_items_doc_tests -> doc_test_lintsJoshua Nelson-2/+2
2020-07-27Move `look_for_tests` to `private_items_doc_tests`Joshua Nelson-55/+0
2020-07-27Separate `missing_doc_code_examples` from intra-doc linksJoshua Nelson-12/+19
These two lints have no relation other than both being nightly-only. This allows stabilizing intra-doc links without stabilizing missing_doc_code_examples.
2020-04-23Create new rustdoc lint to check for code blocks tagsGuillaume Gomez-1/+1
2020-03-30rustc -> rustc_middle part 3 (rustfmt)Mazdak Farrokhzad-1/+1
2020-03-30rustc -> rustc_middle part 2Mazdak Farrokhzad-1/+1
2020-03-16use direct imports for `rustc::{lint, session}`.Mazdak Farrokhzad-1/+1
2020-02-24don't explicitly compare against true or falseMatthias Krüger-2/+2
2020-02-11Run RustFmtjumbatm-6/+3
2020-02-11Invert control in struct_lint_level.jumbatm-6/+4
Caller now passes in a `decorate` function, which is only run if the lint is allowed.
2020-01-09Rollup merge of #67875 - dtolnay:hidden, r=GuillaumeGomezYuki Okushi-36/+51
Distinguish between private items and hidden items in rustdoc I believe rustdoc should not be conflating private items (visibility lower than `pub`) and hidden items (attribute `doc(hidden)`). This matters now that Cargo is passing --document-private-items by default for bin crates. In bin crates that rely on macros, intentionally hidden implementation details of the macros can overwhelm the actual useful internal API that one would want to document. This PR restores the strip-hidden pass when documenting private items, and introduces a separate unstable --document-hidden-items option to skip the strip-hidden pass. The two options are orthogonal to one another. Fixes #67851. Closes #60884.
2020-01-05Remove rustc_hir reexports in rustc::hir.Mazdak Farrokhzad-1/+1
2020-01-04Distinguish between private items and hidden items in rustdocDavid Tolnay-36/+51
I believe rustdoc should not be conflating private items (visibility lower than `pub`) and hidden items (attribute `doc(hidden)`). This matters now that Cargo is passing --document-private-items by default for bin crates. In bin crates that rely on macros, intentionally hidden implementation details of the macros can overwhelm the actual useful internal API that one would want to document. This PR restores the strip-hidden pass when documenting private items, and introduces a separate unstable --document-hidden-items option to skip the strip-hidden pass. The two options are orthogonal to one another.
2020-01-04DefId{Map,Set} -> rustc::hir::def_idMazdak Farrokhzad-2/+1
2020-01-01Rename `syntax_pos` to `rustc_span` in source codeVadim Petrochenkov-1/+1