Commit Graph

1241 Commits

Author SHA1 Message Date
Guillaume Gomez
5a82251e92
Rollup merge of #82598 - GuillaumeGomez:rustdoc-rustc-pass, r=jyn514
Check stability and feature attributes in rustdoc

Fixes #82588.

cc `@Nemo157` `@camelid`
r? `@jyn514`
2021-03-02 00:50:08 +01:00
Dan Gohman
e27eba3397 Add a test in src/test/rustdoc/doc-cfg.rs 2021-02-28 14:07:05 -08:00
Guillaume Gomez
5ab4d46e9a Update rustdoc test to make it work with newly added rustc passes 2021-02-28 00:48:43 +01:00
Lucas De Angelis
5835f6defa Move test file, add test of generated link 2021-02-27 01:08:05 +01:00
Lucas De Angelis
5661fe3fa9 Fix intra-doc handling of Self in enum
Fixes #82209
2021-02-26 22:09:39 +01:00
Guillaume Gomez
3c59e64abf * Fix some typo
* Improve documentation
* Add a test to ensure that spotlighted traits from dependencies are taken into account as expected
2021-02-23 21:58:17 +01:00
Guillaume Gomez
2b59e7667d Add tests for --generate-redirect-map option 2021-02-23 11:13:35 +01:00
Dylan DPC
1c2a949736
Rollup merge of #79423 - camelid:smart-punct, r=jyn514
Enable smart punctuation

Closes #76690.
2021-02-23 02:51:42 +01:00
Yuki Okushi
1dba8ce8a5
Rollup merge of #82351 - notriddle:docs-meta-description, r=jyn514
Use the first paragraph, instead of cookie-cutter text, for rustdoc descriptions

Partially addresses #82283.
2021-02-22 18:26:08 +09:00
Michael Howell
575c75b324
Update src/test/rustdoc/description.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-02-21 09:31:39 -07:00
Michael Howell
a6b85fbc78
Update src/test/rustdoc/description.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-02-21 09:31:23 -07:00
Michael Howell
fd5a710092 Use has for non-regexes 2021-02-20 17:51:41 -07:00
Michael Howell
dcf49916e4 Fix formatting for description rustdoc UI tests 2021-02-20 17:50:01 -07:00
Michael Howell
8b3b1c922e Add rustdoc UI tests for new description behaviour 2021-02-20 17:43:13 -07:00
Guillaume Gomez
0c511c9115 Add test for no src links on dummy spans 2021-02-20 19:51:38 +01:00
Guillaume Gomez
46f24c912f Add tests for !Sized trait display 2021-02-19 22:38:07 +01:00
Simon Sapin
21ceebf296 Fix intra-doc link to raw pointer method
CC https://github.com/rust-lang/rust/pull/80181
2021-02-15 14:27:50 +01:00
Yuki Okushi
3560ff39f0
Rollup merge of #82040 - GuillaumeGomez:ensure-src-link, r=CraftSpider
Add test to prevent src link regression

Fixes #80502.

This PR is simply about adding a test to prevent a regression.

cc `@bugadani` `@CraftSpider`
r? `@camelid`
2021-02-13 16:36:49 +09:00
Dylan DPC
ab3f4f0bc0
Rollup merge of #79775 - jyn514:doctest, r=GuillaumeGomez
Fix injected errors when running doctests on a crate named after a keyword

Closes https://github.com/rust-lang/rust/issues/79771
2021-02-12 22:53:21 +01:00
Guillaume Gomez
95c984a4a3 Add test to prevent src link regression 2021-02-12 20:27:57 +01:00
Joshua Nelson
02ffe9ef01 Fix injected errors when running doctests on a crate named after a keyword
Unfortunately, this can't currently be tested. The problem is that we
need the file to be compiled first to then be used as dependency, which
cannot be done currently unfortunately in the rustdoc test suites.
Example:

```rust
// name this file "foo.rs"

/// ```
/// let x = foo::foo();
/// ```
pub fn foo() {}
```

If you run `rustdoc --test foo.rs`, you'll get:

```
running 1 test
test foo.rs - foo (line 1) ... FAILED

failures:

---- foo.rs - foo (line 1) stdout ----
error[E0463]: can't find crate for `foo`
 --> foo.rs:0:1
  |
2 | extern crate foo;
  | ^^^^^^^^^^^^^^^^^ can't find crate
```

If a test were possible, it would look something like

 ````rust
 #![crate_name = "mod"]
 #![crate_type = "lib"]
 //! ```
 //! // NOTE: requires that the literal string 'mod' appears in the doctest for
 //! // the bug to appear
 //! assert_eq!(1, 1);
 //! ```
 ````
2021-02-11 17:16:43 -05:00
Vadim Petrochenkov
7b021aacb5 resolve: Reduce scope of pub_use_of_private_extern_crate deprecation lint 2021-02-11 10:15:29 +03:00
LeSeulArtichaut
089ee27dd0 Do not ICE on range patterns in function arguments 2021-02-10 16:41:48 +01:00
LeSeulArtichaut
793e88ad16 Add regression test for #81289 2021-02-10 16:41:09 +01:00
Camelid
0a3452110c Fix @has checks "no closing quotation" error
Apparently `"foo\""` has different behavior from `'foo\''` in Python
shlex. See the [discussion on Zulip][z] for more.

[z]: https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/.40has.20checks.20.22no.20closing.20quotation.22
2021-02-08 15:49:04 -08:00
bors
921ec4b3fc Auto merge of #81313 - LeSeulArtichaut:revert-32558, r=jyn514
Restore linking to itself in implementors section of trait page

Reverts #32558 as proposed in [this Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Trait.20implementation.20self-links/near/223773273)
r? `@jyn514` cc `@camelid`
2021-02-08 10:46:10 +00:00
Camelid
f1581ed8fc Test that code does not get smart-punctuated 2021-02-07 20:19:01 -08:00
Camelid
a0f9d4beec Enable smart punctuation 2021-02-07 19:57:53 -08:00
LeSeulArtichaut
1daddb47d2 Restore linking to itself in implementors section of trait page 2021-02-06 21:05:41 +01:00
Joshua Nelson
9653b601b2 Enable 'task list' markdown extension
- Add documentation about task lists
2021-02-06 00:08:21 -05:00
Camelid
cd8dceef86 rustdoc: Render HRTB correctly for bare functions
The angle brackets were not rendered, so code like this:

    some_func: for<'a> fn(val: &'a i32) -> i32

would be rendered as:

    some_func: fn'a(val: &'a i32) -> i32

However, rendering with angle brackets is still invalid syntax:

    some_func: fn<'a>(val: &'a i32) -> i32

so now it renders correctly as:

    some_func: for<'a> fn(val: &'a i32) -> i32

-----

However, note that this code:

    some_trait: dyn for<'a> Trait<'a>

will still render as:

    some_trait: dyn Trait<'a>

which is not invalid syntax, but is still unclear. Unfortunately I think
it's hard to fix that case because there isn't enough information in the
`rustdoc::clean::Type` that this code operates on. Perhaps that case can
be fixed in a later PR.
2021-01-27 19:55:46 -08:00
Jonas Schievink
ee4461a996
Rollup merge of #81302 - LeSeulArtichaut:80777-trait-render, r=jyn514
Fix rendering of stabilization version for trait implementors

Rustdoc compares an item's stabilization version with its parent's to not render it if they are the same. Here, the implementor was compared with itself, resulting in the stabilization version never getting shown.

