Commit graph

204 commits

Author SHA1 Message Date
Urgau af6889c28c rustdoc: bind typedef inner type items to the folding system
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-26 00:15:02 +02:00
Urgau 6b3bba8c3e rustdoc: handle typedef inner type when doing cross-crate inlining 2023-08-26 00:15:02 +02:00
Urgau 2c35abe37c rustdoc: show inner enum and struct in type definition for concrete type 2023-08-26 00:14:49 +02:00
bors 9bd60a60ce Auto merge of #115078 - camelid:tydef-to-alias, r=aDotInTheVoid,GuillaumeGomez
rustdoc: Rename typedef to type alias

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

r? `@GuillaumeGomez`
2023-08-24 04:13:28 +00:00
Guillaume Gomez 5cbc00fb7e
Rollup merge of #115135 - GuillaumeGomez:no-html-source-flag, r=notriddle
Rustdoc: Add unstable --no-html-source flag

Fixes https://github.com/rust-lang/rust/issues/115060.

This is the equivalent of `#![doc(no_html_source)]` but on the command-line. It disables the generation of the source pages (and of the links pointing to them as well).

The motivation behind this is to enable to reduce documentation size when generating it in some locations without enforcing this to end users or adding a new feature to enable/disable the crate attribute.

r? `@notriddle`
2023-08-23 17:46:35 +02:00
Guillaume Gomez d3f35e96c1 Add test for --no-html-source flag 2023-08-23 15:54:04 +02:00
Noah Lev ea9e442222 rustdoc: Rename "Type Definition" to "Type Alias"
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-21 12:53:39 -07:00
Kyle Lin 0e2f2cccd7 Add check-pass tests and fix test behavior 2023-08-18 15:19:18 +08:00
Kyle Lin 5ce6cc7df3 Still resolving rustdoc resolution panicking 2023-08-18 15:19:17 +08:00
Matthias Krüger 5ea536b35f
Rollup merge of #114253 - fmease:compute-variances-for-lazy-ty-aliases, r=oli-obk
Compute variances for lazy type aliases

Fixes #114221.

CC ``@oli-obk``
r? types
2023-08-04 09:18:58 +02:00
Nilstrieb 5830ca216d Add internal_features lint
It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
2023-08-03 14:50:50 +02:00
León Orell Valerian Liehr 6f5d8556ca
Handle inherent associated types fallout 2023-08-03 02:18:52 +02:00
Michael Goulet 4b58ae0bb8 Mark lazy_type_alias as incomplete 2023-07-29 19:47:15 +00:00
León Orell Valerian Liehr 203d400668
Add rustdoc tests for generic const items 2023-07-28 22:23:21 +02:00
bors 9339f446a5 Auto merge of #113374 - GuillaumeGomez:private-to-public-path, r=notriddle,fmease
[rustdoc] If re-export is private, get the next item until a public one is found or expose the private item directly

Fixes #81141.

If we have:

```rust
use Private as Something;

pub fn foo() -> Something {}
```

Then `Something` will be replaced by `Private`.

r? `@notriddle`
2023-07-27 15:56:50 +00:00
Guillaume Gomez 1fa0c4db4f
Rollup merge of #114059 - fmease:rustdoc-fix-x-crate-impl-sized, r=GuillaumeGomez
rustdoc: fix cross-crate `impl Sized` & `impl ?Sized`

Previously, cross-crate impl-Trait (APIT, RPIT, etc.) that only consists of a single `Sized` bound (modulo outlives-bounds) and ones that are `?Sized` were incorrectly rendered. To give you a taste (before vs. after):

```diff
- fn sized(x: impl ) -> impl
+ fn sized(x: impl Sized) -> impl Sized

- fn sized_outlives<'a>(x: impl 'a) -> impl 'a
+ fn sized_outlives<'a>(x: impl Sized + 'a) -> impl Sized + 'a

- fn maybe_sized(x: &impl ) -> &impl
+ fn maybe_sized(x: &impl ?Sized) -> &impl ?Sized

- fn debug_maybe_sized(x: &impl Debug) -> &impl ?Sized + Debug
+ fn debug_maybe_sized(x: &(impl Debug + ?Sized)) -> &(impl Debug + ?Sized)
```

Moreover, we now surround impl-Trait that has multiple bounds with parentheses if they're the pointee of a reference or raw pointer type. This affects both local and cross-crate docs. The current output isn't correct (rustc would emit the error *ambiguous `+` in a type* if we fed the rendered code back to it).

---

Best reviewed commit by commit :)

`@rustbot` label A-cross-crate-reexports
2023-07-27 16:05:13 +02:00
bors 6908c73ab0 Auto merge of #114012 - GuillaumeGomez:fix-113982, r=notriddle
Fix missing attribute merge on glob foreign re-exports

Fixes https://github.com/rust-lang/rust/issues/113982.

