Commit Graph

910 Commits

Author SHA1 Message Date
Dylan DPC
c20657c1ec
Rollup merge of #79264 - jyn514:less-doctree, r=GuillaumeGomez
Get rid of some doctree items

They can be derived directly from the `hir::Item`, there's no special logic.

- TypeDef
- OpaqueTy
- Constant
- Static
- TraitAlias
- Enum
- Union
- Struct

Part of #78082 (the easiest part, I'm still debugging some other changes).
r? `@GuillaumeGomez`
2020-11-21 19:44:18 +01:00
Dylan DPC
5d428cae7d
Rollup merge of #79182 - lochsh:78777-fix-extern-types-ref, r=jyn514
Fix links to extern types in rustdoc (fixes #78777)

 r? `@jyn514`
 Fixes #78777.
The initial fix we tried was:
```diff
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index 8be9482acff..c4b7086fdb1 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
`@@` -433,8 +433,9 `@@` impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
             Res::PrimTy(prim) => Some(
                 self.resolve_primitive_associated_item(prim, ns, module_id, item_name, item_str),
             ),
-            Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias, did) => {
+            Res::Def(kind, did) if kind.ns() == Some(Namespace::TypeNS) => {
                 debug!("looking for associated item named {} for item {:?}", item_name, did);
+
                 // Checks if item_name belongs to `impl SomeItem`
                 let assoc_item = cx
                     .tcx
```

However, this caused traits to be matched, resulting in a panic when `resolve_associated_trait_item` is called further down in this function.

This PR also adds an error message for that panic. Currently it will look something like:
```rust
thread 'rustc' panicked at 'Not a type: DefIndex(8624)', compiler/rustc_metadata/src/rmeta/decoder.rs:951:32
```
I wasn't sure how to get a better debug output than `DefIndex(...)`, and am open to suggestions.
2020-11-21 19:44:11 +01:00
Joshua Nelson
8c94f8be99 Add more tests for renamed items 2020-11-21 10:19:02 -05:00
Hannah McLaughlin
32cd4bc790 Add test 2020-11-18 22:14:58 +00:00
Nixon Enraght-Moony
ae644a2d4d add [src] links to methods on a trait's page 2020-11-18 22:10:10 +00:00
Joshua Nelson
fc4ca55291 Add from_def_id_and_kind reducing duplication in rustdoc
- Add `Item::from_hir_id_and_kind` convenience wrapper
- Make name parameter mandatory

  `tcx.opt_item_name` doesn't handle renames, so this is necessary
  for any item that could be renamed, which is almost all of them.

- Override visibilities to be `Inherited` for enum variants

  `tcx.visibility` returns the effective visibility, not the visibility
  that was written in the source code. `pub enum E { A, B }` always has
  public variants `A` and `B`, so there's no sense printing `pub` again.

- Don't duplicate handling of `Visibility::Crate`

  Instead, represent it as just another `Restricted` path.
2020-11-17 15:16:03 -05:00
Joshua Nelson
6c28ffbef3 Use DefPath for clean::Visibility, not clean::Path
Visibility needs much less information than a full path, since modules
can never have generics. This allows constructing a Visibility from only
a DefId.

Note that this means that paths are now normalized to their DefPath.
In other words, `pub(self)` or `pub(super)` now always shows `pub(in
path)` instead of preserving the original text.
2020-11-17 15:13:25 -05:00
Mara Bos
7a1bd805fa
Rollup merge of #78678 - Nemo157:doc-cfg-w-traits, r=jyn514,GuillaumeGomez
Add tests and improve rendering of cfgs on traits

Shows the additional features required to get the trait implementation, suppressing any already shown on the current page. One interesting effect from this is if you have a cfg-ed type, implementing a cfg-ed trait (so the implementation depends on both cfgs), you will get the inverted pair of cfgs shown on each page:

![image](https://user-images.githubusercontent.com/81079/97904671-207bdc00-1d41-11eb-8144-707e8017d2b6.png)

![image](https://user-images.githubusercontent.com/81079/97904700-27a2ea00-1d41-11eb-8b9f-e925ba339044.png)

The hidden items on the trait implementation also now get the correct cfgs displayed on them.

Tests are blocked on #78673.

fixes #68100
cc #43781
2020-11-16 17:26:25 +01:00
Dylan DPC
50603891dc
Rollup merge of #78962 - poliorcetics:rustdoc-raw-ident-test, r=jyn514
Add a test for r# identifiers

I'm not entirely sure I properly ran the test locally (I think so though), waiting for CI to confirm. :)

```````@rustbot``````` modify labels: T-rustdoc

r? ```````@jyn514```````
2020-11-15 03:02:44 +01:00
Wim Looman
c34350ab4f
Add tests and improve rendering of features on traits 2020-11-14 22:11:45 +01:00
bors
b63d05a908 Auto merge of #78683 - Nemo157:issue-78673, r=lcnr
Check predicates from blanket trait impls while testing if they apply

fixes #78673
2020-11-13 23:12:01 +00:00
Guillaume Gomez
804ca1d5b7
Rollup merge of #78984 - GuillaumeGomez:rustdoc-check-option, r=jyn514
Rustdoc check option

The ultimate goal behind this option would be to have `rustdoc --check` being run when you use `cargo check` as a second step.

r? `@jyn514`
2020-11-13 15:26:16 +01:00
Alexis Bourget
309d863e37 Fix wrong XPath 2020-11-13 14:58:21 +01:00
Joshua Nelson
38127caf73 Handle and test wildcard arguments 2020-11-12 11:14:29 -05:00
Joshua Nelson
2baa0ceff4 Don't reuse bindings for ref mut
Reusing bindings causes errors later in lowering:

```
 error[E0596]: cannot borrow `vec` as mutable, as it is not declared as mutable
  --> /checkout/src/test/ui/async-await/argument-patterns.rs:12:20
   |
LL | async fn b(n: u32, ref mut vec: A) {
   |                    ^^^^^^^^^^^
   |                    |
   |                    cannot borrow as mutable
   |                    help: consider changing this to be mutable: `mut vec`
```
2020-11-12 11:13:05 -05:00
Guillaume Gomez
5e154fae92 Add tests for rustdoc --check option 2020-11-12 14:58:07 +01:00
Guillaume Gomez
0cd118d967
Rollup merge of #78916 - lcnr:const-generics-tests, r=varkor
extend const generics test suite

should implement most of #78433, especially all parts of [the hackmd](https://hackmd.io/WnFmN4MjRCqAjGmYfYcu2A?view) which I did not explicitly mention in that issue.

r? ``@varkor``
2020-11-12 11:31:45 +01:00
Poliorcetics
ecfeac58aa
Use intradoc-links for the whole test, add a @has check
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-11-12 01:55:28 +01:00
Alexis Bourget
9c7069645c Ignore tidy linelength 2020-11-12 01:39:06 +01:00
Alexis Bourget
f5e67b5ee1 Add a test for r# identifiers 2020-11-12 01:05:27 +01:00
Bastian Kauschke
7d9f81517b add rustdoc test 2020-11-11 21:24:03 +01:00
Florian Warzecha
7beb0da4a9
(rustdoc) [src] link for types defined by macros shows invocation
Previously the [src] link on types defined by a macro
pointed to the macro definition.
This commit makes the Clean-Implementation for Spans
aware of macro defined types,
so that the link points to the invocation instead.
2020-11-10 01:02:38 +01:00
Mara Bos
9bbb052af8
Rollup merge of #78727 - liketechnik:issue-55201, r=GuillaumeGomez
(rustdoc) fix test for trait impl display

The test checks that parameters and return values with `impl Trait` types are correctly generated in rustdoc's output.

In essence, the previous version of the test checked the absence of values that would never be generated by rustdoc, so it could basically never fail. These values were adjusted to the expected output and are now required to exist in rustdoc's output. See https://github.com/rust-lang/rust/issues/55201#issuecomment-716182474 for a detailed explanation of the reasoning behind the changes.

Note that the output of rustdoc for `impl Trait`s in parameters and return values did not change since the inital test creation, so this PR only modifies the test.

Closes #55201
2020-11-05 10:29:50 +01:00
Wim Looman
0e2af5cc63 Check predicates from blanket trait impls while testing if they apply 2020-11-02 22:25:01 +01:00
Guillaume Gomez
fcee70f643 Update tests 2020-10-29 11:43:21 +01:00
Guillaume Gomez
b4c35368f4 Add test for doc comments unindent fix 2020-10-26 21:34:53 +01:00
Florian Warzecha
251f6da276
(rustdoc) fix test for trait impl display 2020-10-25 20:47:05 +01:00
Yuki Okushi
47042594cb
Rollup merge of #77920 - ayazhafiz:i/mut-ident-spacing, r=jyn514
Avoid extraneous space between visibility kw and ident for statics

Today, given a static like `static mut FOO: usize = 1`, rustdoc would
emit `static mut  FOO: usize = 1`, as it emits both the mutability kw
with a space and reserves a space after the mutability kw. This patch
fixes that misformatting.

This patch also adds some tests for emit of other statics, as I could
not find an existing test devoted to statics.
2020-10-23 18:26:24 +09:00
Dylan DPC
446686f59b
Rollup merge of #77785 - GuillaumeGomez:remove-compiler-reexports, r=ollie27
Remove compiler-synthesized reexports when documenting

Fixes #77567

r? @ollie27
2020-10-17 03:27:17 +02:00
Dylan DPC
71b0ea6235
Rollup merge of #77672 - Nemo157:simplify-cfg, r=jyn514
Simplify doc-cfg rendering based on the current context

For sub-items on a page don't show cfg that has already been rendered on
a parent item. At its simplest this means not showing anything that is
shown in the portability message at the top of the page, but also for
things like fields of an enum variant if that variant itself is
cfg-gated then don't repeat those cfg on each field of the variant.

This does not touch trait implementation rendering, as that is more
complex and there are existing issues around how it deals with doc-cfg
that need to be fixed first.

### Screenshots, left is current, right is new:

![image](https://user-images.githubusercontent.com/81079/95387261-c2e6a200-08f0-11eb-90d4-0a9734acd922.png)

![image](https://user-images.githubusercontent.com/81079/95387458-06411080-08f1-11eb-81f7-5dd7f37695dd.png)

![image](https://user-images.githubusercontent.com/81079/95387702-6637b700-08f1-11eb-82f4-46b6cd9b24f2.png)

![image](https://user-images.githubusercontent.com/81079/95387905-b9aa0500-08f1-11eb-8d95-8b618d31d419.png)

![image](https://user-images.githubusercontent.com/81079/95388300-5bc9ed00-08f2-11eb-9ac9-b92cbdb60b89.png)

cc #43781
2020-10-16 02:10:19 +02:00
ayazhafiz
e60072f5c6 fixup! Avoid extraneous space between visibility kw and ident for statics 2020-10-13 16:47:53 -05:00
ayazhafiz
abfbd1bd71 Avoid extraneous space between visibility kw and ident for statics
Today, given a static like `static mut FOO: usize = 1`, rustdoc would
emit `static mut  FOO: usize = 1`, as it emits both the mutability kw
with a space and reserves a space after the mutability kw. This patch
fixes that misformatting.

This patch also adds some tests for emit of other statics, as I could
not find an existing test devoted to statics.
2020-10-13 16:21:55 -05:00
Guillaume Gomez
0faaa499cc Add test for compiler reexports removal 2020-10-12 11:26:01 +02:00
Joshua Nelson
1772f2d2dc Show summary lines on cross-crate re-exports
This removes the unnecessary `DocFragmentKind::Divider` in favor of just
using the logic I actually want in `collapse_docs`.
2020-10-11 20:27:17 -04:00
Dániel Buga
725e3d1df3 Re-enable test case 2020-10-10 15:56:51 +02:00
bors
b1af43bc63 Auto merge of #76934 - camelid:rustdoc-allow-generic-params, r=jyn514
Allow generic parameters in intra-doc links

Fixes #62834.

---

The contents of the generics will be mostly ignored (except for warning
if fully-qualified syntax is used, which is currently unsupported in
intra-doc links - see issue #74563).

* Allow links like `Vec<T>`, `Result<T, E>`, and `Option<Box<T>>`
* Allow links like `Vec::<T>::new()`
* Warn on
  * Unbalanced angle brackets (e.g. `Vec<T` or `Vec<T>>`)
  * Missing type to apply generics to (`<T>` or `<Box<T>>`)
  * Use of fully-qualified syntax (`<Vec as IntoIterator>::into_iter`)
  * Invalid path separator (`Vec:<T>:new`)
  * Too many angle brackets (`Vec<<T>>`)
  * Empty angle brackets (`Vec<>`)

Note that this implementation *does* allow some constructs that aren't
valid in the actual Rust syntax, for example `Box::<T>new()`. That may
not be supported in rustdoc in the future; it is an implementation
detail.
2020-10-10 21:19:50 +00:00
Camelid
5883d3de9c Move @has checks closer to corresponding doc comments 2020-10-09 16:11:15 -07:00
Guillaume Gomez
e3b1be3b62 Remove unneeded ImportItem on glob ones 2020-10-09 20:26:06 +02:00
Guillaume Gomez
6bea76f175 Simplify included import items handling 2020-10-09 20:26:06 +02:00
Camelid
4c765f66a4 Allow generic parameters in intra-doc links
The contents of the generics will be mostly ignored (except for warning
if fully-qualified syntax is used, which is currently unsupported in
intra-doc links - see issue #74563).

* Allow links like `Vec<T>`, `Result<T, E>`, and `Option<Box<T>>`
* Allow links like `Vec::<T>::new()`
* Warn on
  * Unbalanced angle brackets (e.g. `Vec<T` or `Vec<T>>`)
  * Missing type to apply generics to (`<T>` or `<Box<T>>`)
  * Use of fully-qualified syntax (`<Vec as IntoIterator>::into_iter`)
  * Invalid path separator (`Vec:<T>:new`)
  * Too many angle brackets (`Vec<<T>>`)
  * Empty angle brackets (`Vec<>`)

Note that this implementation *does* allow some constructs that aren't
valid in the actual Rust syntax, for example `Box::<T>new()`. That may
not be supported in rustdoc in the future; it is an implementation
detail.
2020-10-08 22:24:34 -07:00
Joshua Nelson
e39a86019d Use the new module information for intra-doc links
- Make the parent module conditional on whether the docs are on a re-export
- Make `resolve_link` take `&Item` instead of `&mut Item`

  Previously the borrow checker gave an error about multiple mutable
  borrows, because `dox` borrowed from `item`.

- Fix `crate::` for re-exports

  `crate` means something different depending on where the attribute
  came from.

- Make it work for `#[doc]` attributes too

  This required combining several attributes as one so they would keep
  the links.
2020-10-08 00:29:38 -04:00
Wim Looman
6f0544abe4 Simplify doc-cfg rendering based on the current context
For sub-items on a page don't show cfg that has already been rendered on
a parent item. At its simplest this means not showing anything that is
shown in the portability message at the top of the page, but also for
things like fields of an enum variant if that variant itself is
cfg-gated then don't repeat those cfg on each field of the variant.

This does not touch trait implementation rendering, as that is more
complex and there are existing issues around how it deals with doc-cfg
that need to be fixed first.
2020-10-07 22:54:12 +02:00
bors
9e34b72964 Auto merge of #77253 - jyn514:crate-link, r=Manishearth
Resolve `crate` in intra-doc links properly across crates

Closes https://github.com/rust-lang/rust/issues/77193; see https://github.com/rust-lang/rust/issues/77193#issuecomment-699065946 for an explanation of what's going on here.
~~This also fixes the BTreeMap docs that have been broken for a while; see the description on the second commit for why and how.~~ Nope, see the second commit for why the link had to be changed.

r? `@Manishearth`
cc `@dylni`

`@dylni` note that this doesn't solve your original problem - now _both_ `with_code` and `crate::with_code` will be broken links. However this will fix a lot of other broken links (in particular I think https://docs.rs/sqlx/0.4.0-beta.1/sqlx/query/struct.Query.html is because of this bug). I'll open another issue for resolving additional docs in the new scope.
2020-09-29 12:11:17 +00:00
Joshua Nelson
8437d7b1d3 Resolve crate properly across crates 2020-09-27 10:13:59 -04:00
Joshua Nelson
03d8be0896 Separate private_intra_doc_links and broken_intra_doc_links into separate lints
This is not ideal because it means `deny(broken_intra_doc_links)` will
no longer `deny(private_intra_doc_links)`. However, it can't be fixed
with a new lint group, because `broken` is already in the `rustdoc` lint
group; there would need to be a way to nest groups somehow.

This also removes the early `return` so that the link will be generated
even though it gives a warning.
2020-09-27 09:58:29 -04:00
Joshua Nelson
049d29bac5 Unify primitive errors with other intra-link errors
Now that `PrimTy::name()` exists, there's no need to carry around the
name of the primitive that failed to resolve. This removes the variants
special-casing primitives in favor of `NotResolved`.

- Remove `NoPrimitiveImpl` and `NoPrimitiveAssocItem`
- Remove hacky `has_primitive` check in `resolution_failure()`
- Fixup a couple tests that I forgot to `--bless` before
2020-09-23 21:04:50 -04:00
Joshua Nelson
472e52e5a0 Fix intra-doc links for primitives
- Add `PrimTy::name` and `PrimTy::name_str`
- Use those new functions to distinguish between the name in scope and
the canonical name
- Fix diagnostics for primitive types
- Add tests for primitives
2020-09-23 21:04:22 -04:00
Joshua Nelson
dd7b8c85a6 Perform most diagnostic lookups in resolution_failure
Previously, these were spread throughout the codebase. This had two
drawbacks:

1. It caused the fast path to be slower: even if a link resolved,
rustdoc would still perform various lookups for the error diagnostic.
2. It was inconsistent and didn't always give all diagnostics (https://github.com/rust-lang/rust/issues/76925)

Now, diagnostics only perform expensive lookups in the error case.
Additionally, the error handling is much more consistent, both in
wording and behavior.

- Remove `CannotHaveAssociatedItems`, `NotInScope`, `NoAssocItem`, and `NotAVariant`
  in favor of the more general `NotResolved`

  `resolution_failure` will now look up which of the four above
  categories is relevant, instead of requiring the rest of the code to
  be consistent and accurate in which it picked.

- Remove unnecessary lookups throughout the intra-doc link pass. These
are now done by `resolution_failure`.
  + Remove unnecessary `extra_fragment` argument to `variant_field()`;
    it was only used to do lookups on failure.
  + Remove various lookups related to associated items
  + Remove distinction between 'not in scope' and 'no associated item'

- Don't perform unnecessary copies
- Remove unused variables and code
- Update tests
- Note why looking at other namespaces is still necessary
- 'has no inner item' -> 'contains no item'

bless tests
2020-09-23 21:04:20 -04:00
bors
356d8ad1a3 Auto merge of #76571 - lzutao:rustdoc-private-traits, r=jyn514
Ignore rustc_private items from std docs

By ignoring rustc_private items for non local impl block,
this may fix #74672 and fix #75588 .

This might suppress #76529 if it is simple enough for backport.
2020-09-14 08:25:41 +00:00
bors
a055c5a1bd Auto merge of #76623 - slightlyoutofphase:master, r=jyn514
Use `is_unstable_const_fn` instead of `is_min_const_fn` in rustdoc where appropriate

This closes #76501. Specifically, it allows for nightly users with the `#![feature(const_fn)]` flag enabled to still have their `const fn` declarations documented as such, while retaining the desired behavior that rustdoc *not* document functions that have the `rustc_const_unstable` attribute as `const`.
2020-09-13 13:36:31 +00:00