This probably needs a test.

Fixes #80777.
r? `@jyn514`
2021-01-24 22:10:04 +01:00
LeSeulArtichaut
20a460e1cf Fix rendering of stabilization version for trait implementors 2021-01-23 22:02:06 +01:00
Camelid
93e51b185a rustdoc: Fix visibility of trait and impl items 2021-01-22 18:30:30 -08:00
bors
339e19697a Auto merge of #80958 - bstrie:deptbdnums, r=KodrAus
Deprecate-in-future the constants superceded by RFC 2700

Successor to #78335, re-opened after addressing the issues tracked in #68490.

This PR makes use of the new ability to explicitly annotate an item as triggering the deprecated-in-future lint (via `rustc_deprecated(since="TBD"`, see #78381). We might call this *soft deprecation*; unlike with deprecation, users will *not* receive warnings when compiling code that uses these items *unless* they opt-in via `#[warn(deprecated_in_future)]`. Like deprecation, soft deprecation causes documentation to formally acknowledge that an item is marked for eventual deprecation (at a non-specific point in the future).

With this new ability, we can sidestep all debate about when or on what timeframe something ought to be deprecated; as long as we can agree that something ought to be deprecated, we can receive much of the benefits of deprecation with none of the drawbacks. For these items specifically, the libs team has already agreed that they should be deprecated (see https://github.com/rust-lang/rust/issues/68490#issuecomment-747022696).
2021-01-21 09:14:37 +00:00
bstrie
6f3df00610 Deprecate-in-future the constants superceded by RFC 2700 2021-01-20 20:08:11 -05:00
Joshua Nelson
1f6f750ade Remove flaky test
See https://github.com/rust-lang/rust/pull/81197 for what's going on
here; this is a temporary stopgap until someone has time to review the
proper fix.
2021-01-20 19:18:23 -05:00
Joshua Nelson
fc53594756 Feature-gate pointer and reference in intra-doc links
- Only feature gate associated items
- Add docs to unstable book
2021-01-17 15:27:35 -05:00
Yuki Okushi
0dedc6c054
Rollup merge of #80254 - Aaron1011:rustdoc-auto-param-env, r=estebank
Don't try to add nested predicate to Rustdoc auto-trait `ParamEnv`

Fixes #80233

We already have logic in `evaluate_predicates` that tries to add
unimplemented predicates to our `ParamEnv`. Trying to add a predicate
that already holds can lead to errors later on, since projection
will prefer trait candidates from the `ParamEnv` to predicates from an
impl.
2021-01-15 18:26:04 +09:00
Mark Rousskov
8a3edb1d66 Update tests for extern block linting 2021-01-13 07:49:16 -05:00
Tristan Dannenberg
f3c8f29b3b
Simplify regression test
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-12 18:18:10 +01:00
Tristan Dannenberg
0401a9935f Update help message and add regression test 2021-01-12 17:59:57 +01:00
Yuki Okushi
7e160256e4
Rollup merge of #80885 - camelid:intra-doc-str-ref, r=jyn514
rustdoc: Resolve `&str` as `str`

People almost always are referring to `&str`, not `str`, so this will
save a manual link resolve in many cases.

Note that we already accept `&` (resolves to `reference`) in intra-doc
links, so this shouldn't cause breakage.

r? `@jyn514`
2021-01-12 07:59:15 +09:00
Yuki Okushi
a7f7d70860
Rollup merge of #80892 - camelid:intra-doc-remove-star, r=jyn514
rustdoc: Remove `*` intra-doc alias for `pointer`

It's not valid Rust code and it can easily be confused with a wildcard
glob pattern or something else. People can always use `pointer` instead,
so it's just removing an alias.

It hasn't hit stable yet (I think it's still on nightly), so it's okay
to remove it. (We can always add it back later if we change our mind
too.)

r? `@jyn514`
cc https://github.com/rust-lang/rust/pull/80885#discussion_r554622737
2021-01-11 14:34:54 +09:00
Yuki Okushi
6e2249d2fd
Rollup merge of #80881 - jyn514:intra-doc-self, r=GuillaumeGomez
Fix intra-doc links to `Self` and `crate`

Closes https://github.com/rust-lang/rust/issues/77732.
2021-01-11 14:34:51 +09:00
Camelid
e98f11b27d rustdoc: Remove * intra-doc alias for pointer
It's not valid Rust code and it can easily be confused with a wildcard
glob pattern or something else. People can always use `pointer` instead,
so it's just removing an alias.

It hasn't hit stable yet (I think it's still on nightly), so it's okay
to remove it. (We can always add it back later if we change our mind
too.)
2021-01-10 15:41:32 -08:00
Camelid
2750e36209 rustdoc: Resolve &str as str
People almost always are referring to `&str`, not `str`, so this will
save a manual link resolve in many cases.

Note that we already accept `&` (resolves to `reference`) in intra-doc
links, so this shouldn't cause breakage.
2021-01-10 12:51:48 -08:00
Joshua Nelson
0acaa5af6b Fix intra-doc links to Self and crate 2021-01-10 10:00:17 -05:00
bors
7a193921a0 Auto merge of #77862 - danielhenrymantilla:rustdoc/fix-macros_2_0-paths, r=jyn514,petrochenkov
Rustdoc: Fix macros 2.0 and built-in derives being shown at the wrong path

