| Age | Commit message (Collapse) | Author | Lines |
|
|
|
|
|
|
|
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
|
|
|
|
|
|
Keep ids of the documented items themselves, not their parent modules.
Parent modules can be retreived from those ids when necessary.
|
|
This trait was a way to generalize over both `TyCtxt` and `Resolver`, but now `Resolver` has access to `TyCtxt`, so this trait is no longer necessary.
|
|
in metadata
|
|
|
|
|
|
|
|
Not all uses are converted, a few cases iterating through maps/sets and requiring nontrivial changes are kept.
|
|
errors before this pass
|
|
|
|
This reduces ItemKind size from 224 bytes to 160 bytes.
|
|
r=GuillaumeGomez
rustdoc: avoid including impl blocks with filled-in generics
Fixes #94937
# Before

# After

|
|
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
|
|
|
|
Fixes #94937
|
|
|
|
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.
Same applies to `local_parent`/`opt_local_parent`.
|
|
|
|
This change makes it so that local impls count when listing primitives that
need retained.
|
|
This improves the accuracy of libcore primitive docs, which was missing the
blanket and auto impls for most primitive types. To test this, compare nightly
[libcore::str] docs, which lack auto traits like Send, with [std::str] docs,
which show them.
[libcore::str]: https://doc.rust-lang.org/nightly/core/primitive.str.html
[libstd::str]: https://doc.rust-lang.org/nightly/std/primitive.str.html
It also avoids getting synthetic impls for primitive types on crates that
do not actually show them.
<details>
<summary>Before and After trace logs</summary>
Before:
[notriddle@deep-thought test-dingus]$ RUSTDOC_LOG=rustdoc=trace rustdoc +nightly test.rs 2>&1 | grep -E 'get_blanket_impls\('
TRACE rustdoc::clean::blanket_impl get_blanket_impls(Whatever)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(isize)
TRACE rustdoc::clean::blanket_impl get_blanket_impls([T])
TRACE rustdoc::clean::blanket_impl get_blanket_impls([u8])
TRACE rustdoc::clean::blanket_impl get_blanket_impls([T])
TRACE rustdoc::clean::blanket_impl get_blanket_impls([u8])
TRACE rustdoc::clean::blanket_impl get_blanket_impls(char)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(u128)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(u16)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(i128)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(i16)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(str)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(str)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(f64)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(f64)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(u64)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(u8)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(i64)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(i8)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(*const T)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(*mut T)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(*const [T])
TRACE rustdoc::clean::blanket_impl get_blanket_impls(*mut [T])
TRACE rustdoc::clean::blanket_impl get_blanket_impls([T; N])
TRACE rustdoc::clean::blanket_impl get_blanket_impls(bool)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(f32)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(f32)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(u32)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(usize)
TRACE rustdoc::clean::blanket_impl get_blanket_impls(i32)
After:
[notriddle@deep-thought test-dingus]$ RUSTDOC_LOG=rustdoc=trace rustdoc +dev test.rs 2>&1 | grep -E 'get_blanket_impls\('
TRACE rustdoc::clean::blanket_impl get_blanket_impls(Whatever)
</details>
|
|
|
|
|
|
|
|
remove the definition of def_id_no_primitives and change;
a missing use was modified;
narrow the Cache accessibility of BadImplStripper;
|
|
|
|
|
|
resolution and later passes
|
|
|
|
|
|
These are currently documented at
https://rustc-dev-guide.rust-lang.org/rustdoc-internals.html#hot-potato
but can easily go out of date. We'd like to document them in place and
link to
https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/passes/index.html
|
|
rustdoc: use Type::def_id() instead of Type::def_id_no_primitives()
For: #90187
r? `@jyn514`
|
|
This change has two advantages:
1. It makes the possible states clearer, and it makes it impossible to
construct invalid states, such as a blanket impl that is also an auto
trait impl.
2. It shrinks the size of `Impl` a bit, since now there is only one
field, rather than two.
|
|
Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
|
|
|
|
I think these are the last of the impls that can be easily converted to visitors.
|
|
Show all Deref implementations recursively
Fixes #87783.
This is a re-implementation of #80653, so taking the original PR comment:
This changes `rustdoc` to recursively follow `Deref` targets so that methods from all levels are added to the rendered output. This implementation displays the methods from all levels in the expanded state with separate sections for each level.

cc `@camelid`
r? `@jyn514`
|
|
|
|
|
|
|
|
Before, it was only measuring one callsite of `build_impl`, and it
incremented the call count even if `build_impl` returned early because
the `did` was already inlined.
Now, it measures all calls, minus calls that return early.
|
|
It should be preferred over `def_id_no_primitives()`, so it should have
a shorter name. I also put it before `def_id_no_primitives()` so that it
shows up first in the docs.
|
|
The old name was confusing because it's easy to assume that using
`def_id()` is fine, but in some situations it's incorrect. In general,
`def_id_full()` should be preferred, so `def_id_full()` should have a
shorter name. That will happen in the next commit.
|
|
In general, it should be preferred over `Type::def_id()`. See each
method's docs for more.
|
|
|
|
|