summary refs log tree commit diff
path: root/src/librustdoc
AgeCommit message (Collapse)AuthorLines
2020-09-17Ignore rustc_private items from std docsLzu Tao-9/+10
Apply suggestions from code review Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-28Fix swapped stability attributesJoshua Nelson-6/+6
This fixes a regression introduced in https://github.com/rust-lang/rust/pull/74855.
2020-08-25Auto merge of #75666 - davidtwco:tidy-lang-items, r=varkorbors-7/+7
hir: consistent use and naming of lang items This PR adjusts the naming of various lang items so that they are consistent and don't include prefixes containing the target or "LangItem". In addition, lang item variants are no longer exported from the `lang_items` module. This is certainly subjective and while I think this is an improvement, if many in the team don't then we can just close this.
2020-08-24Auto merge of #74590 - jyn514:timing, r=Mark-Simulacrumbors-186/+216
Add some timing info to rustdoc There are various improvements, but the main one is to time each pass that rustdoc performs (`rustdoc::passes`). Before, these were the top five timings for `cargo doc` on the cargo repository: ``` +---------------------------------+-----------+-----------------+----------+------------+ | Item | Self time | % of total time | Time | Item count | +---------------------------------+-----------+-----------------+----------+------------+ | <unknown> | 854.70ms | 20.888 | 2.47s | 744823 | +---------------------------------+-----------+-----------------+----------+------------+ | expand_crate | 795.29ms | 19.436 | 848.00ms | 1 | +---------------------------------+-----------+-----------------+----------+------------+ | metadata_decode_entry | 256.73ms | 6.274 | 279.49ms | 518344 | +---------------------------------+-----------+-----------------+----------+------------+ | resolve_crate | 240.56ms | 5.879 | 242.86ms | 1 | +---------------------------------+-----------+-----------------+----------+------------+ | hir_lowering | 146.79ms | 3.587 | 146.79ms | 1 | +---------------------------------+-----------+-----------------+----------+------------+ ``` Now the timings are: ``` +---------------------------------+-----------+-----------------+----------+------------+ | Item | Self time | % of total time | Time | Item count | +---------------------------------+-----------+-----------------+----------+------------+ | <unknown> | 1.40s | 22.662 | 3.73s | 771430 | +---------------------------------+-----------+-----------------+----------+------------+ | collect-trait-impls | 1.34s | 21.672 | 2.87s | 1 | +---------------------------------+-----------+-----------------+----------+------------+ | expand_crate | 1.21s | 19.577 | 1.28s | 1 | +---------------------------------+-----------+-----------------+----------+------------+ | build extern trait impl | 704.66ms | 11.427 | 1.07s | 21893 | +---------------------------------+-----------+-----------------+----------+------------+ | metadata_decode_entry | 354.84ms | 5.754 | 391.81ms | 544919 | +---------------------------------+-----------+-----------------+----------+------------+ ``` The goal is to help me debug regressions like https://github.com/rust-lang/rust/pull/74518#issuecomment-661498214 (currently I have _no_ idea what could have gone wrong). r? @eddyb or @Mark-Simulacrum
2020-08-24hir: consistent use and naming of lang itemsDavid Wood-7/+7
This commit adjusts the naming of various lang items so that they are consistent and don't include prefixes containing the target or "LangItem". In addition, lang item variants are no longer exported from the `lang_items` module. Signed-off-by: David Wood <david@davidtw.co>
2020-08-23Fix bad rebaseJoshua Nelson-164/+164
Had to use -Xignore-whitespace-conflicts to avoid awful conflicts, but that threw off the indentation
2020-08-23Use underscores instead of spacesJoshua Nelson-7/+7
2020-08-23Time how long it takes to render HTMLJoshua Nelson-8/+11
2020-08-23xpy fmtJoshua Nelson-12/+25
2020-08-23Time running the global contextJoshua Nelson-1/+1
2020-08-23Separate `run_global_ctxt` into a separate functionJoshua Nelson-8/+14
2020-08-23Remove redundant timing for queryJoshua Nelson-3/+1
2020-08-23Time loading all crates, not each individual crateJoshua Nelson-2/+2
2020-08-23Add some timing info to rustdocJoshua Nelson-5/+15
There are various improvements, but the main one is to time each pass that rustdoc performs (`rustdoc::passes`). Before, these were the top five timings for `cargo doc` on the cargo repository: ``` +---------------------------------+-----------+-----------------+----------+------------+ | Item | Self time | % of total time | Time | Item count | +---------------------------------+-----------+-----------------+----------+------------+ | <unknown> | 854.70ms | 20.888 | 2.47s | 744823 | +---------------------------------+-----------+-----------------+----------+------------+ | expand_crate | 795.29ms | 19.436 | 848.00ms | 1 | +---------------------------------+-----------+-----------------+----------+------------+ | metadata_decode_entry | 256.73ms | 6.274 | 279.49ms | 518344 | +---------------------------------+-----------+-----------------+----------+------------+ | resolve_crate | 240.56ms | 5.879 | 242.86ms | 1 | +---------------------------------+-----------+-----------------+----------+------------+ | hir_lowering | 146.79ms | 3.587 | 146.79ms | 1 | +---------------------------------+-----------+-----------------+----------+------------+ ``` Now the timings are: ``` +---------------------------------+-----------+-----------------+----------+------------+ | Item | Self time | % of total time | Time | Item count | +---------------------------------+-----------+-----------------+----------+------------+ | <unknown> | 1.40s | 22.662 | 3.73s | 771430 | +---------------------------------+-----------+-----------------+----------+------------+ | collect-trait-impls | 1.34s | 21.672 | 2.87s | 1 | +---------------------------------+-----------+-----------------+----------+------------+ | expand_crate | 1.21s | 19.577 | 1.28s | 1 | +---------------------------------+-----------+-----------------+----------+------------+ | build extern trait impl | 704.66ms | 11.427 | 1.07s | 21893 | +---------------------------------+-----------+-----------------+----------+------------+ | metadata_decode_entry | 354.84ms | 5.754 | 391.81ms | 544919 | +---------------------------------+-----------+-----------------+----------+------------+ ```
2020-08-23xpy fmtJoshua Nelson-7/+2
2020-08-23Report an ambiguity if both modules and primitives are in scopeJoshua Nelson-43/+109
- Add a new `prim@` disambiguator, since both modules and primitives are in the same namespace - Refactor `report_ambiguity` into a closure Additionally, I noticed that rustdoc would previously allow `[struct@char]` if `char` resolved to a primitive (not if it had a DefId). I fixed that and added a test case.
2020-08-23Auto merge of #74489 - jyn514:assoc-items, r=manishearth,petrochenkovbors-93/+227
Fix intra-doc links for associated items @Manishearth and I found that links of the following sort are broken: ```rust $ cat str_from.rs /// [`String::from`] pub fn foo() {} $ rustdoc str_from.rs warning: `[String::from]` cannot be resolved, ignoring it. --> str_from.rs:4:6 | 4 | /// [`String::from`] | ^^^^^^^^^^^^^^ cannot be resolved, ignoring ``` It turns out this is because the current implementation only looks at inherent impls (`impl Bar {}`) and traits _for the item being documented_. Note that this is not the same as the item being _linked_ to. So this code would work: ```rust pub trait T1 { fn method(); } pub struct S; impl T1 for S { /// [S::method] on method fn method() {} } ``` but putting the documentation on `trait T1` would not. ~~I realized that writing it up that my fix is only partially correct: It removes the inherent impls code when it should instead remove the `trait_item` code.~~ Fixed. Additionally, I discovered while writing this there is some ambiguity: you could have multiple methods with the same name, but for different traits: ```rust pub trait T1 { fn method(); } pub trait T2 { fn method(); } /// See [S::method] pub struct S; ``` Rustdoc should give an ambiguity error here, but since there is currently no way to disambiguate the traits (https://github.com/rust-lang/rust/issues/74563) it does not (https://github.com/rust-lang/rust/pull/74489#issuecomment-673878404). There is a _third_ ambiguity that pops up: What if the trait is generic and is implemented multiple times with different generic parameters? In this case, my fix does not do very well: it thinks there is only one trait instantiated and links to that trait: ``` /// [`String::from`] -- this resolves to https://doc.rust-lang.org/nightly/alloc/string/struct.String.html#method.from pub fn foo() {} ``` However, every `From` implementation has a method called `from`! So the browser picks a random one. This is not the desired behavior, but it's not clear how to avoid it. To be consistent with the rest of intra-doc links, this only resolves associated items from traits that are in scope. This required changes to rustc_resolve to work cross-crate; the relevant commits are prefixed with `resolve: `. As a bonus, considering only traits in scope is slightly faster. To avoid re-calculating the traits over and over, rustdoc uses a cache to store the traits in scope for a given module.
2020-08-23Auto merge of #74238 - RalfJung:offset_from, r=oli-obkbors-1/+0
stabilize ptr_offset_from This stabilizes ptr::offset_from, and closes https://github.com/rust-lang/rust/issues/41079. It also removes the deprecated `wrapping_offset_from`. This function was deprecated 19 days ago and was never stable; given an FCP of 10 days and some waiting time until FCP starts, that leaves at least a month between deprecation and removal which I think is fine for a nightly-only API. Regarding the open questions in https://github.com/rust-lang/rust/issues/41079: * Should offset_from abort instead of panic on ZSTs? -- As far as I know, there is no precedent for such aborts. We could, however, declare this UB. Given that the size is always known statically and the check thus rather cheap, UB seems excessive. * Should there be more methods like this with different restrictions (to allow nuw/nsw, perhaps) or that return usize (like how isize-taking offset is more conveniently done with usize-taking add these days)? -- No reason to block stabilization on that, we can always add such methods later. Also nominating the lang team because this exposes an intrinsic. The stabilized method is best described [by its doc-comment](https://github.com/RalfJung/rust/blob/56d4b2d69abb93e4f0ca79471deca7aaaaeca214/src/libcore/ptr/const_ptr.rs#L227). The documentation forgot to mention the requirement that both pointers must "have the same provenance", aka "be derived from pointers to the same allocation", which I am adding in this PR. This is a precondition that [Miri already implements](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=a3b9d0a07a01321f5202cd99e9613480) and that, should LLVM ever obtain a `psub` operation to subtract pointers, will likely be required for that operation (following the semantics in [this paper](https://people.mpi-sws.org/~jung/twinsem/twinsem.pdf)).
2020-08-22Lazy decoding of DefPathTable from crate metadata (non-incremental case)Aaron Hill-4/+4
2020-08-22stabilize ptr_offset_fromRalf Jung-1/+0
2020-08-22Auto merge of #75776 - ↵bors-22/+20
GuillaumeGomez:missing-doc-examples-lint-improvements, r=jyn514 Missing doc examples lint improvements Fixes #75719. To be merged after #75718 (only the two last commits are from this PR). Since you already reviewed #75718, I'll set you as reviewer here as well. :) r? @jyn514
2020-08-22rustdoc: Only resolve traits in scopeJoshua Nelson-17/+22
2020-08-22rustdoc: Cache traits implemented by a typeJoshua Nelson-45/+65
This avoids taking the slow path several thousand times in a row. - Fallback to all traits if the traits in scope are unknown - Use a rustdoc thread_local cache instead of a query The set of traits implemented by a type is not stable across crates: there could be new traits added in a new crate. - Use DocContext instead of a thread-local
2020-08-22rustdoc: Add support for associated items even outside the impl itselfJoshua Nelson-89/+198
Previously, associated items would only be available for linking directly on the `impl Trait for Type`. Now they can be used anywhere. - Make `item` for resolve mandatory - Refactor resolving associated items into a separate function - Remove broken trait_item logic - Don't skip the type namespace for associated items - Only call `variant_field` for `TypeNS` - Add test for associated items - Use exhaustive matches instead of wildcards Wildcards caused several bugs while implementing this.
2020-08-22rustdoc: Rename misleading functionJoshua Nelson-2/+2
- `is_associated` -> `is_type_alias` `is_associated` is not a good name for what this is doing. If you look at https://github.com/rust-lang/rust/pull/74489/files#diff-6a301d597807ee441a41e7237800563dR296, is_associated() and as_assoc_kind() do completely different things, but from the name it sounds like they're similar.
2020-08-22Rollup merge of #75745 - jyn514:refactor-resolve, r=ManishearthDylan DPC-23/+1
Remove duplication in `fold_item` r? @Manishearth
2020-08-21Unify checks for lint missing_doc_code_examples and --show-coverageGuillaume Gomez-22/+20
2020-08-21Show line even if there is no code examplesGuillaume Gomez-5/+3
2020-08-21Ignore more kind of items for doc examplesGuillaume Gomez-0/+4
2020-08-20fmtGuillaume Gomez-11/+2
2020-08-20Update how doc examples are countedGuillaume Gomez-18/+16
2020-08-20Remove "total" columns in --show-coverage outputGuillaume Gomez-6/+5
2020-08-20Remove duplicate binding in matchJoshua Nelson-1/+1
Co-authored-by: lzutao <taolzu@gmail.com>
2020-08-20Update rustdoc coverage UI testGuillaume Gomez-5/+11
2020-08-20Ignore code examples on given items where it doesn't make senseGuillaume Gomez-19/+40
2020-08-20Remove duplication in `fold_item`Joshua Nelson-23/+1
2020-08-19Rollup merge of #75649 - jyn514:inherent-lang-impls, r=guillaumegomezTyler Mandry-97/+110
Fix intra-doc links for inherent impls that are both lang items and not the default impl I found in https://github.com/rust-lang/rust/pull/75464#issuecomment-675125984 that `str::to_uppercase()` doesn't resolve while `str::trim()` does. The only real difference is that `to_uppercase` is defined in `alloc`, while trim is defined in `core`. It turns out that rustdoc was ignoring `lang_items.str_alloc_impl()` - it saw them in `collect_trait_impls`, but not for intra-doc links. This uses the same `impls` for all parts of rustdoc, so that there can be no more inconsistency. It does have the slight downside that the matches are no longer exhaustive but it will be very clear if a new lang item is missed because it will panic when you try to document it (and if you don't document it, does rustdoc really need to know about it?). ~~This needs a test case (probably just `str::to_uppercase`).~~ Added. This is best reviewed commit-by-commit. r? @GuillaumeGomez
2020-08-19Auto merge of #74098 - GuillaumeGomez:doc-alias-checks, r=ollie27bors-0/+4
Doc alias checks: ensure only items appearing in search index can use it Following the discussion in #73721, I added checks to ensure that only items appearing in the search are allowed to have doc alias. r? @ollie27
2020-08-19xpy fmtJoshua Nelson-5/+11
2020-08-19Use `impls` for intra doc links as wellJoshua Nelson-35/+19
2020-08-19Allow reusing the code in `collect_trait_impls`Joshua Nelson-87/+80
2020-08-19impl_for_type -> PrimitiveType::implsJoshua Nelson-57/+59
2020-08-19Return all impls, not just the primary oneJoshua Nelson-10/+32
2020-08-19Say `tcx.lang_items()` lessJoshua Nelson-20/+21
2020-08-19Refactor `impl_for_type` into a separate functionJoshua Nelson-29/+34
2020-08-19Rollup merge of #75665 - GuillaumeGomez:doc-examples-coverage, r=jyn514Yuki Okushi-26/+88
Add doc examples coverage r? @jyn514
2020-08-19Rollup merge of #75652 - jyn514:true-false-2, r=GuillaumeGomezYuki Okushi-7/+18
Resolve true and false as booleans Successor to https://github.com/rust-lang/rust/pull/75101. r? @Manishearth cc @rust-lang/rustdoc
2020-08-18Add doc examples count for --show-coverageGuillaume Gomez-26/+88
2020-08-17Resolve true and false as booleansJoshua Nelson-7/+18
2020-08-17Auto merge of #75120 - JulianKnodt:rm_reps, r=oli-obkbors-24/+24
rust_ast::ast => rustc_ast Rework of #71199 which is a rework #70621 Still working on this but just made the PR to track progress r? @Dylan-DPC