Fixes #74355

  - ~~waiting on author + draft PR since my code ought to be cleaned up _w.r.t._ the way I avoid the `.unwrap()`s:~~

      - ~~dummy items may avoid the first `?`,~~

      - ~~but within the module traversal some tests did fail (hence the second `?`), meaning the crate did not possess the exact path of the containing module (`extern` / `impl` blocks maybe? I'll look into that).~~

r? `@jyn514`
2021-01-10 05:15:01 +00:00
bors
937f629535 Auto merge of #80653 - jryans:doc-deref-recursive, r=jyn514,GuillaumeGomez
Recursively document methods via `Deref` traits

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.

![image](https://user-images.githubusercontent.com/279572/103482863-46723b00-4ddb-11eb-972b-c463351a425c.png)

Fixes https://github.com/rust-lang/rust/issues/26207
Fixes https://github.com/rust-lang/rust/issues/53038
Fixes https://github.com/rust-lang/rust/issues/71640

r? `@jyn514`
2021-01-08 12:34:20 +00:00
J. Ryan Stinnett
8eaf68f92c Preserve non-local recursive Deref impls
This adjusts the `rustdoc` trait impl collection path to preserve `Deref` impls
from other crates. This adds a first pass to map all of the `Deref` type to
target edges and then recursively preserves all targets.
2021-01-08 07:15:03 +00:00
J. Ryan Stinnett
06ce97c3c9 Use target in Deref method section IDs
There can now be multiple `Deref` method sections, so this adds the target type
to the section ID to ensure they are unique.
2021-01-08 07:15:03 +00:00
J. Ryan Stinnett
fd0ad03902 Recursively document methods via Deref traits 2021-01-08 07:15:03 +00:00
Yuki Okushi
dec3dbd36a
Rollup merge of #80799 - jyn514:pretty-print, r=CraftSpider
Get rid of custom pretty-printing in rustdoc

and use rustc_hir_pretty directly instead.

Closes https://github.com/rust-lang/rust/issues/79497.

r? `@CraftSpider`
2021-01-08 11:11:50 +09:00
Joshua Nelson
31375d2074 Get rid of custom pretty-printing in rustdoc
and use rustc_hir_pretty directly instead
2021-01-07 17:44:59 -05:00
Yuki Okushi
2e9788b298
Rollup merge of #80660 - max-heller:issue-80559-fix, r=jyn514
Properly handle primitive disambiguators in rustdoc

Fixes #80559

r? ``@jyn514``

Is there a way to test that the generated intra-doc link is what I expect?
2021-01-08 02:06:09 +09:00
Daniel Henry-Mantilla
255f107cac Fix ICE on pub macros defined within a non-module type namespace. 2021-01-06 15:13:39 +01:00
Daniel Henry-Mantilla
8df60663cc Enhance tests based on code review
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-06 15:13:39 +01:00
Daniel Henry-Mantilla
28e9c6723a Update test assertions (showcases bug) 2021-01-06 15:13:38 +01:00
Daniel Henry-Mantilla
d3a33eb1f9 Fix type/value namespace clashes + test for that 2021-01-06 15:13:38 +01:00
Daniel Henry-Mantilla
7d03870882 Implement suggestions from code review. 2021-01-06 15:13:38 +01:00
Daniel Henry-Mantilla
0bee80210d Rustdoc: Fix macros 2.0 and built-in derives being shown at the wrong path.
Fixes #74355

The issue with the built-in derives may be related to:
https://github.com/rust-lang/rust/issues/55482#issuecomment-434035721
2021-01-06 15:13:38 +01:00
Camille GILLOT
abef2ed2bc Add rustdoc test. 2021-01-05 21:10:34 +01:00
max-heller
6f0413316f fix incompatible disambiguator test 2021-01-04 15:38:30 -05:00
bors
6163bfdcce Auto merge of #80661 - jyn514:duplicate-types, r=GuillaumeGomez
Cleanup rustdoc handling of associated types

This is best reviewed a commit at a time. No particular reason for these changes, they just stood out as I was reviewing https://github.com/rust-lang/rust/pull/80653 and thinking about https://github.com/rust-lang/rust/issues/80379. The new test case worked before, it just wasn't tested.

r? `@GuillaumeGomez`
2021-01-04 10:32:28 +00:00
max-heller
e33a205bdf primitive disambiguator tests 2021-01-03 20:38:28 -05:00
max-heller
b4a0ef066d fix issue 80559 2021-01-03 20:38:28 -05:00
Joshua Nelson
a786eaac1f Simplify rustdoc handling of type aliases for associated types
The logic was very hard to follow before.
2021-01-03 15:40:41 -05:00
bors
206ee1eea3 Auto merge of #80565 - camelid:fix-not-has, r=GuillaumeGomez
Fix tests that incorrectly used `!@has` instead of `@!has`

The command is ``@!has`,` not `!`@has`.` I don't think these checks were
doing anything before! Ideally we would accept `!`@has`` as well, or at
least fail tests that use `!`@has`.` The current behavior seems to be
silently ignoring the check, which is very confusing.

r? `@GuillaumeGomez`
2021-01-01 16:12:27 +00:00
Dylan DPC
7d247c9246
Rollup merge of #80368 - camelid:rustdoc-succinct-vis, r=jyn514
rustdoc: Render visibilities succinctly

Fixes #79139.

r? `@jyn514`
2020-12-31 22:20:49 +01:00
Camelid
2c405aea5d Fix tests that incorrectly used !@has instead of @!has
The command is `@!has`, not `!@has`. I don't think these checks were
doing anything before! Ideally we would accept `!@has` as well, or at
least fail tests that use `!@has`. The current behavior seems to be
silently ignoring the check, which is very confusing.
2020-12-31 12:47:09 -08:00
Camelid
5604a18a60 Add @!has checks to ensure private items don't have pub 2020-12-31 12:08:20 -08:00
bors
a6bd5246da Auto merge of #80267 - 0urobor0s:ouro/61592, r=jyn514
Rustdoc render public underscore_imports as Re-exports

Fixes #61592
2020-12-31 09:07:52 +00:00
bors
cb4553bdae Rustdoc render public underscore_imports as Re-exports
Fixes #61592
2020-12-31 09:07:51 +00:00
bors
257becbfe4 Auto merge of #80181 - jyn514:intra-doc-primitives, r=Manishearth
Fix intra-doc links for non-path primitives

This does *not* currently work for associated items that are
auto-implemented by the compiler (e.g. `never::eq`), because they aren't
present in the source code. I plan to fix this in a follow-up PR.

Fixes https://github.com/rust-lang/rust/issues/63351 using the approach mentioned in https://github.com/rust-lang/rust/issues/63351#issuecomment-683352130.

r? `@Manishearth`

cc `@petrochenkov` - this makes `rustc_resolve::Res` public, is that ok? I'd just add an identical type alias in rustdoc if not, which seems a waste.
2020-12-27 18:55:33 +00:00
Bastian Kauschke
c4ba60a191 update tests 2020-12-26 18:24:10 +01:00
Camelid
bb4761d1eb Merge pub-restricted and visibility test 2020-12-25 16:27:56 -08:00
Camelid
b959c75b31 Prefer pub(crate) over no modifier 2020-12-25 16:20:08 -08:00
Camelid
50c1c27fa6 Fix bugs; fix and add tests 2020-12-25 15:53:17 -08:00
Dylan DPC
d837407339
Rollup merge of #80319 - jyn514:async-lifetimes, r=tmandry
Fix elided lifetimes shown as `'_` on async functions

Closes https://github.com/rust-lang/rust/issues/63037.

r? `@tmandry` on the implementation, `@Darksonn` on the test cases.
2020-12-25 03:39:40 +01:00
Joshua Nelson
6ac52f0d9d Don't process [] and () in intra-doc links
These caused several false positives when documenting rustc, which means
there will likely be many more false positives in the rest of the
ecosystem.
2020-12-24 20:45:01 -05:00
bors
b2516121e2 Auto merge of #79742 - GuillaumeGomez:move-tooltips-messages-out-of-html, r=Nemo157
Move tooltips messages out of html

First thing first: nothing in the output has changed. You still have the "i" on the left of code blocks examples when they have `ignore`, `compile_fail`, `should_panic` and `edition`. The behavior also remains the same: when you hover the "i", you have the corresponding message showing up.

So now, why this PR then? I realized recently that we were actually generating those messages into the HTML every time whereas all messages are the same (except for the edition ones, I'll come back to it later). So instead of generating more content, I simply moved it inside the CSS thanks to pseudo elements (`::before` and `::after`). The message is now inside `::after` and we use the `::before` to have the small triangle on the left of the message. So now, we have less HTML generated which is seems pretty nice.

So now, back to the `edition` change: the message is globally the same, but the "edition" itself can be different (2015 or 2018 currently, I expect 2021 to arrive not too far in the future). So the only difference for it is that I added a new attribute on the tooltip called `edition` which contains this information. Then, the `::after` uses it inside its `content` (you can get the content of an element's attribute by using `attr` and concat different strings by simply having them after the other).

Don't hesitate if a part of my explanations isn't clear.

r? `@jyn514`
2020-12-24 15:22:28 +00:00
Guillaume Gomez
152d4e74be Update HTML DOM attribute "edition" to "data-edition" 2020-12-23 20:27:12 +01:00
Joshua Nelson
ceb66ad464 Add more tests 2020-12-23 09:23:05 -05:00
Joshua Nelson
530c33cd5f Fix elided lifetimes shown as '_ on async functions 2020-12-22 20:49:33 -05:00
Joshua Nelson
4092891a8f Fix intra-doc links for non-path primitives
This does *not* currently work for associated items that are
auto-implemented by the compiler (e.g. `never::eq`), because they aren't
present in the source code. I plan to fix this in a follow-up PR.
2020-12-22 11:45:23 -05:00
Aaron Hill
f2d7c05db0
Don't try to add nested predicate to Rustdoc auto-trait ParamEnv
Fixes #80233

We already have logic in `evaluate_predicates` that tries to add
unimplemented predicates to our `ParamEnv`. Trying to add a predicate
that already holds can lead to errors later on, since projection
will prefer trait candidates from the `ParamEnv` to predicates from an
impl.
2020-12-20 21:10:29 -05:00
bstrie
1e1ca28f39 Allow since="TBD" for rustc_deprecated 2020-12-16 13:21:24 -05:00
Dániel Buga
fa64c272c8 Add test case for Self:: links 2020-12-14 11:00:54 +01:00
bors
9eb3a7ceaf Auto merge of #79349 - Nemo157:issue-79201, r=jyn514
Apply `doc(cfg)` from parent items while collecting trait impls

Because trait impls bypass the standard `clean` hierarchy they do not participate in the `propagate_doc_cfg` pass, so instead we need to pre-collect all possible `doc(cfg)` attributes that will apply to them when cleaning.

fixes #79201
2020-12-11 22:00:00 +00:00
Vadim Petrochenkov
31d72c2658 Accept arbitrary expressions in key-value attributes at parse time 2020-12-09 21:37:32 +03:00
bors
d577c535b4 Auto merge of #78609 - lcnr:rustdoc-const-eval, r=matthewjasper
extend `WithOptConstParam` docs, move rustdoc test

This should hopefully make things a bit clearer, feel free to comment on anything which can still be improved.

cc `@ecstatic-morse` `@nikomatsakis` `@RalfJung`
2020-12-06 13:03:45 +00:00
Guillaume Gomez
9b62936928 Update tests 2020-12-05 20:15:40 +01:00
Dylan DPC
5495bb97a0
Rollup merge of #79638 - jyn514:intra-link-self-raw, r=Manishearth
Use `item_name` instead of pretty printing for resolving `Self` on intra-doc links

Pretty printing would add a `r#` prefix to raw identifiers, which was
not correct. In general I think this change makes sense -
pretty-printing is for showing to the *user*, `item_name` is suitable to
pass to resolve.

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

r? `@Manishearth`
2020-12-04 03:30:34 +01:00
Camelid
5d4a7128d9 Render Markdown in search results
Previously Markdown documentation was not rendered to HTML for search results,
which led to the output not being very readable, particularly for inline code.
This PR fixes that by rendering Markdown to HTML with the help of pulldown-cmark
(the library rustdoc uses to parse Markdown for the main text of documentation).
However, the text for the title attribute (the text shown when you hover over an
element) still uses the plain-text rendering since it is displayed in browsers
as plain-text.

Only these styles will be rendered; everything else is stripped away:

* *italics*
* **bold**
* `inline code`
2020-12-03 14:11:37 -08:00
Joshua Nelson
4e7a2dcabb Use item_name instead of pretty printing
Pretty printing would add a `r#` prefix to raw identifiers, which was
not correct. In general I think this change makes sense -
pretty-printing is for showing to the *user*, `item_name` is suitable to
pass to resolve.
2020-12-02 10:25:16 -05:00
Bastian Kauschke
b8defab08d rustdoc: move lazy norm tests into const-generics 2020-12-01 22:36:43 +01:00
Mara Bos
33d7b8c65c
Rollup merge of #79548 - CraftSpider:76998, r=jyn514
Show since when a function is const in stdlib

Fixes #76998

This makes it so that functions with the `#[rustc_const_stable()]` attribute now show from what version they were stably declared const, alongside what version they were declared stable. Example from `Result`:
![image](https://user-images.githubusercontent.com/13342132/100561194-1be60d00-3286-11eb-99ff-1e81201218a9.png)

r? ``@jyn514``
2020-12-01 10:50:21 +00:00
Mara Bos
f45e6953d7
Rollup merge of #79527 - jyn514:intra-doc-tests, r=Manishearth
Move intra-doc link tests into a subdirectory

They were starting to get unwieldy.

r? ``@Manishearth``
2020-12-01 10:50:19 +00:00
Mara Bos
99e075ff29
Rollup merge of #79525 - jyn514:feature-gate-normalize, r=GuillaumeGomez
Add -Z normalize-docs and enable it for compiler docs

Works around https://github.com/rust-lang/rust/issues/79459 by only enabling normalization for the compiler itself (and anyone who opts-in on nightly). Eventually I want to remove this and enable normalization by default, but that's turned out to be [really hard](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20do.20I.20normalize.20projection.20types.20to.20a.20single.20type.3F/near/218125195).

This uses a command line option instead of a feature gate so it's easier to pass it to all crates at once. Theoretically it's better to use a feature gate instead so that it's easier for people to use on docs.rs, but I'm also not terribly concerned with how easy it to use a temporary hack.

Addresses https://github.com/rust-lang/rust/issues/77459.
2020-12-01 10:50:18 +00:00
bors
b7ebc6b0c1 Auto merge of #76467 - jyn514:intra-link-self, r=Manishearth
Fix intra-doc links for `Self` on cross-crate items and primitives

- Remove the difference between `parent_item` and `current_item`; these
  should never have been different.
- Remove `current_item` from `resolve` and `variant_field` so that
  `Self` is only substituted in one place at the very start.
- Resolve the current item as a `DefId`, not a `HirId`. This is what
  actually fixed the bug.

Hacks:
- `clean` uses `TypedefItem` when it _really_ should be
  `AssociatedTypeItem`. I tried fixing this without success and hacked
  around it instead (see comments)
- This second-guesses the `to_string()` impl since it wants
  fully-qualified paths. Possibly there's a better way to do this.
2020-11-30 09:00:52 +00:00
Rune Tynan
ccbb0f5c1a
Add support for stable-const-since in docs on items (standalone or assoc) 2020-11-29 21:00:14 -05:00
Joshua Nelson
95a6427d2c Add -Z normalize-docs and enable it for compiler docs 2020-11-29 17:21:24 -05:00
Joshua Nelson
2b17f02561 Add test for cross-crate Self 2020-11-29 13:52:51 -05:00
Joshua Nelson
6ab1f05697 Fix intra-doc links for Self on primitives
- Remove the difference between `parent_item` and `current_item`; these
  should never have been different.
- Remove `current_item` from `resolve` and `variant_field` so that
  `Self` is only substituted in one place at the very start.
- Resolve the current item as a `DefId`, not a `HirId`. This is what
  actually fixed the bug.

Hacks:
- `clean` uses `TypedefItem` when it _really_ should be
  `AssociatedTypeItem`. I tried fixing this without success and hacked
  around it instead (see comments)
- This stringifies DefIds, then resolves them a second time. This is
  really silly and rustdoc should just use DefIds throughout. Fixing
  this is a larger task than I want to take on right now.
2020-11-29 13:40:08 -05:00
bors
af780e569d Auto merge of #78380 - bstrie:rm-old-num-const-from-tests, r=jyn514
Update tests to remove old numeric constants

Part of #68490.

Care has been taken to leave the old consts where appropriate, for testing backcompat regressions, module shadowing, etc. The intrinsics docs were accidentally referring to some methods on f64 as std::f64, which I changed due to being contrary with how we normally disambiguate the shadow module from the primitive. In one other place I changed std::u8 to std::ops since it was just testing path handling in macros.

For places which have legitimate uses of the old consts, deprecated attributes have been optimistically inserted. Although currently unnecessary, they exist to emphasize to any future deprecation effort the necessity of these specific symbols and prevent them from being accidentally removed.
2020-11-29 14:29:23 +00:00
bors
3cbb56f80b Auto merge of #79455 - CraftSpider:master, r=jyn514
Remove doctree::Macro and distinguish between `macro_rules!` and `pub macro`

This is a part of #78082, removing doctree::Macro. Uses the changes in #79372

Fixes #76761
2020-11-29 07:05:49 +00:00
bstrie
90a2e5e3fe Update tests to remove old numeric constants
Part of #68490.

Care has been taken to leave the old consts where appropriate, for testing backcompat regressions, module shadowing, etc. The intrinsics docs were accidentally referring to some methods on f64 as std::f64, which I changed due to being contrary with how we normally disambiguate the shadow module from the primitive. In one other place I changed std::u8 to std::ops since it was just testing path handling in macros.

For places which have legitimate uses of the old consts, deprecated attributes have been optimistically inserted. Although currently unnecessary, they exist to emphasize to any future deprecation effort the necessity of these specific symbols and prevent them from being accidentally removed.
2020-11-29 00:55:55 -05:00
Rune Tynan
d23b57c1a8
Add test for macro by example syntax in decl macros with only one option 2020-11-28 21:32:07 -05:00
Dylan DPC
ca8a1b05c6
Rollup merge of #79464 - GuillaumeGomez:doc-keyword-ident, r=jyn514
Extend doc keyword feature by allowing any ident

Part of #51315.

As suggested by ``@danielhenrymantilla`` in [this comment](https://github.com/rust-lang/rust/issues/51315#issuecomment-733879934), this PR extends `#[doc(keyword = "...")]` to allow any ident to be used as keyword. The final goal is to allow (proc-)macro crates' owners to write documentation of the keywords they might introduce.

r? ``@jyn514``
2020-11-29 03:14:21 +01:00
Dylan DPC
858b44a433
Rollup merge of #79340 - GuillaumeGomez:rename-stability, r=jyn514
Rename "stability" CSS class to "item-info" and combine `document_stability` with `document_short`

Follow-up of #79300

The point of this PR is to make the CSS class more accurate since it's not only about stability anymore.

r? ``@jyn514``
2020-11-29 03:14:13 +01:00
Joshua Nelson
ddfb581fb9 Move src/test/rustdoc intra-doc link tests into a subdirectory
They were starting to get unwieldy.
2020-11-28 21:13:55 -05:00
Rune Tynan
ff690931b7
Add support for multi-argument decl macros 2020-11-28 20:51:48 -05:00
Rune Tynan
a61c09a897
Update src/test/rustdoc/decl_macro_priv.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-11-28 00:02:46 -05:00
Rune Tynan
949b72e9d9
Update decl_macro test, add decl_macro_priv test for --document-private-items 2020-11-27 21:59:21 -05:00
Rune Tynan
c007f4354d
Add test, fix pub macro impl, compile error 2020-11-27 21:59:20 -05:00
oli
8b81bb8715 Revert the effect of #77467 by disabling normalization in rustdoc 2020-11-27 17:08:49 +00:00
Guillaume Gomez
af2040ff95 Add tests for doc_keyword feature extension 2020-11-27 17:54:28 +01:00
bors
65ecc481fa Auto merge of #77467 - jyn514:query-docs, r=oli-obk
Normalize `<X as Y>::T` for rustdoc

- Only run for `QPath::Resolved` with `Some` self parameter (`<X as Y>::T`)
- Fall back to the previous behavior if the path can't be resolved

The first commit is a pure refactor and should probably be reviewed by `@GuillaumeGomez.` I recommend reviewing the second commit on its own.

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

r? `@eddyb`
cc `@danielhenrymantilla` , `@lcnr`
2020-11-26 16:31:12 +00:00
Jonas Schievink
7b723795ef
Rollup merge of #79412 - GuillaumeGomez:cleanup-rustdoc-tests, r=jyn514
Clean up rustdoc tests by removing unnecessary features

r? ``@jyn514``
2020-11-26 13:39:13 +01:00
Guillaume Gomez
d61ea56884 Clean up rustdoc tests by removing unnecessary features 2020-11-25 14:27:51 +01:00
bors
ec039bd075 Auto merge of #79336 - camelid:rename-feature-oibit-to-auto, r=oli-obk
Rename `optin_builtin_traits` to `auto_traits`

They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.

r? `@oli-obk` (feel free to re-assign if you're not the right reviewer for this)
2020-11-25 07:25:19 +00:00
Camelid
82dc99ba7a Use the name "auto traits" everywhere in the compiler
Goodbye, OIBIT!
2020-11-24 16:25:43 -08:00
Joshua Nelson
6278daac54 Track ParamEnvs properly
This uses the same `with_param_env` pattern that late lints use.
Thanks to all the doctree refactors, this was very easy to add.
2020-11-24 14:10:18 -05:00
Joshua Nelson
a192e5d9c2 Normalize <X as Y>::T for rustdoc
- Only run for `QPath::Resolved` with `Some` self parameter (`<X as Y>::T`)
- Fall back to the previous behavior if the path can't be resolved
- Show what the behavior is if the type can't be normalized
- Run `resolve_vars_if_possible`

  It's not clear whether or not this is necessary. See
  https://github.com/rust-lang/rust/pull/77616 for more context.

- Add a test for cross-crate re-exports
- Use the same code for both `hir::Ty` and `Ty`
2020-11-24 14:10:18 -05:00
Guillaume Gomez
caf6c5790a Rename "stability" CSS class to "item-info" 2020-11-24 18:07:03 +01:00
Camelid
810324d1f3 Rename optin_builtin_traits to auto_traits
They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.
2020-11-23 14:14:06 -08:00
Wim Looman
d93f1d6c04
Apply doc(cfg) from parent items while collecting trait impls
Because trait impls bypass the standard `clean` hierarchy they do not
participate in the `propagate_doc_cfg` pass, so instead we need to
pre-collect all possible `doc(cfg)` attributes that will apply to them
when cleaning.
2020-11-23 17:47:29 +01:00
Camelid
0b6537a9ea Accept '!' in intra-doc links
This will allow linking to things like `Result<T, !>`.
2020-11-22 14:25:50 -08:00
bors
a1a13b2bc4 Auto merge of #78461 - TimDiekmann:vec-alloc, r=Amanieu
Add support for custom allocators in `Vec`

This follows the [roadmap](https://github.com/rust-lang/wg-allocators/issues/7) of the allocator WG to add custom allocators to collections.

r? `@Amanieu`

This pull request requires a crater run.

### Prior work:
- #71873: Crater-test to solve rust-lang/wg-allocators#1
- [`alloc-wg`](https://github.com/TimDiekmann/alloc-wg)-crate
2020-11-21 22:46:50 +00:00
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
Tim Diekmann
8725e4c337 Add support for custom allocators in Vec 2020-11-18 19:34:19 +01: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
Lzu Tao
7dd4582f95 Add ui test for 74672 and 76571
These tests will fall without the next commit.
2020-09-13 05:27:10 +00:00
SlightlyOutOfPhase
8a1288be74
Give functions unique names 2020-09-12 11:24:19 -04:00
SlightlyOutOfPhase
9c1389418e
Fix const-display.rs XPATH queries (#1)
* Fix `const-display.rs` XPATH queries

* Add `issue_76501.rs` test file

* Rename issue_76501.rs to issue-76501.rs
2020-09-12 10:52:12 -04:00
Ralf Jung
5d90d6ee90
Rollup merge of #76297 - lcnr:const-ty-alias, r=varkor
rustdoc: fix min_const_generics with ty::Param

fixes #75913

r? @varkor cc @jyn514
2020-09-12 10:43:15 +02:00
Dylan DPC
f1eb5f800f
Rollup merge of #76082 - jyn514:top-level-links, r=ollie27,GuillaumeGomez
Fix intra-doc links on pub re-exports

Partial fix for https://github.com/rust-lang/rust/issues/76073 - This removes the incorrect error, but doesn't show the documentation anywhere.
r? @GuillaumeGomez
2020-09-05 16:28:28 +02:00
Dylan DPC
ed39e6d60a
Rollup merge of #76078 - jyn514:no-disambiguator, r=manishearth
Remove disambiguators from intra doc link text

Closes https://github.com/rust-lang/rust/issues/65354.
r? @Manishearth

The commits are mostly atomic, but there might be some mix between them here and there. I recommend reading 'refactor ItemLink' and 'refactor RenderedLink' on their own though, lots of churn without any logic changes.
2020-09-05 16:28:26 +02:00
Joshua Nelson
18c14fde0d Misc cleanup
- Preserve suffixes when displaying
- Rename test file to match `intra-link*`
- Remove unnecessary .clone()s
- Improve comments and naming
- Fix more bugs and add tests
- Escape intra-doc link example in public documentation
2020-09-04 08:27:56 -04:00
Bastian Kauschke
ccf1f58081 rustdoc: fix min_const_generics with ty::Param 2020-09-03 21:57:27 +02:00
bors
62dad457bc Auto merge of #73819 - euclio:rustdoc-summaries, r=jyn514,GuillaumeGomez
rustdoc: do not use plain summary for trait impls

Fixes #38386.
Fixes #48332.
Fixes #49430.
Fixes #62741.
Fixes #73474.

Unfortunately this is not quite ready to go because the newly-working links trigger a bunch of linkcheck failures. The failures are tough to fix because the links are resolved relative to the implementor, which could be anywhere in the module hierarchy.

(In the current docs, these links end up rendering as uninterpreted markdown syntax, so I don't think these failures are any worse than the status quo. It might be acceptable to just add them to the linkchecker whitelist.)

Ideally this could be fixed with intra-doc links ~~but it isn't working for me: I am currently investigating if it's possible to solve it this way.~~ Opened #73829.

EDIT: This is now ready!
2020-09-03 19:07:38 +00:00
Joshua Nelson
9815010d8f Remove disambiguators from link text
Related to https://github.com/rust-lang/rust/issues/65354

- Pass through the replacement text to `markdown.rs`
- Add some tests
- Add a state machine that actually replaces the text when parsing Markdown
2020-09-03 09:29:22 -04:00
Camelid
c86d249e94 Use "Fira Sans" for crate list font
Fira Sans is what's used for module lists and other item lists.
Previously, the default body font, "Source Serif Pro", was used for
crate lists, which didn't visually match other item lists.
2020-09-01 13:41:56 -07:00
Joshua Nelson
d7150154fa Improve tests
Now this actually tests the links are generated correctly
2020-08-30 12:06:40 -04:00
Andy Russell
e0822ecdbc
rustdoc: do not use plain summary for trait impls
Fixes #38386.
Fixes #48332.
Fixes #49430.
Fixes #62741.
Fixes #73474.
2020-08-30 12:02:18 -04:00
Joshua Nelson
e885f00f24 Comment out test for generated docs until rustdoc changes its behavior around documenting re-exports 2020-08-30 11:16:19 -04:00
bors
db534b3ac2 Auto merge of #75176 - jyn514:impl-link, r=GuillaumeGomez,petrochenkov
Fix intra-doc links for cross-crate re-exports of default trait methods

The original fix for this was very simple: https://github.com/rust-lang/rust/pull/58972 ignored `extern_traits` because before https://github.com/rust-lang/rust/issues/65983 was fixed, they would always fail to resolve, giving spurious warnings. So the first commit just undoes that change, so extern traits are now seen by the `collect_intra_doc_links` pass. There are also some minor changes in `librustdoc/fold.rs` to avoid borrowing the `extern_traits` RefCell more than once at a time.

However, that brought up a much more thorny problem. `rustc_resolve` started giving 'error: cannot find a built-in macro with name `cfg`' when documenting `libproc_macro` (I still haven't been able to reproduce on anything smaller than the full standard library). The chain of events looked like this (thanks @eddyb for the help debugging!):

0. `x.py build --stage 1` builds the standard library and creates a sysroot
1. `cargo doc` does something like `cargo check` to create `rmeta`s for all the crates (unrelated to what was built above)
2. the `cargo check`-like `libcore-*.rmeta` is loaded as a transitive dependency *and claims ownership* of builtin macros
3. `rustdoc` later tries to resolve some path in a doc link
4. suggestion logic fires and loads "extern prelude" crates by name
5. the sysroot `libcore-*.rlib` is loaded and *fails to claim ownership* of builtin macros

`rustc_resolve` gives the error after step 5. However, `rustdoc` doesn't need suggestions at all - `resolve_str_path_error` completely discards the `ResolutionError`! The fix implemented in this PR is to skip the suggestion logic for `resolve_ast_path`: pass `record_used: false` and skip `lookup_import_candidates` when `record_used` isn't set.

It's possible that if/when https://github.com/rust-lang/rust/issues/74207 is implemented this will need a more in-depth fix which returns a `ResolutionError` from `compile_macro`, to allow rustdoc to reuse the suggestions from rustc_resolve. However, that's a much larger change and there's no need for it yet, so I haven't implemented it here.

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

r? @GuillaumeGomez
2020-08-30 13:16:38 +00:00
bors
f6d910c852 Auto merge of #76093 - jyn514:prim-assoc-items, r=Manishearth
Fix intra-doc links for associated constants

Previously, only associated functions would be resolved. Fixes the issues in https://github.com/rust-lang/rust/pull/75969#discussion_r477898003.

I'm a little uncomfortable hard-coding the string constants, but it looks like that's how it's done elsewhere. I might make a follow-up PR at some point putting it in one place.

Not sure how to test associated types, since AFAIK there aren't any on primitives.

r? @Manishearth
2020-08-30 02:36:48 +00:00
Joshua Nelson
1404784992 Fix intra-doc links for associated constants
Previously, only associated functions would be resolved.
2020-08-29 21:37:08 -04:00
bors
ced37a53d9 Auto merge of #75775 - matklad:rustc-lexer-rustdoc-highlight, r=GuillaumeGomez
Use rustc_lexer for rustdoc syntax highlighting

r? @ghost
2020-08-29 22:42:08 +00:00
Joshua Nelson
868927fefb rustdoc: Fix intra-doc links for cross-crate re-exports of traits
#58972 ignored extern_traits because before #65983 was fixed, they
would always fail to resolve, giving spurious warnings.
This undoes that change, so extern traits are now seen by the
`collect_intra_doc_links` pass. There are also some minor changes in
librustdoc/fold.rs to avoid borrowing the extern_traits RefCell more
than once at a time.
2020-08-29 17:21:26 -04:00
Joshua Nelson
1b1935452f [WIP] Fix intra-doc links on pub re-exports
This removes the incorrect error, but doesn't show the documentation
anywhere.
2020-08-29 16:33:12 -04:00
Pietro Albini
8730c2beb7
Rollup merge of #75330 - Nemo157:improve-doc-cfg-features, r=GuillaumeGomez
Improve rendering of crate features via doc(cfg)

The current rendering of crate features with `doc(cfg(feature = ".."))` is verbose and unwieldy for users, `doc(cfg(target_feature = ".."))` is special-cased to make it render nicely, and a similar rendering can be applied to `doc(cfg(feature))` to make it easier for users to read.

I also added special casing of `all`/`any` cfgs consisting of just `feature`/`target-feature` to remove the repetitive "target/crate feature" prefix.

The downside of this current rendering is that there is no distinction between `feature` and `target_feature` in the shorthand display. IMO this is ok, or if anything `target_feature` should have a more verbose shorthand, because `doc(cfg(feature = ".."))` usage is going to vastly outstrip `doc(cfg(target_feature = ".."))` usage in non-stdlib crates when it eventually stabilizes (or even before that given the number of crates using `cfg_attr(docsrs)` like constructs).

## Previously

<img width="259" alt="Screenshot 2020-08-09 at 13 32 42" src="https://user-images.githubusercontent.com/81079/89731110-d090c000-da44-11ea-96fa-56adc6339123.png">
<img width="438" alt="image" src="https://user-images.githubusercontent.com/81079/89731116-d7b7ce00-da44-11ea-87c6-022d192d6eca.png">
<img width="765" alt="image" src="https://user-images.githubusercontent.com/81079/89731152-24030e00-da45-11ea-9552-1c270bff2729.png">
<img width="671" alt="image" src="https://user-images.githubusercontent.com/81079/89731158-28c7c200-da45-11ea-8acb-97d8a4ce00eb.png">

## Now

<img width="216" alt="image" src="https://user-images.githubusercontent.com/81079/89731123-e1d9cc80-da44-11ea-82a8-5900bd9448a5.png">
<img width="433" alt="image" src="https://user-images.githubusercontent.com/81079/89731127-e8684400-da44-11ea-9d18-572fd810f19f.png">
<img width="606" alt="image" src="https://user-images.githubusercontent.com/81079/89731162-2feed000-da45-11ea-98d2-8a88c364d903.png">
<img width="669" alt="image" src="https://user-images.githubusercontent.com/81079/89731991-ccb46c00-da4b-11ea-9416-cd20a3193826.png">

cc #43781
2020-08-28 10:23:53 +02:00
Aleksey Kladov
1f95a91c24 Remove dependency on StringReader from rustdoc highlighter
rustc_lexer is the lossless lexer, which is a better fit for
approximate syntax highlighting.

As a side-effect, we can now syntax-highlight even broken code.
2020-08-27 17:43:15 +02:00
Joshua Nelson
bcd6fe35e0 Update primitive test to match the new behavior 2020-08-23 22:40:20 -04:00
Joshua Nelson
42232ba70a rustdoc: Add support for associated items even outside the impl itself
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-22 00:25:28 -04:00
Joshua Nelson
aff01f8de9 Add test for f32 and f64 methods 2020-08-19 10:53:44 -04:00
Joshua Nelson
570b0d9ece Add a test 2020-08-19 08:26:31 -04:00
Wim Looman
3328bd9a0f Add long cfg description to tooltip on short description 2020-08-18 22:35:50 +02:00
Joshua Nelson
4f9cd74926 Resolve true and false as booleans 2020-08-17 20:13:58 -04:00
bors
4745cbe83e Auto merge of #75205 - Aaron1011:fix/auto-trait-proj-ice, r=nikomatsakis
Handle projection predicates in the param env for auto-trait docs

Fixes #72213

Any predicates in the param env are guaranteed to hold, so we don't need
to do any additional processing of them if we come across them as
sub-obligations of a different predicate. This allows us to avoid adding
the same predicate to the computed ParamEnv multiple times (but with
different regions each time), which causes an ambiguity error during
fulfillment.
2020-08-12 06:42:49 +00:00
bors
1275cc15d6 Auto merge of #74936 - GuillaumeGomez:const-rustc_const_unstable, r=jyn514
Don't print "const" keyword on non-nightly build if rustc_const_unstable is used on the item

Fixes #74579.
2020-08-10 17:12:42 +00:00
Guillaume Gomez
2a281e0a76 Add test for rustc_const_unstable on methods 2020-08-10 16:57:25 +02:00
Joshua Nelson
b11e2f2341 Give precedence to primitives over modules
This has less surprising behavior when there is a module with the same
name as a primitive in scope.
2020-08-09 08:34:21 -04:00
Wim Looman
234ec956ab Render longhand multiple crate/target features nicer 2020-08-09 14:20:11 +02:00
Wim Looman
a8de713e26 Improve rendering of crate features via doc(cfg) 2020-08-09 14:19:09 +02:00
Yuki Okushi
255434d83c
Rollup merge of #75237 - nbdd0121:rustdoc, r=jyn514
Display elided lifetime for non-reference type in doc

In edition 2018 we encourage writing `<'_>` explicitly, so rustdoc should display like such as well.

Fixes #75225

~~Somehow when I run the compiled rustdoc using `cargo +stage2 doc` on other crates, it correctly produces `<'_>`, but I couldn't get the std doc to do the same with `./x.py doc --stage 2`. Might this be related to the recent change to x.py about how the doc is built?~~
2020-08-08 11:36:03 +09:00
Gary Guo
541fbbb6fa Cross-crate doc inlining test case for elided lifetime 2020-08-08 01:07:43 +01:00
Gary Guo
505d157814 Display elided lifetime for external paths 2020-08-07 23:41:07 +01:00
Gary Guo
63c0d9ca51 Display elided lifetime for non-reference type in doc 2020-08-07 23:35:07 +01:00
Joshua Nelson
d240490229 Fix outdated code 2020-08-06 18:53:12 -04:00
Joshua Nelson
ef54cde625 Improve tests 2020-08-06 18:33:29 -04:00
Aaron Hill
ab766f0511
Handle projection predicates in the param env for auto-trait docs
Fixes #72213

Any predicates in the param env are guaranteed to hold, so we don't need
to do any additional processing of them if we come across them as
sub-obligations of a different predicate. This allows us to avoid adding
the same predicate to the computed ParamEnv multiple times (but with
different regions each time), which causes an ambiguity error during
fulfillment.
2020-08-05 20:22:55 -04:00
Joshua Nelson
519c85439a Don't mark associated items as traits
This caused the following false positive:

```
warning: unresolved link to `Default::default`
 --> /home/joshua/rustc2/default.rs:1:14
  |
1 | /// Link to [Default::default()]
  |              ^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(broken_intra_doc_links)]` on by default
note: this item resolved to a trait, which did not match the disambiguator 'fn'
 --> /home/joshua/rustc2/default.rs:1:14
  |
1 | /// Link to [Default::default()]
  |              ^^^^^^^^^^^^^^^^^^
```
2020-08-02 22:49:12 -04:00
Manish Goregaokar
98a9397c2a
Rollup merge of #74992 - lcnr:fix-generic-param-order, r=GuillaumeGomez
fix rustdoc generic param order

fixes #61292

r? @varkor cc @GuillaumeGomez
2020-08-01 17:42:15 -07:00
Bastian Kauschke
b90bc8d70b fix rustdoc generic param order 2020-07-31 23:51:19 +02:00
Manish Goregaokar
8fe438e632 intra_doc_resolution_failures -> broken_intra_doc_links 2020-07-30 10:38:55 -07:00
Manish Goregaokar
4df76f0f90 Rename to intra_doc_resolution_failures 2020-07-30 08:14:27 -07:00
Manish Goregaokar
48de8ac041 Rename usage of intra_doc_link_resolution_failure 2020-07-29 15:23:14 -07:00
Bastian Kauschke
2a16bb085e handle ConstEquate in rustdoc 2020-07-29 00:00:55 +02:00
Mark Rousskov
e24a0172b0 Only skip impls of foreign unstable traits
Previously unstable impls were skipped, which meant that any impl with an
unstable method would get skipped.
2020-07-19 16:39:20 -04:00
Manish Goregaokar
69dab50762 Add test for module ambiguity 2020-07-17 13:04:54 -07:00
Manish Goregaokar
90c678cb03 Update src/test/rustdoc/intra-doc-crate/auxiliary/hidden.rs
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-07-16 22:22:48 -07:00
Manish Goregaokar
50d350b67c Add test for doc(hidden) intra-doc cross-crate reexports 2020-07-16 22:22:40 -07:00
Manish Goregaokar
0e70884083
Rollup merge of #74351 - lzutao:remove-rustc-internal-compiler-warns, r=Mark-Simulacrum
Do not render unstable items for rustc doc

See the zulip conversion: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/rustc.20doc.3A.20.22internal.20compiler.20API.22.20warns.20are.20everywhere!/near/203850782

Before:
![image](https://user-images.githubusercontent.com/15225902/87501971-9cff8780-c68a-11ea-93b4-ea53ce18a77b.png)
After:
![image](https://user-images.githubusercontent.com/15225902/87501985-a7218600-c68a-11ea-81c0-a6b5b120832c.png)

Nothing changes in unstable items of std:
Before:
![image](https://user-images.githubusercontent.com/15225902/87502004-b7d1fc00-c68a-11ea-9224-a27a1d2a81d6.png)
After:
![image](https://user-images.githubusercontent.com/15225902/87502018-c0c2cd80-c68a-11ea-9773-4c63158025cb.png)

Closes  #54682
2020-07-16 17:08:59 -07:00
Joshua Nelson
c46e0386c5 Fix invalid lint
intra_doc_resolution_failure is not a lint.
2020-07-16 18:26:58 -04:00
Joshua Nelson
8387e3825f Add (broken and ignored) test for #73829 2020-07-16 18:26:58 -04:00
Joshua Nelson
82b3b0705b Support intra-doc links on trait and module re-exports
Trait implementations are treated the same as modules for the purposes
of intra-doc links.
2020-07-16 18:26:58 -04:00
Joshua Nelson
e63e5cdab0 Support intra-doc links on macro re-exports
This includes both `macro_rules!` and proc-macros.
2020-07-16 18:26:58 -04:00
Joshua Nelson
5f49f55eb4 rand -> my_rand
This fixes a failure in stage2 rustdoc tests.
2020-07-16 18:26:58 -04:00
Joshua Nelson
769acbaca0 #![deny(intra_doc_resolution_failure)] 2020-07-16 18:26:58 -04:00
Joshua Nelson
71fe8f7cd8 Add test for submodules in inner crate 2020-07-16 18:26:58 -04:00
Joshua Nelson
9eb63945eb Add test for documenting the re-export 2020-07-16 18:26:58 -04:00
Joshua Nelson
e78d499637 Add test for re-exports
I had a hard time getting this to work without the `extern crate`,
suggestions are welcome.
2020-07-16 18:26:57 -04:00
Joshua Nelson
9542e23a7d Add tests for basic intra-doc links 2020-07-16 18:26:57 -04:00
Manish Goregaokar
fc098170ce
Rollup merge of #74370 - Manishearth:re-spotlight, r=GuillaumeGomez
Reintroduce spotlight / "important traits" feature

(Reopened version of https://github.com/rust-lang/rust/pull/74111 because Github is broken, see discussion there)

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

This PR reintroduces the "spotlight" ("important traits") feature.

A couple changes have been made:

As there were concerns about its visibility, it has been moved to be next to the return type, as opposed to being on the side.

It also no longer produces a modal, it shows the traits on hover, and it can be clicked on to pin the hover bubble.

![image](https://user-images.githubusercontent.com/1617736/86674555-a82d2600-bfad-11ea-9a4a-a1a9ffd66ae5.png)

![image](https://user-images.githubusercontent.com/1617736/86674533-a1061800-bfad-11ea-9e8a-c62ad86ed0d7.png)

It also works fine on mobile:

![image](https://user-images.githubusercontent.com/1617736/86674638-bda25000-bfad-11ea-8d8d-1798b608923e.png)
2020-07-16 11:18:55 -07:00
Manish Goregaokar
98450757e5 Revert "Remove "important traits" feature"
This reverts commit 1244ced958.
2020-07-16 09:58:17 -07:00
Joshua Nelson
d01044305a Add test case for #65863 2020-07-15 10:54:05 -04:00
Joshua Nelson
768d6a4950 Don't ICE on errors in function returning impl trait
Instead, report the error.

This emits the errors on-demand, without special-casing `impl Trait`, so
it should catch all ICEs of this kind, including ones that haven't been
found yet.

Since the error is emitted during type-checking there is less info about
the error; see comments in the code for details.

- Add test case for -> impl Trait
- Add test for impl trait with alias
- Move EmitIgnoredResolutionErrors to rustdoc

This makes `fn typeck_item_bodies` public, which is not desired behavior.
That change should be removed once
https://github.com/rust-lang/rust/pull/74070 is merged.

- Don't visit nested closures twice
2020-07-15 10:54:05 -04:00
Dylan MacKenzie
14a8707cde Add rustdoc tests from #72088 2020-07-15 10:54:05 -04:00
Joshua Nelson
1b8accb749 Add an option not to report resolution errors for rustdoc
- Remove unnecessary `should_loop` variable
- Report errors for trait implementations

These should give resolution errors because they are visible outside the
current scope. Without these errors, rustdoc will give ICEs:

```
thread 'rustc' panicked at 'attempted .def_id() on invalid res: Err', /home/joshua/src/rust/src/libstd/macros.rs:16:9
  15: rustc_hir::def::Res<Id>::def_id
             at /home/joshua/src/rust/src/librustc_hir/def.rs:382
  16: rustdoc::clean::utils::register_res
             at src/librustdoc/clean/utils.rs:627
  17: rustdoc::clean::utils::resolve_type
             at src/librustdoc/clean/utils.rs:587
```

- Add much more extensive tests
  + fn -> impl -> fn
  + fn -> impl -> fn -> macro
  + errors in function parameters
  + errors in trait bounds
  + errors in the type implementing the trait
  + unknown bounds for the type
  + unknown types in function bodies
  + errors generated by macros

- Use explicit state instead of trying to reconstruct it from random info
- Use an enum instead of a boolean
- Add example of ignored error
2020-07-15 10:54:05 -04:00