about summary refs log tree commit diff
path: root/src/librustdoc/html/render/print_item.rs
AgeCommit message (Collapse)AuthorLines
2023-12-15Rollup merge of #113091 - GuillaumeGomez:prevent-cfg-merge-reexport, r=rustdocGuillaume Gomez-11/+2
Don't merge cfg and doc(cfg) attributes for re-exports Fixes #112881. ## Explanations When re-exporting things with different `cfg`s there are two things that can happen: * The re-export uses a subset of `cfg`s, this subset is sufficient so that the item will appear exactly with the subset * The re-export uses a non-subset of `cfg`s (e.g. like the example I posted just above where the re-export is ungated), if the non-subset `cfg`s are active (e.g. compiling that example on windows) then this will be a compile error as the item doesn't exist to re-export, if the subset `cfg`s are active it behaves like 1. ### Glob re-exports? **This only applies to non-glob inlined re-exports.** For glob re-exports the item may or may not exist to be re-exported (potentially the `cfg`s on the path up until the glob can be removed, and only `cfg`s on the globbed item itself matter), for non-inlined re-exports see https://github.com/rust-lang/rust/issues/85043. cc `@Nemo157` r? `@notriddle`
2023-12-04Don't generate the "Fields" heading if there is no field displayedGuillaume Gomez-1/+8
2023-12-01Add highlighting for comments in items declarationGuillaume Gomez-8/+14
2023-11-29rustdoc: remove small from `small-section-header`Michael Howell-7/+7
There's no such thing as a big section header, so I don't know why the name was used.
2023-11-29rustdoc: Move `AssocItemRender` and `RenderMode` to `html::render`.Alona Enraght-Moony-2/+3
They're only used for HTML, so it makes more sense for them to live their.
2023-11-24Replace `option.map(cond) == Some(true)` with `option.is_some_and(cond)`David Tolnay-2/+4
2023-11-23Sort unstable items last in rustdoc, instead of firstDavid Tolnay-2/+2
2023-11-23Don't print "private fields" on empty tuple structsKyuuhachi-5/+9
Test for presence rather than absence Remove redundant tests Issues in those parts will likely be caught by other parts of the test suite.
2023-11-22Don't merge cfg and doc(cfg) attributes for re-exportsGuillaume Gomez-11/+2
2023-11-15Re-format code with new rustfmtMark Rousskov-9/+11
2023-11-02Fix order of implementations in the "implementations on foreign types" sectionGuillaume Gomez-1/+2
2023-10-31Rollup merge of #113241 - poliorcetics:85138-doc-object-safety, r=GuillaumeGomezMatthias Krüger-0/+15
rustdoc: Document lack of object safety on affected traits Closes #85138 I saw the issue didn't have any recent activity, if there is another MR for it I missed it. I want the issue to move forward so here is my proposition. It takes some space just before the "Implementors" section and only if the trait is **not** object safe since it is the only case where special care must be taken in some cases and this has the benefit of avoiding generation of HTML in (I hope) the common case.
2023-10-30Move deprecation_in_effect to inherent method on DeprecationDavid Tolnay-6/+1
2023-10-29feat: Add 'object-safety' ID to init_id_map() in rustdocAlexis (Poliorcetics) Bourget-1/+2
2023-10-29feat: render Object Safety informations non-object safe traitsAlexis (Poliorcetics) Bourget-0/+14
2023-10-22rustdoc: use JS to inline target type impl docs into aliasMichael Howell-0/+98
This is an attempt to balance three problems, each of which would be violated by a simpler implementation: - A type alias should show all the `impl` blocks for the target type, and vice versa, if they're applicable. If nothing was done, and rustdoc continues to match them up in HIR, this would not work. - Copying the target type's docs into its aliases' HTML pages directly causes far too much redundant HTML text to be generated when a crate has large numbers of methods and large numbers of type aliases. - Using JavaScript exclusively for type alias impl docs would be a functional regression, and could make some docs very hard to find for non-JS readers. - Making sure that only applicable docs are show in the resulting page requires a type checkers. Do not reimplement the type checker in JavaScript. So, to make it work, rustdoc stashes these type-alias-inlined docs in a JSONP "database-lite". The file is generated in `write_shared.rs`, included in a `<script>` tag added in `print_item.rs`, and `main.js` takes care of patching the additional docs into the DOM. The format of `trait.impl` and `type.impl` JS files are superficially similar. Each line, except the JSONP wrapper itself, belongs to a crate, and they are otherwise separate (rustdoc should be idempotent). The "meat" of the file is HTML strings, so the frontend code is very simple. Links are relative to the doc root, though, so the frontend needs to fix that up, and inlined docs can reuse these files. However, there are a few differences, caused by the sophisticated features that type aliases have. Consider this crate graph: ```text --------------------------------- | crate A: struct Foo<T> | | type Bar = Foo<i32> | | impl X for Foo<i8> | | impl Y for Foo<i32> | --------------------------------- | ---------------------------------- | crate B: type Baz = A::Foo<i8> | | type Xyy = A::Foo<i8> | | impl Z for Xyy | ---------------------------------- ``` The type.impl/A/struct.Foo.js JS file has a structure kinda like this: ```js JSONP({ "A": [["impl Y for Foo<i32>", "Y", "A::Bar"]], "B": [["impl X for Foo<i8>", "X", "B::Baz", "B::Xyy"], ["impl Z for Xyy", "Z", "B::Baz"]], }); ``` When the type.impl file is loaded, only the current crate's docs are actually used. The main reason to bundle them together is that there's enough duplication in them for DEFLATE to remove the redundancy. The contents of a crate are a list of impl blocks, themselves represented as lists. The first item in the sublist is the HTML block, the second item is the name of the trait (which goes in the sidebar), and all others are the names of type aliases that successfully match. This way: - There's no need to generate these files for types that have no aliases in the current crate. If a dependent crate makes a type alias, it'll take care of generating its own docs. - There's no need to reimplement parts of the type checker in JavaScript. The Rust backend does the checking, and includes its results in the file. - Docs defined directly on the type alias are dropped directly in the HTML by `render_assoc_items`, and are accessible without JavaScript. The JSONP file will not list impl items that are known to be part of the main HTML file already. [JSONP]: https://en.wikipedia.org/wiki/JSONP
2023-10-22rustdoc: rename `/implementors` to `/impl.trait`Michael Howell-4/+4
This is shorter, avoids potential conflicts with a crate named `implementors`[^1], and will be less confusing when JS include files are added for type aliases. [^1]: AFAIK, this couldn't actually cause any problems right now, but it's simpler just to make it impossible than relying on never having a file named `trait.Foo.js` in the crate data area.
2023-10-14Rollup merge of #115439 - fmease:rustdoc-priv-repr-transparent-heuristic, ↵Matthias Krüger-12/+11
r=GuillaumeGomez rustdoc: hide `#[repr(transparent)]` if it isn't part of the public ABI Fixes #90435. This hides `#[repr(transparent)]` when the non-1-ZST field the struct is "transparent" over is private. CC `@RalfJung` Tentatively nominating it for the release notes, feel free to remove the nomination. `@rustbot` label needs-fcp relnotes A-rustdoc-ui
2023-10-11Improve code documentation a bitGuillaume Gomez-2/+2
2023-10-11Show enum discriminant if a compatible repr is usedGuillaume Gomez-10/+24
2023-10-09Improve codeGuillaume Gomez-12/+12
2023-10-07Correctly handle cross-crate C-like variantsGuillaume Gomez-20/+7
2023-10-07Only display enum variants integer values if one of them has a value setGuillaume Gomez-18/+27
2023-10-06Show values of C-like variants even if not defined by the userGuillaume Gomez-22/+90
2023-09-25Show enum variant value if it is a C-like variantGuillaume Gomez-2/+14
2023-09-18rustdoc: hide repr(transparent) if it isn't part of the public ABILeón Orell Valerian Liehr-12/+11
2023-09-08Rollup merge of #115604 - GuillaumeGomez:private-fields-tuple-struct, ↵Matthias Krüger-14/+30
r=notriddle rustdoc: Render private fields in tuple struct as `/* private fields */` Reopening of https://github.com/rust-lang/rust/pull/110552. All that was missing was a test for the different cases so I added it into the second commit. Description from the original PR: > I've gotten some feedback that the current rustdoc rendering of... > > ``` > struct HasPrivateFields(_); > ``` > > ...is confusing, and I agree with that feedback, especially compared to the field struct case: > > ``` > struct HasPrivateFields { /* private fields */ } > ``` > > So this PR makes it so that when all of the fields of a tuple variant are private, just render it with the `/* private fields */` comment. We can't *always* render it like that, for example when there's a mix of private and public fields. cc ````@jsha```` r? ````@notriddle````
2023-09-06Render missing fields in tuple struct/enum as /* private fields */Michael Goulet-14/+30
2023-08-28rustdoc: always print type alias inner type (with it's where clauses)Urgau-4/+13
2023-08-26rustdoc: remove details for type alias inner type and fix sidebarUrgau-92/+51
2023-08-26rustdoc: bind typedef inner type items to the folding systemUrgau-13/+20
This let's us handle a multitude of things for free: - #[doc(hidden)] - private fields/variants - --document-private-items - --document-hidden-items And correct in the process the determination of "has stripped items" by doing the same logic done by other ones.
2023-08-26rustdoc: show inner enum and struct in type definition for concrete typeUrgau-0/+94
2023-08-24rustdoc: extract logic for printing enum fields and struct variantsUrgau-131/+195
2023-08-21rustdoc: Rename `clean` items from typedef to type aliasNoah Lev-5/+5
2023-08-21rustdoc: Rename "Type Definition" to "Type Alias"Noah Lev-1/+1
This matches the name used by the Rust Reference [1], which is also what people usually call these items. [1]: https://doc.rust-lang.org/reference/items/type-aliases.html
2023-08-16Use more named format argsGuillaume Gomez-12/+18
2023-08-16Improve code readability by moving fmt args directly into the stringGuillaume Gomez-49/+41
2023-07-30Remove some unneeded `clone()` callsGuillaume Gomez-1/+1
2023-07-28Render generic const items in rustdocLeón Orell Valerian Liehr-1/+3
2023-06-12Revert "List matching impls on type aliases"Guillaume Gomez-32/+16
This reverts commit 4b1d13d9841c815915433ca2a3088a8e3e97ad96.
2023-06-11Add `item_template` macroNicky Lim-57/+116
2023-06-09List matching impls on type aliasesGuillaume Gomez-16/+32
2023-06-08Rollup merge of #112034 - sladyn98:migrate-opaque-ty, r=GuillaumeGomezGuillaume Gomez-3/+10
Migrate `item_opaque_ty` to Askama This PR migrates `item_opaque_ty` to Askama Refers: https://github.com/rust-lang/rust/issues/108868
2023-06-08Migrate item_opaque_type to Askamasladynnunes-3/+10
Migrate item_opaque_type to Askama Fix wrap_item parameters Fix to write
2023-06-05Rollup merge of #112243 - GuillaumeGomez:rm-unneeded-buffer-creations, ↵Guillaume Gomez-21/+16
r=notriddle Remove unneeded `Buffer` allocations when `&mut fmt::Write` can be used directly With the recent changes, `wrap_item` can now directly take `&mut Write`, which makes some `Buffer` creations unneeded. r? `@notriddle`
2023-06-05Move write! arguments directly into the stringGuillaume Gomez-4/+4
2023-06-03Remove unneeded `Buffer` allocations when `&mut fmt::Write` can be used directlyGuillaume Gomez-21/+16
2023-06-03Auto merge of #112032 - sladyn98:migrate-item-primitive, r=GuillaumeGomezbors-3/+3
Migrate `item_primitive` to Askama This PR migrates `item_primitive` to Askama Refers https://github.com/rust-lang/rust/issues/108868
2023-06-01Rollup merge of #112030 - sladyn98:item-trait-alias, r=GuillaumeGomezMichael Goulet-8/+15
Migrate `item_trait_alias` to Askama This PR migrates `item_trait_alias` to Askama Refers https://github.com/rust-lang/rust/issues/108868
2023-06-01Migrate to Askamasladynnunes-8/+15
Implemented wrap_item_write Update wrap_item