The attributes were not merged with the import's in case of glob re-export of foreign items.

r? `@notriddle`
2023-07-26 17:35:51 +00:00
Guillaume Gomez 51eb0c3b36 Fix regression for private in public 2023-07-26 15:29:45 +02:00
León Orell Valerian Liehr 28d40f1959
rustdoc: fix cross-crate impl-Sized 2023-07-26 02:11:35 +02:00
bors beef07fe8f Auto merge of #113958 - lukas-code:doc-links, r=GuillaumeGomez,petrochenkov
fix intra-doc links on nested `use` and `extern crate` items

This PR fixes two rustdoc ICEs that happen if there are any intra-doc links on nested `use` or `extern crate` items, for example:
```rust
/// Re-export [`fmt`] and [`io`].
pub use std::{fmt, io}; // "nested" use = use with braces

/// Re-export [`std`].
pub extern crate std;
```

Nested use items were incorrectly considered private and therefore didn't have their intra-doc links resolved. I fixed this by always resolving intra-doc links for nested `use` items that are declared `pub`.

<details>

During AST->HIR lowering, nested `use` items are desugared like this:
```rust
pub use std::{}; // "list stem"
pub use std::fmt;
pub use std::io;
```
Each of these HIR nodes has it's own effective visibility and the list stem is always considered private.
To check the effective visibility of an AST node, the AST node is mapped to a HIR node with `Resolver::local_def_id`, which returns the (private) list stem for nested use items.

</details>

For `extern crate`, there was a hack in rustdoc that stored the `DefId` of the crate itself in the cleaned item, instead of the `DefId` of the `extern crate` item. This made rustdoc look at the resolved links of the extern crate's crate root instead of the `extern crate` item. I've removed this hack and instead translate the `DefId` in the appropriate places.

As as side effect of fixing `extern crate`, i've turned
```rust
#[doc(masked)]
extern crate self as _;
```
into a no-op instead of hiding all trait impls. Proper verification for `doc(masked)` is included as a bonus.

fixes https://github.com/rust-lang/rust/issues/113896
2023-07-25 01:35:53 +00:00
Guillaume Gomez 95cea621cd Add regression test for generics reexport of private import 2023-07-24 17:07:57 +02:00
Guillaume Gomez 5859b44e97 Add test for --document-hidden-items 2023-07-24 17:07:57 +02:00
Guillaume Gomez 298cd366d5 Add test for private items 2023-07-24 17:07:57 +02:00
Guillaume Gomez 9fb6548905 Correctly handle super and :: 2023-07-24 17:07:57 +02:00
Guillaume Gomez 278d15c254 Extend issue-81141-private-reexport-in-public-api test to cover more cases 2023-07-24 17:07:56 +02:00
Guillaume Gomez d67a31f058 Add regression test for #81141 2023-07-24 17:07:56 +02:00
Guillaume Gomez 7150e35c92 Add regression test for #113982 2023-07-24 16:32:06 +02:00
Lukas Markeffsky bb98f3ad4d fix doc links on extern crate items 2023-07-22 12:27:25 +02:00
León Orell Valerian Liehr 5924043b86
rustdoc: handle cross-crate RPITITs correctly 2023-07-22 12:20:17 +02:00
Lukas Markeffsky 9ebd8095fa fix doc links on use items 2023-07-22 12:14:26 +02:00
Matthias Krüger 80f749dfa0
Rollup merge of #110765 - wackbyte:fix-defaultness-position, r=fmease,GuillaumeGomez
rustdoc: fix position of `default` in method rendering

With the following code:
```rs
#![feature(specialization)]

pub trait A {
    unsafe fn a();
}

impl A for () {
    default unsafe fn a() {}
}
```
rustdoc would render the `impl` of `a` as
```rs
unsafe default fn a()
```
which is inconsistent with the actual position of `default`.
This PR fixes this issue.
2023-07-20 17:19:32 +02:00
Matthias Krüger 53580da72d
Rollup merge of #113857 - GuillaumeGomez:document-hidden-items-test, r=notriddle
Add tests for `--document-hidden-items` option

Since `--document-hidden-items` was greatly fixed/improved in https://github.com/rust-lang/rust/pull/113574, thought it might be worth adding some more tests for it to prevent new regressions.

As for the first commit, it allows to go from:

```
Traceback (most recent call last):
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 706, in <module>
    check(sys.argv[1], get_commands(rust_test_path))
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 689, in check
    for c in commands:
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 274, in get_commands
    args = shlex.split(args)
  File "/usr/lib/python3.10/shlex.py", line 315, in split
    return list(lex)
  File "/usr/lib/python3.10/shlex.py", line 300, in __next__
    token = self.get_token()
  File "/usr/lib/python3.10/shlex.py", line 109, in get_token
    raw = self.read_token()
  File "/usr/lib/python3.10/shlex.py", line 191, in read_token
    raise ValueError("No closing quotation")
ValueError: No closing quotation
```

