Commit graph

139452 commits

Author SHA1 Message Date
Camelid
ff39c46959 Box some fields to reduce Context size
Reduced from 152 bytes to 88 bytes.
2021-03-05 19:41:27 -08:00
Camelid
4c51a66d67 Don't share id_map and deref_id_map
All the tests passed, so it doesn't seem they need to be shared.
Plus they should be item/page-specific.

I'm not sure why they were shared before. I think the reason `id_map`
worked as a shared value before is that it is cleared before rendering
each item (in `render_item`). And then I'm guessing `deref_id_map`
worked because it's a hashmap keyed by `DefId`, so there was no overlap
(though I'm guessing we could have had issues in the future).

Note that `id_map` currently still has to be cleared because otherwise
child items would inherit the `id_map` of their parent. I'm hoping to
figure out a way to stop cloning `Context`, but until then we have to
reset `id_map`.
2021-03-05 19:40:54 -08:00
Camelid
3bc879e76b rustdoc: Add static size assertion for Context
It's cloned a lot, so we don't want it to grow in size unexpectedly.

Only run the assert on x86-64 since the size is architecture-dependent.
2021-03-05 19:39:17 -08:00
Camelid
b3d2a371bb rustdoc: Make a bunch of fields private
Also create issue for removing shared mutable state.
2021-03-05 19:39:08 -08:00
Camelid
c4bb66c284 rustdoc: Replace Arc around SharedContext with Rc
It doesn't look like it's shared across threads, so it doesn't need to
be thread-safe. Of course, since we're using Rust, we'll get an error if
we try to share it across threads, so this should be safe :)
2021-03-05 18:08:01 -08:00
Camelid
9763eb87a3 rustdoc: Move most shared fields to SharedContext
...and remove `Rc`s for the moved fields.

The only shared one that I didn't move was `cache`; see the doc-comment
I added to `cache` for details.
2021-03-05 17:57:58 -08:00
bors
8fd946c63a Auto merge of #82795 - m-ou-se:rollup-uzx0b92, r=m-ou-se
Rollup of 10 pull requests

Successful merges:

 - #80723 (Implement NOOP_METHOD_CALL lint)
 - #80763 (resolve: Reduce scope of `pub_use_of_private_extern_crate` deprecation lint)
 - #81136 (Improved IO Bytes Size Hint)
 - #81939 (Add suggestion `.collect()` for iterators in iterators)
 - #82289 (Fix underflow in specialized ZipImpl::size_hint)
 - #82728 (Avoid unnecessary Vec construction in BufReader)
 - #82764 (Add {BTreeMap,HashMap}::try_insert)
 - #82770 (Add assert_matches macro.)
 - #82773 (Add diagnostic item to `Default` trait)
 - #82787 (Remove unused code from main.js)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-03-05 13:34:33 +00:00
Mara
16518e70fb
Rollup merge of #82787 - notriddle:main-js-cleanup, r=GuillaumeGomez
Remove unused code from main.js

It looks like `lev_distance` was used in a very old version of the function, since it was written but never read, and Blame reports that it was added before the `checkGenerics` function header itself.

`convertHTMLToPlaintext` is was removed by 768d5e9509
2021-03-05 10:57:25 +01:00
Mara
2cd1f79aa1
Rollup merge of #82773 - mgacek8:feature/add_diagnostic_item_to_Default_trait, r=oli-obk
Add diagnostic item to `Default` trait

This PR adds diagnostic item to `Default` trait to be used by rust-lang/rust-clippy#6562 issue.
Also fixes the obsolete path to the `symbols.rs` file in the comment.
2021-03-05 10:57:24 +01:00
Mara
04045cc83f
Rollup merge of #82770 - m-ou-se:assert-match, r=joshtriplett
Add assert_matches macro.

This adds `assert_matches!(expression, pattern)`.

Unlike the other asserts, this one ~~consumes the expression~~ may consume the expression, to be able to match the pattern. (It could add a `&` implicitly, but that's noticable in the pattern, and will make a consuming guard impossible.)

See https://github.com/rust-lang/rust/issues/62633#issuecomment-790737853

This re-uses the same `left: .. right: ..` output as the `assert_eq` and `assert_ne` macros, but with the pattern as the right part:

assert_eq:
```
assertion failed: `(left == right)`
  left: `Some("asdf")`,
 right: `None`
```
assert_matches:
```
assertion failed: `(left matches right)`
  left: `Ok("asdf")`,
 right: `Err(_)`
```

cc ```@cuviper```
2021-03-05 10:57:23 +01:00
Mara
232caad395
Rollup merge of #82764 - m-ou-se:map-try-insert, r=Amanieu
Add {BTreeMap,HashMap}::try_insert

`{BTreeMap,HashMap}::insert(key, new_val)` returns `Some(old_val)` if the key was already in the map. It's often useful to assert no duplicate values are inserted.

We experimented with `map.insert(key, val).unwrap_none()` (https://github.com/rust-lang/rust/issues/62633), but decided that that's not the kind of method we'd like to have on `Option`s.

`insert` always succeeds because it replaces the old value if it exists. One could argue that `insert()` is never the right method for panicking on duplicates, since already handles that case by replacing the value, only allowing you to panic after that already happened.

This PR adds a `try_insert` method that instead returns a `Result::Err` when the key already exists. This error contains both the `OccupiedEntry` and the value that was supposed to be inserted. This means that unwrapping that result gives more context:
```rust
    map.insert(10, "world").unwrap_none();
    // thread 'main' panicked at 'called `Option::unwrap_none()` on a `Some` value: "hello"', src/main.rs:8:29
```

```rust
    map.try_insert(10, "world").unwrap();
    // thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value:
    // OccupiedError { key: 10, old_value: "hello", new_value: "world" }', src/main.rs:6:33
```

It also allows handling the failure in any other way, as you have full access to the `OccupiedEntry` and the value.

`try_insert` returns a reference to the value in case of success, making it an alternative to `.entry(key).or_insert(value)`.

r? ```@Amanieu```

Fixes https://github.com/rust-lang/rfcs/issues/3092
2021-03-05 10:57:22 +01:00
Mara
68f2934a15
Rollup merge of #82728 - calebsander:refactor/bufreader-buf, r=m-ou-se
Avoid unnecessary Vec construction in BufReader

As mentioned in #80460, creating a `Vec` and calling `Vec::into_boxed_slice()` emits unnecessary calls to `realloc()` and `free()`. Updated the code to use `Box::new_uninit_slice()` to create a boxed slice directly. I think this also makes it more explicit that the initial contents of the buffer are uninitialized.

r? ``@m-ou-se``
2021-03-05 10:57:20 +01:00
Mara
ee796c6523
Rollup merge of #82289 - SkiFire13:fix-issue-82282, r=m-ou-se
Fix underflow in specialized ZipImpl::size_hint

Fixes #82282
2021-03-05 10:57:19 +01:00
Mara
20887b7ebf
Rollup merge of #81939 - kper:fixing-81584-allocate-in-iter, r=davidtwco
Add suggestion `.collect()` for iterators in iterators

Closes #81584

```
error[E0515]: cannot return value referencing function parameter `y`
 --> main3.rs:4:38
  |
4 | ...                   .map(|y| y.iter().map(|x| x + 1))
  |                                -^^^^^^^^^^^^^^^^^^^^^^
  |                                |
  |                                returns a value referencing data owned by the current function
  |                                `y` is borrowed here
  |                                help: Maybe use `.collect()` to allocate the iterator
```

Added the suggestion: `help: Maybe use `.collect()` to allocate the iterator`
2021-03-05 10:57:18 +01:00
Mara
60138110d7
Rollup merge of #81136 - Xavientois:io_reader_size_hint, r=cramertj
Improved IO Bytes Size Hint

After trying to implement better `size_hint()` return values for `File` in [this PR](https://github.com/rust-lang/rust/pull/81044) and changing to implementing it for `BufReader` in [this PR](https://github.com/rust-lang/rust/pull/81052), I have arrived at this implementation that provides tighter bounds for the `Bytes` iterator of various readers including `BufReader`, `Empty`, and `Chain`.

Unfortunately, for `BufReader`, the size_hint only improves after calling `fill_buffer` due to it using the contents of the buffer for the hint. Nevertheless, the the tighter bounds  should result in better pre-allocation of space to handle the contents of the `Bytes` iterator.

Closes #81052
2021-03-05 10:57:17 +01:00
Mara
ec2619ca62
Rollup merge of #80763 - petrochenkov:pubusecrate, r=estebank
resolve: Reduce scope of `pub_use_of_private_extern_crate` deprecation lint

This lint was deny-by-default since July 2017, crater showed 7 uses on crates.io back then (https://github.com/rust-lang/rust/pull/42894#issuecomment-311921147).

Unfortunately, the construction `pub use foo as bar` where `foo` is `extern crate foo;` was used by an older version `bitflags`, so turning it into an error causes too many regressions.
So, this PR reduces the scope of the lint instead of turning it into a hard error, and only turns some more rarely used components of it into errors.
2021-03-05 10:57:15 +01:00
Mara
e6a6df5daa
Rollup merge of #80723 - rylev:noop-lint-pass, r=estebank
Implement NOOP_METHOD_CALL lint

Implements the beginnings of https://github.com/rust-lang/lang-team/issues/67 - a lint for detecting noop method calls (e.g, calling `<&T as Clone>::clone()` when `T: !Clone`).

This PR does not fully realize the vision and has a few limitations that need to be addressed either before merging or in subsequent PRs:
* [ ] No UFCS support
* [ ] The warning message is pretty plain
* [ ] Doesn't work for `ToOwned`

The implementation uses [`Instance::resolve`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/instance/struct.Instance.html#method.resolve) which is normally later in the compiler. It seems that there are some invariants that this function relies on that we try our best to respect. For instance, it expects substitutions to have happened, which haven't yet performed, but we check first for `needs_subst` to ensure we're dealing with a monomorphic type.

Thank you to ```@davidtwco,``` ```@Aaron1011,``` and ```@wesleywiser``` for helping me at various points through out this PR ❤️.
2021-03-05 10:57:14 +01:00
bors
8ccc89bc31 Auto merge of #82777 - GuillaumeGomez:rollup-etcsupl, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #76716 (Don't warn for `missing_doc_examples` when item is #[doc(hidden)])
 - #82088 (Shorten html::render)
 - #82690 (Update rustdoc documentation)
 - #82752 (Add a regression test for issue-81712)
 - #82765 (Fix polymorphization ICE on associated types in trait decls using const generics in bounds)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-03-05 09:28:07 +00:00
bors
a0d66b54fb Auto merge of #71481 - estebank:inherit-stability, r=nikomatsakis
Inherit `#[stable(..)]` annotations in enum variants and fields from its item

Lint changes for #65515. The stdlib will have to be updated once this lands in beta and that version is promoted in master.
2021-03-05 05:28:07 +00:00
Michael Howell
ad91915455 Remove unused code from main.js
It looks like `lev_distance` was used in a very old version of the function,
since it was written but never read, and Blame reports that it was added
before the `checkGenerics` function header itself.

`convertHTMLToPlaintext` is was removed by 768d5e9509
2021-03-04 19:41:20 -07:00
Guillaume Gomez
f74231fd27
Rollup merge of #82765 - oli-obk:polymorphization_regression, r=davidtwco
Fix polymorphization ICE on associated types in trait decls using const generics in bounds

r? `@davidtwco`

only the last commit actually changes something
2021-03-04 21:56:35 +01:00
Guillaume Gomez
e89276baba
Rollup merge of #82752 - JohnTitor:gat-ice-test, r=jackh726
Add a regression test for issue-81712

Fixes #81712, also fixes #79768 as duplicate.
r? `@jackh726`
2021-03-04 21:56:34 +01:00
Guillaume Gomez
2a5ecb2927
Rollup merge of #82690 - jyn514:remove-pass-docs, r=Manishearth
Update rustdoc documentation

- Remove most of the information about passes. Passes are deprecated.
- Add `--document-private-items`; it was missing before.
- Update `--output-format json`; it was very outdated.
- Note that `--input-format` is deprecated.
- Move deprecated options to the very end.

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

r? `@Manishearth`
2021-03-04 21:56:33 +01:00
Guillaume Gomez
2f28361936
Rollup merge of #82088 - Nicholas-Baron:shorten_html_render, r=GuillaumeGomez
Shorten html::render

The `mod.rs` for librustdoc's `html::render` was over 3,000 lines. This PR reduces it to around 2,300 by
1. Moving `Context` and associated `impl`s to a separate file
2. Moving the `print_item` function and its helpers to a separate file
3. Moving `write_shared` and `write_minify` to their own file

Related to issue #60302.
Edit 1: `SharedContext` and related `impl`s is only 72 lines and so will not be moved.
2021-03-04 21:56:27 +01:00
Guillaume Gomez
95bbc7ef33
Rollup merge of #76716 - GuillaumeGomez:stop-complains-on-doc-hidden, r=jyn514
Don't warn for `missing_doc_examples` when item is #[doc(hidden)]

r? `@jyn514`
2021-03-04 21:56:27 +01:00
Mara Bos
80fcdef3b5 Add tracking issue for assert_matches. 2021-03-04 21:33:31 +01:00
Guillaume Gomez
1683cb12e4 Use cache access levels 2021-03-04 21:22:44 +01:00
Guillaume Gomez
e4287992a7 No more need for borrow call 2021-03-04 21:22:44 +01:00
Guillaume Gomez
ad30c39918 Pass TyCtxt directly instead of DocContext in librustdoc::visit_ast::inherits_doc_hidden 2021-03-04 21:22:43 +01:00
Guillaume Gomez
186f13914a Move visibility check inside the should_have_doc_example function 2021-03-04 21:22:43 +01:00
Guillaume Gomez
91095b1be5 Update missing code example test 2021-03-04 21:22:43 +01:00
Guillaume Gomez
4b30625094 Don't warn for missing_doc_examples when item is #[doc(hidden)] 2021-03-04 21:22:42 +01:00
bors
45b3c28518 Auto merge of #82747 - JohnTitor:pin-es-check-version, r=Mark-Simulacrum
Pin es-check version to prevent unrelated CI failures

es-check v5.2.1 causes a lot of unrelated CI failures on mingw-check, e.g. https://github.com/rust-lang/rust/pull/80723#issuecomment-790294196.
es-check v5.2.2 fixes it but let's pin its version to prevent further failures.
2021-03-04 19:24:21 +00:00
Joshua Nelson
dbdaa12486 Update rustdoc documentation
- Remove most of the information about passes. Passes are deprecated.
- Add `--document-private-items`; it was missing before.
- Update `--output-format json`; it was very outdated.
- Note that `--input-format` is deprecated.
- Move deprecated options to the very end.
- Move `passes.html` to the end of the table of contents. Ideally it
  would be removed altogether, but that causes mdbook not to generate the
  docs.
2021-03-04 14:07:34 -05:00
Mara Bos
f223affd7a Don't consume the expression in assert_matches!()'s failure case. 2021-03-04 19:36:36 +01:00
Nicholas-Baron
afb8220d0a Corrected imports for render tests and mod files
Due to a rebase, some edits were needed in the mod file.
2021-03-04 10:25:00 -08:00
Nicholas-Baron
fd14e38612 Moved write_shared to its own file 2021-03-04 10:24:56 -08:00
Mateusz Gacek
58d6f80f96 Fix comment with path to symbols! macro 2021-03-04 10:14:56 -08:00
Mateusz Gacek
a5951d4b23 Add diagnostic item to Default trait
Required to resolve #6562 rust-clippy issue.
2021-03-04 10:14:48 -08:00
Nicholas-Baron
14983b9812 Moved the make_item_keywords function to context.rs as it is only used there 2021-03-04 10:01:22 -08:00
Nicholas-Baron
6c7d7a6bf4 Moved print_item and helpers to a separate file 2021-03-04 10:01:22 -08:00
Nicholas-Baron
48167c499a Moved Context and its impls to a separate file 2021-03-04 10:01:22 -08:00
Mara Bos
5bd1204fc2 Fix assert_matches doc examples. 2021-03-04 18:41:43 +01:00
Mara Bos
0a8e401188 Add debug_assert_matches macro. 2021-03-04 18:12:33 +01:00
Mara Bos
cfce60ea37 Allow for multiple patterns and a guard in assert_matches. 2021-03-04 18:12:26 +01:00
Mara Bos
eb18746bc6 Add assert_matches!(expr, pat). 2021-03-04 18:07:20 +01:00
Mara Bos
eddd4f0501 Add tracking issue for map_try_insert. 2021-03-04 16:54:28 +01:00
Mara Bos
1aedb4c3a3 Remove unnecessary bound from HashMap::try_insert. 2021-03-04 16:46:41 +01:00
Oli Scherer
29f4aa753f Fixes -Zpolymorphize for src/test/ui/const-generics/auxiliary/crayte.rs 2021-03-04 15:45:31 +00:00
Oli Scherer
67a61b9a01 Typo 2021-03-04 15:45:31 +00:00