to:

```
Traceback (most recent call last):
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 708, in <module>
    check(sys.argv[1], get_commands(rust_test_path))
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 691, in check
    for c in commands:
  File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 278, in get_commands
    raise Exception("line {}: {}".format(lineno + 1, exc)) from None
Exception: line 57: No closing quotation
```

Having the line where the error occurred is quite useful.

r? `@notriddle`
2023-07-20 07:08:43 +02:00
Guillaume Gomez d9753d714d Add tests for --document-hidden-items option 2023-07-19 14:34:06 +02:00
Guillaume Gomez c845a53aa2 Add regression test for #105735 2023-07-18 10:41:16 +02:00
Michael Howell e72fba4160 rustdoc: use src consistently over source in JavaScript
Since the directory that contains source files is called `src`,
it makes sense to name the scripts that way, too.
2023-07-14 16:54:14 -07:00
Michael Howell 34bc8fbea3 rustdoc: use src consistently over source in code
The CSS uses an inconsistent mix of both. This commit switches
it to always use `src`.
2023-07-14 16:38:01 -07:00
Guillaume Gomez 6d44879eb3 Update jump to def tests 2023-07-12 16:50:43 +02:00
Matthias Krüger 3238a97d39
Rollup merge of #113058 - GuillaumeGomez:improve-code-comments, r=notriddle
Add/improve code comments

Working on something else and did some small comments updates/adds.

r? `@notriddle`
2023-06-27 07:01:32 +02:00
Guillaume Gomez 32f056ce6b Add/improve code comments 2023-06-26 16:38:14 +02:00
Takayuki Maeda 40e3fcfd59
Rollup merge of #112920 - fmease:rustdoc-fix-112904, r=GuillaumeGomez
rustdoc: render generic params & where-clauses of cross-crate assoc tys in impls

We used to only ever render generic parameters & where-clauses of cross-crate associated types when the item was located inside of a trait and we used to just drop them when it was inside of an impl block (trait or inherent).

Fixes #112904.

`@rustbot` label A-cross-crate-reexports
2023-06-26 23:16:16 +09:00
bors 7f01f03061 Auto merge of #113038 - matthiaskrgr:rollup-sdcfkxa, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #112976 (Add test for futures with HRTB)
 - #113013 (rustdoc: get rid of extra line when line-wrapping fn decls with empty arg list)
 - #113030 (Add a regression test for #109071)
 - #113031 (Add a regression test for #110933)
 - #113036 (Accept `ReStatic` for RPITIT)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-25 22:01:21 +00:00
León Orell Valerian Liehr 247aa06f10
rustdoc: handle assoc const equalities in cross-crate impl-Trait-in-arg-pos 2023-06-25 15:42:32 +02:00
wackbyte 13f58a8ea0
Add tests for default unsafe trait methods 2023-06-24 23:14:57 -04:00
León Orell Valerian Liehr d23c334707
rustdoc: get rid of extra line when line-wrapping fn decls with empty arg list 2023-06-24 23:39:35 +02:00
León Orell Valerian Liehr c643bedf7c
rustdoc: render gen params & where-clauses of cross-crate assoc tys in impl blocks 2023-06-24 12:20:26 +02:00
Matthias Krüger 4821f80716
Rollup merge of #112960 - GuillaumeGomez:rustdoc-files-check, r=notriddle
[tests/rustdoc] Add @files command

The ``````@!has`````` checks is very problematic as it wouldn't catch if the file scheme is updated and the file is generated again. ``````@files`````` allows to ensure that the given folder contains exactly the provided entries (files and folders).

I'm wondering if we should forbid the ``````@!has`````` for files. To be discussed after this PR I suppose.

r? `````@notriddle`````
2023-06-23 19:40:00 +02:00
Guillaume Gomez 752fb52ae9 Add @files checks in rustdoc tests 2023-06-23 15:12:48 +02:00
Matthias Krüger 3feee9f1f2
Rollup merge of #112927 - GuillaumeGomez:where-clause-indent, r=notriddle
Fix indentation for where clause in rustdoc pages

Screenshot of the bug:

![image](https://github.com/rust-lang/rust/assets/3050060/090cfeaa-0edc-46c7-9ea0-e26ac865b2c2)

I used this opportunity to clarify the code a bit because some weird things were going on.

r? ````@notriddle````
2023-06-23 13:18:13 +02:00
Guillaume Gomez b858a4745c Update existing snapshot and add more snapshots of where clause indentation 2023-06-22 17:39:23 +02:00
Matthias Krüger 3ba66df643
Rollup merge of #112906 - fmease:rustdoc-render-assoc-ty-body-before-where-clause, r=notriddle
rustdoc: render the body of associated types before the where-clause

Fixes #112903.
2023-06-22 06:29:33 +02:00