]> git.lizzy.rs Git - rust.git/log
rust.git
3 years agoRollup merge of #82751 - RalfJung:offset_from, r=dtolnay
Yuki Okushi [Sun, 7 Mar 2021 01:41:16 +0000 (10:41 +0900)]
Rollup merge of #82751 - RalfJung:offset_from, r=dtolnay

improve offset_from docs

`@thomcc` pointed out that the current docs leave it kind of unclear how one can satisfy the "no wrapping around `isize` or the address space" requirement of `offset_from`, so make the docs clearer about that.

FWIW, I don't think I entirely agree with that second paragraph about large objects (that I left mostly unchanged here). LLVM, to my knowledge, fundamentally assumes that all allocations fit into an `isize::MAX`. So in that sense creating a larger allocation is simply UB. I would expect a guarantee that Rust heap allocation methods will never return allocations larger than `isize::MAX` (or rather, Rust heap allocation methods should require that the `Layout` is no larger than `isize::MAX`). However, I cannot find any such requirement documented currently. Large allocations are not mentioned at all in the allocator docs, which is quite surprising -- even if we say that such allocations are not insta-UB (which I think is incompatible with LLVM), they are still extremely footgunny since `ptr::offset`/`ptr::add` do not support offsetting by more than `isize::MAX` bytes.

Furthermore, the allocator docs don't even say anything about allocations wrapping around the address space. But that is certainly something allocators must ensure never happens; we cannot expect clients to defend against this.

Cc `@rust-lang/wg-allocators`

3 years agoRollup merge of #82720 - henryboisdequin:fix-79040, r=oli-obk
Yuki Okushi [Sun, 7 Mar 2021 01:41:15 +0000 (10:41 +0900)]
Rollup merge of #82720 - henryboisdequin:fix-79040, r=oli-obk

Fix diagnostic suggests adding type `[type error]`

Fixes #79040

### Unresolved questions:

<del>Why does this change output the diagnostic twice (`src/test/ui/79040.rs`)?</del> Thanks `````@oli-obk`````

3 years agoRollup merge of #82651 - jyn514:rustdoc-warnings, r=GuillaumeGomez
Yuki Okushi [Sun, 7 Mar 2021 01:41:13 +0000 (10:41 +0900)]
Rollup merge of #82651 - jyn514:rustdoc-warnings, r=GuillaumeGomez

Cleanup rustdoc warnings

## Clean up error reporting for deprecated passes

Using `error!` here goes all the way back to the original commit, https://github.com/rust-lang/rust/pull/8540. I don't see any reason to use logging; rustdoc should use diagnostics wherever possible. See https://github.com/rust-lang/rust/pull/81932#issuecomment-785291244 for further context.

- Use spans for deprecated attributes
- Use a proper diagnostic for unknown passes, instead of error logging
- Add tests for unknown passes
- Improve some wording in diagnostics

##  Report that `doc(plugins)` doesn't work using diagnostics instead of `eprintln!`

This also adds a test for the output.

This was added in https://github.com/rust-lang/rust/pull/52194. I don't see any particular reason not to use diagnostics here, I think it was just missed in https://github.com/rust-lang/rust/pull/50541.

3 years agoRollup merge of #82592 - Lonami:patch-1, r=RalfJung
Yuki Okushi [Sun, 7 Mar 2021 01:41:12 +0000 (10:41 +0900)]
Rollup merge of #82592 - Lonami:patch-1, r=RalfJung

Improve transmute docs with further clarifications

Closes #82493.

Please let me know if any of the new wording sounds off, English is not my mother tongue.

3 years agoRollup merge of #82402 - jyn514:module-cache-refcell, r=GuillaumeGomez
Yuki Okushi [Sun, 7 Mar 2021 01:41:11 +0000 (10:41 +0900)]
Rollup merge of #82402 - jyn514:module-cache-refcell, r=GuillaumeGomez

Remove RefCell around `module_trait_cache`

This builds on https://github.com/rust-lang/rust/pull/82018 and should not be merged before.

## Don't require a `DocContext` for `report_diagnostic`

This is needed for the next commit, which needs mutable access to the `cx` from
within the `decorate` closure.

- Change `as_local_hir_id` to an associated function, since it only
  needs a `TyCtxt`
- Change `source_span_for_markdown_range` to only take a `TyCtxt`

##  Remove RefCell around module_trait_cache

This is mostly just changing lots of functions from `&DocContext` to `&mut DocContext`.

3 years agoRollup merge of #82292 - SkiFire13:fix-issue-82291, r=m-ou-se
Yuki Okushi [Sun, 7 Mar 2021 01:41:10 +0000 (10:41 +0900)]
Rollup merge of #82292 - SkiFire13:fix-issue-82291, r=m-ou-se

Prevent specialized ZipImpl from calling `__iterator_get_unchecked` twice with the same index

Fixes #82291

It's open for review, but conflicts with #82289, wait before merging. The conflict involves only the new test, so it should be rather trivial to fix.

3 years agoRollup merge of #82130 - jhpratt:const-option-result, r=RalfJung
Yuki Okushi [Sun, 7 Mar 2021 01:41:09 +0000 (10:41 +0900)]
Rollup merge of #82130 - jhpratt:const-option-result, r=RalfJung

Make some Option, Result methods unstably const

The following methods are now unstably const:

- Option::transpose
- Option::flatten
- Result::flatten

While some methods for could likely be made `const` in the future, nearly all of them require something to be dropped at compile-time, which isn't currently supported. The functions listed above should have a trivial path to stabilization.

3 years agoRollup merge of #77916 - QuiltOS:kernel-code-targets-os-none, r=joshtriplett
Yuki Okushi [Sun, 7 Mar 2021 01:41:04 +0000 (10:41 +0900)]
Rollup merge of #77916 - QuiltOS:kernel-code-targets-os-none, r=joshtriplett

Change built-in kernel targets to be os = none throughout

Whether for Rust's own `target_os`, LLVM's triples, or GNU config's, the
OS-related have fields have been for code running *on* that OS, not code
hat is *part* of the OS.

The difference is huge, as syscall interfaces are nothing like
freestanding interfaces. Kernels are (hypervisors and other more exotic
situations aside) freestanding programs that use the interfaces provided
by the hardware. It's *those* interfaces, the ones external to the
program being built and its software dependencies, that are the content
of the target.

For the Linux Kernel in particular, `target_env: "gnu"` is removed for
the same reason: that `-gnu` refers to glibc or GNU/linux, neither of
which applies to the kernel itself.

Relates to #74247

3 years agoAuto merge of #82738 - estebank:tail-expr-check-is-too-slow, r=oli-obk
bors [Sat, 6 Mar 2021 21:02:53 +0000 (21:02 +0000)]
Auto merge of #82738 - estebank:tail-expr-check-is-too-slow, r=oli-obk

Move check only relevant in error case out of critical path

Move the check for potentially forgotten `return` in a tail expression
of arbitrary expressions into the coercion error branch to avoid
computing unncessary coercion checks on successful code.

Follow up to #81458.

3 years agoMake some Option, Result methods unstably const
Jacob Pratt [Mon, 15 Feb 2021 03:11:46 +0000 (22:11 -0500)]
Make some Option, Result methods unstably const

The following functions are now unstably const:

- Option::transpose
- Option::flatten
- Result::transpose

3 years agoImprove transmute docs with further clarifications
Lonami [Sat, 27 Feb 2021 15:16:41 +0000 (16:16 +0100)]
Improve transmute docs with further clarifications

Closes #82493.

3 years agoaddress comments
Henry Boisdequin [Wed, 3 Mar 2021 11:39:40 +0000 (17:09 +0530)]
address comments

3 years agoAuto merge of #82816 - GuillaumeGomez:rollup-hxohu2e, r=GuillaumeGomez
bors [Fri, 5 Mar 2021 23:16:04 +0000 (23:16 +0000)]
Auto merge of #82816 - GuillaumeGomez:rollup-hxohu2e, r=GuillaumeGomez

Rollup of 7 pull requests

Successful merges:

 - #80845 (Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition over hir::ItemKind simpler)
 - #82708 (Warn on `#![doc(test(...))]` on items other than the crate root and use future incompatible lint)
 - #82714 (Detect match arm body without braces)
 - #82736 (Bump optimization from mir_opt_level 2 to 3 and 3 to 4 and make "release" be level 2 by default)
 - #82782 (Make rustc shim's verbose output include crate_name being compiled.)
 - #82797 (Update tests names to start with `issue-`)
 - #82809 (rustdoc: Use substrings instead of split to grab enum variant paths)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

3 years agoRollup merge of #82809 - notriddle:microoptimize-main-js, r=GuillaumeGomez
Guillaume Gomez [Fri, 5 Mar 2021 20:44:44 +0000 (21:44 +0100)]
Rollup merge of #82809 - notriddle:microoptimize-main-js, r=GuillaumeGomez

rustdoc: Use substrings instead of split to grab enum variant paths

Both versions are about equally readable, but this version avoids scanning the entire path and building an intermediate array (`split()` in Rust is a lazy iterator, but not in JavaScript).

3 years agoRollup merge of #82797 - henryboisdequin:name-issue-num, r=Xanewok
Guillaume Gomez [Fri, 5 Mar 2021 20:44:42 +0000 (21:44 +0100)]
Rollup merge of #82797 - henryboisdequin:name-issue-num, r=Xanewok

Update tests names to start with `issue-`

See ``@JohnTitor's`` [comment](https://github.com/rust-lang/rust/pull/82720#discussion_r586488083)

``@rustbot`` label +C-cleanup

3 years agoRollup merge of #82782 - pnkfelix:include-crate-being-compiled-in-bootstrap-verbose...
Guillaume Gomez [Fri, 5 Mar 2021 20:44:41 +0000 (21:44 +0100)]
Rollup merge of #82782 - pnkfelix:include-crate-being-compiled-in-bootstrap-verbose-output, r=Mark-Simulacrum

Make rustc shim's verbose output include crate_name being compiled.

This change is mainly motivated by an issue with the environment printing I added in PR 82403: multiple rustc invocations progress in parallel, and the environment output, spanning multiple lines, gets interleaved in ways make it difficult to extra the enviroment settings.

(This aforementioned difficulty is more of a hiccup than an outright show-stopper, because the environment variables tend to be the same for all of the rustc invocations, so it doesn't matter too much if one mixes up which lines one is looking at. But still: Better to fix it.)

3 years agoRollup merge of #82736 - spastorino:mir-opt-level-perf-changes, r=oli-obk
Guillaume Gomez [Fri, 5 Mar 2021 20:44:40 +0000 (21:44 +0100)]
Rollup merge of #82736 - spastorino:mir-opt-level-perf-changes, r=oli-obk

Bump optimization from mir_opt_level 2 to 3 and 3 to 4 and make "release" be level 2 by default

r? `@oli-obk`

3 years agoRollup merge of #82714 - estebank:missing-braces, r=oli-obk
Guillaume Gomez [Fri, 5 Mar 2021 20:44:39 +0000 (21:44 +0100)]
Rollup merge of #82714 - estebank:missing-braces, r=oli-obk

Detect match arm body without braces

Fix #82524.

3 years agoRollup merge of #82708 - GuillaumeGomez:doc-test-attr-check, r=Manishearth
Guillaume Gomez [Fri, 5 Mar 2021 20:44:38 +0000 (21:44 +0100)]
Rollup merge of #82708 - GuillaumeGomez:doc-test-attr-check, r=Manishearth

Warn on `#![doc(test(...))]` on items other than the crate root and use future incompatible lint

Part of #82672.

This PR does multiple things:
 * Create a new `INVALID_DOC_ATTRIBUTE` lint which is also "future incompatible", allowing us to use it as a warning for the moment until it turns (eventually) into a hard error.
 * Use this link when `#![doc(test(...))]` isn't used at the crate level.
 * Make #82702 use this new lint as well.

r? ``@jyn514``

3 years agoRollup merge of #80845 - GuillaumeGomez:item-kind-transition, r=jyn514
Guillaume Gomez [Fri, 5 Mar 2021 20:44:37 +0000 (21:44 +0100)]
Rollup merge of #80845 - GuillaumeGomez:item-kind-transition, r=jyn514

Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition over hir::ItemKind simpler

It was surprisingly difficult to make this change, mostly because of two issues:

* We now store the `ExternCrate` name in the parent struct (`clean::Item`), which forced me to modify the json conversion code a bit more than expected.
* The second problem was that, since we now have a `Some(name)`, it was trying to render it, ending up in a panic because we ended up in a `unreachable` statement. The solution was simply to add `!item.is_extern_crate()` in `formats::renderer` before calling `cx.item(item, &cache)?;`.

I'll continue to replace all the `clean::ItemKind` variants one by one until it looks exactly like `hir::ItemKind`. Then we'll simply discard the rustdoc type. Once this done, we'll be able to discard `clean::Item` too to use `hir::Item`.

r? ``@jyn514``

3 years agobless mir-inlining warning message
Santiago Pastorino [Fri, 5 Mar 2021 20:40:34 +0000 (17:40 -0300)]
bless mir-inlining warning message

3 years agoFix MIR optimization level description
Santiago Pastorino [Fri, 5 Mar 2021 00:11:28 +0000 (21:11 -0300)]
Fix MIR optimization level description

3 years agoBump one missing mir_opt_level
Santiago Pastorino [Thu, 4 Mar 2021 14:15:49 +0000 (11:15 -0300)]
Bump one missing mir_opt_level

3 years agoFix rustc_driver self text and bump the mir_opt_level
Santiago Pastorino [Thu, 4 Mar 2021 14:13:39 +0000 (11:13 -0300)]
Fix rustc_driver self text and bump the mir_opt_level

3 years agoBump mir-opt-level from 2 to 3 in tests
Santiago Pastorino [Thu, 4 Mar 2021 13:35:11 +0000 (10:35 -0300)]
Bump mir-opt-level from 2 to 3 in tests

3 years agoBump mir-opt-level from 3 to 4 in tests
Santiago Pastorino [Thu, 4 Mar 2021 13:21:13 +0000 (10:21 -0300)]
Bump mir-opt-level from 3 to 4 in tests

3 years agoMake clippy set mir_opt_level using Option
Santiago Pastorino [Thu, 4 Mar 2021 02:33:18 +0000 (23:33 -0300)]
Make clippy set mir_opt_level using Option

3 years agoMake mir_opt_level default to 2 for optimized levels
Santiago Pastorino [Wed, 3 Mar 2021 22:45:33 +0000 (19:45 -0300)]
Make mir_opt_level default to 2 for optimized levels

3 years agoBump all mir_opt_level 2 to 3
Santiago Pastorino [Wed, 3 Mar 2021 21:56:00 +0000 (18:56 -0300)]
Bump all mir_opt_level 2 to 3

3 years agoBump all mir_opt_level 3 to 4
Santiago Pastorino [Wed, 3 Mar 2021 21:30:42 +0000 (18:30 -0300)]
Bump all mir_opt_level 3 to 4

3 years agoFor better consistency change mir_opt_level <= 1 to < 2
Santiago Pastorino [Wed, 3 Mar 2021 22:41:04 +0000 (19:41 -0300)]
For better consistency change mir_opt_level <= 1 to < 2

3 years agoExtract mir_opt_level to a method and use Option to be able to know if the value...
Santiago Pastorino [Wed, 3 Mar 2021 21:19:15 +0000 (18:19 -0300)]
Extract mir_opt_level to a method and use Option to be able to know if the value is provided or not

3 years agoAuto merge of #74024 - Folyd:master, r=m-ou-se
bors [Fri, 5 Mar 2021 20:12:13 +0000 (20:12 +0000)]
Auto merge of #74024 - Folyd:master, r=m-ou-se

Improve slice.binary_search_by()'s best-case performance to O(1)

This PR aimed to improve the [slice.binary_search_by()](https://doc.rust-lang.org/std/primitive.slice.html#method.binary_search_by)'s best-case performance to O(1).

# Noticed

I don't know why the docs of `binary_search_by` said `"If there are multiple matches, then any one of the matches could be returned."`, but the implementation isn't the same thing. Actually, it returns the **last one** if multiple matches found.

Then we got two options:

## If returns the last one is the correct or desired result

Then I can rectify the docs and revert my changes.

## If the docs are correct or desired result

Then my changes can be merged after fully reviewed.

However, if my PR gets merged, another issue raised: this could be a **breaking change** since if multiple matches found, the returning order no longer the last one instead of it could be any one.

For example:
```rust
let mut s = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
let num = 1;
let idx = s.binary_search(&num);
s.insert(idx, 2);

// Old implementations
assert_eq!(s, [0, 1, 1, 1, 1, 2, 2, 3, 5, 8, 13, 21, 34, 42, 55]);

// New implementations
assert_eq!(s, [0, 1, 1, 1, 2, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]);
```

# Benchmarking

**Old implementations**
```sh
$ ./x.py bench --stage 1 library/libcore
test slice::binary_search_l1           ... bench:          59 ns/iter (+/- 4)
test slice::binary_search_l1_with_dups ... bench:          59 ns/iter (+/- 3)
test slice::binary_search_l2           ... bench:          76 ns/iter (+/- 5)
test slice::binary_search_l2_with_dups ... bench:          77 ns/iter (+/- 17)
test slice::binary_search_l3           ... bench:         183 ns/iter (+/- 23)
test slice::binary_search_l3_with_dups ... bench:         185 ns/iter (+/- 19)
```

**New implementations (1)**

Implemented by this PR.
```rust
if cmp == Equal {
    return Ok(mid);
} else if cmp == Less {
    base = mid
}
```
```sh
$ ./x.py bench --stage 1 library/libcore
test slice::binary_search_l1           ... bench:          58 ns/iter (+/- 2)
test slice::binary_search_l1_with_dups ... bench:          37 ns/iter (+/- 4)
test slice::binary_search_l2           ... bench:          76 ns/iter (+/- 3)
test slice::binary_search_l2_with_dups ... bench:          57 ns/iter (+/- 6)
test slice::binary_search_l3           ... bench:         200 ns/iter (+/- 30)
test slice::binary_search_l3_with_dups ... bench:         157 ns/iter (+/- 6)

$ ./x.py bench --stage 1 library/libcore
test slice::binary_search_l1           ... bench:          59 ns/iter (+/- 8)
test slice::binary_search_l1_with_dups ... bench:          37 ns/iter (+/- 2)
test slice::binary_search_l2           ... bench:          77 ns/iter (+/- 2)
test slice::binary_search_l2_with_dups ... bench:          57 ns/iter (+/- 2)
test slice::binary_search_l3           ... bench:         198 ns/iter (+/- 21)
test slice::binary_search_l3_with_dups ... bench:         158 ns/iter (+/- 11)

```

**New implementations (2)**

Suggested by `@nbdd0121` in [comment](https://github.com/rust-lang/rust/pull/74024#issuecomment-665430239).
```rust
base = if cmp == Greater { base } else { mid };
if cmp == Equal { break }
```

```sh
$ ./x.py bench --stage 1 library/libcore
test slice::binary_search_l1           ... bench:          59 ns/iter (+/- 7)
test slice::binary_search_l1_with_dups ... bench:          37 ns/iter (+/- 5)
test slice::binary_search_l2           ... bench:          75 ns/iter (+/- 3)
test slice::binary_search_l2_with_dups ... bench:          56 ns/iter (+/- 3)
test slice::binary_search_l3           ... bench:         195 ns/iter (+/- 15)
test slice::binary_search_l3_with_dups ... bench:         151 ns/iter (+/- 7)

$ ./x.py bench --stage 1 library/libcore
test slice::binary_search_l1           ... bench:          57 ns/iter (+/- 2)
test slice::binary_search_l1_with_dups ... bench:          38 ns/iter (+/- 2)
test slice::binary_search_l2           ... bench:          77 ns/iter (+/- 11)
test slice::binary_search_l2_with_dups ... bench:          57 ns/iter (+/- 4)
test slice::binary_search_l3           ... bench:         194 ns/iter (+/- 15)
test slice::binary_search_l3_with_dups ... bench:         151 ns/iter (+/- 18)

```

I run some benchmarking testings against on two implementations. The new implementation has a lot of improvement in duplicates cases, while in `binary_search_l3` case, it's a little bit slower than the old one.

3 years agoUse substrings instead of split to grab enum variant paths
Michael Howell [Fri, 5 Mar 2021 18:20:31 +0000 (11:20 -0700)]
Use substrings instead of split to grab enum variant paths

Both versions are about equally readable, but this version avoids scanning
the entire path and building an intermediate array (`split()` in Rust is
a lazy iterator, but not in JavaScript).

3 years agoAdd relevant test
Giacomo Stevanato [Fri, 19 Feb 2021 14:25:09 +0000 (15:25 +0100)]
Add relevant test

3 years agoPrevent Zip specialization from calling __iterator_get_unchecked twice with the same...
Giacomo Stevanato [Wed, 3 Mar 2021 20:09:01 +0000 (21:09 +0100)]
Prevent Zip specialization from calling __iterator_get_unchecked twice with the same index after calling next_back

3 years agoRevise prefix a bit, adding both `--test` (conditionally) and `[RUSTC-SHIM]` uncondit...
Felix S. Klock II [Fri, 5 Mar 2021 16:46:04 +0000 (11:46 -0500)]
Revise prefix a bit, adding both `--test` (conditionally) and `[RUSTC-SHIM]` unconditionally.

1. I added `--test` based on review feedback from simulacrum: I decided I would
rather include such extra context than get confused later on by its absence.
(However, I chose to encode it differently than how `[RUSTC-TIMING]` does... I
don't have much basis for doing so, other than `--test` to me more directly
reflects what it came from.)

2. I also decided to include `[RUSTC-SHIM]` at start of all of these lines
driven by the verbosity level, to make to clear where these lines of text
originate from. (Basically, I skimmed over the output and realized that a casual
observer might not be able to tell where this huge set of new lines were coming
from.)

3 years agoRefactor from_clean_item_kind to improve ExternCrateItem handling
Guillaume Gomez [Fri, 5 Mar 2021 15:05:07 +0000 (16:05 +0100)]
Refactor from_clean_item_kind to improve ExternCrateItem handling

3 years agoMake ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition...
Guillaume Gomez [Fri, 5 Mar 2021 15:04:24 +0000 (16:04 +0100)]
Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition over hir::ItemKind simpler

3 years agoMake invalid_doc_attribute lint plural
Guillaume Gomez [Fri, 5 Mar 2021 13:44:31 +0000 (14:44 +0100)]
Make invalid_doc_attribute lint plural

3 years agoAuto merge of #82795 - m-ou-se:rollup-uzx0b92, r=m-ou-se
bors [Fri, 5 Mar 2021 13:34:33 +0000 (13:34 +0000)]
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

3 years agoUpdate tests names to start with `issue-`
Henry Boisdequin [Fri, 5 Mar 2021 11:28:11 +0000 (16:58 +0530)]
Update tests names to start with `issue-`

See @JohnTitor's [comment](https://github.com/rust-lang/rust/pull/82720#discussion_r586488083)

@rustbot label +C-cleanup

3 years agoRollup merge of #82787 - notriddle:main-js-cleanup, r=GuillaumeGomez
Mara [Fri, 5 Mar 2021 09:57:25 +0000 (10:57 +0100)]
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 768d5e950953738a54480e530341964838d29da2

3 years agoRollup merge of #82773 - mgacek8:feature/add_diagnostic_item_to_Default_trait, r...
Mara [Fri, 5 Mar 2021 09:57:24 +0000 (10:57 +0100)]
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.

3 years agoRollup merge of #82770 - m-ou-se:assert-match, r=joshtriplett
Mara [Fri, 5 Mar 2021 09:57:23 +0000 (10:57 +0100)]
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```

3 years agoRollup merge of #82764 - m-ou-se:map-try-insert, r=Amanieu
Mara [Fri, 5 Mar 2021 09:57:22 +0000 (10:57 +0100)]
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

3 years agoRollup merge of #82728 - calebsander:refactor/bufreader-buf, r=m-ou-se
Mara [Fri, 5 Mar 2021 09:57:20 +0000 (10:57 +0100)]
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``

3 years agoRollup merge of #82289 - SkiFire13:fix-issue-82282, r=m-ou-se
Mara [Fri, 5 Mar 2021 09:57:19 +0000 (10:57 +0100)]
Rollup merge of #82289 - SkiFire13:fix-issue-82282, r=m-ou-se

Fix underflow in specialized ZipImpl::size_hint

Fixes #82282

3 years agoRollup merge of #81939 - kper:fixing-81584-allocate-in-iter, r=davidtwco
Mara [Fri, 5 Mar 2021 09:57:18 +0000 (10:57 +0100)]
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`

3 years agoRollup merge of #81136 - Xavientois:io_reader_size_hint, r=cramertj
Mara [Fri, 5 Mar 2021 09:57:17 +0000 (10:57 +0100)]
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

3 years agoRollup merge of #80763 - petrochenkov:pubusecrate, r=estebank
Mara [Fri, 5 Mar 2021 09:57:15 +0000 (10:57 +0100)]
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.

3 years agoRollup merge of #80723 - rylev:noop-lint-pass, r=estebank
Mara [Fri, 5 Mar 2021 09:57:14 +0000 (10:57 +0100)]
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 ❤️.

3 years agoAuto merge of #82777 - GuillaumeGomez:rollup-etcsupl, r=GuillaumeGomez
bors [Fri, 5 Mar 2021 09:28:07 +0000 (09:28 +0000)]
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

3 years agoAuto merge of #71481 - estebank:inherit-stability, r=nikomatsakis
bors [Fri, 5 Mar 2021 05:28:07 +0000 (05:28 +0000)]
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.

3 years agoRemove unused code from main.js
Michael Howell [Fri, 5 Mar 2021 00:06:06 +0000 (17:06 -0700)]
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 768d5e950953738a54480e530341964838d29da2

3 years agoMake rustc shim's verbose output include crate_name being compiled.
Felix S. Klock II [Thu, 4 Mar 2021 22:19:41 +0000 (17:19 -0500)]
Make rustc shim's verbose output include crate_name being compiled.

This change is mainly motivated by an issue with the environment
printing I added in PR 82403: multiple rustc invocations progress
in parallel, and the environment output, spanning multiple lines,
gets interleaved in ways make it difficult to extra the enviroment settings.

(This aforementioned difficulty is more of a hiccup than an outright
show-stopper, because the environment variables tend to be the same for all of
the rustc invocations, so it doesn't matter too much if one mixes up which lines
one is looking at. But still: Better to fix it.)

3 years agoRollup merge of #82765 - oli-obk:polymorphization_regression, r=davidtwco
Guillaume Gomez [Thu, 4 Mar 2021 20:56:35 +0000 (21:56 +0100)]
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

3 years agoRollup merge of #82752 - JohnTitor:gat-ice-test, r=jackh726
Guillaume Gomez [Thu, 4 Mar 2021 20:56:34 +0000 (21:56 +0100)]
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`

3 years agoRollup merge of #82690 - jyn514:remove-pass-docs, r=Manishearth
Guillaume Gomez [Thu, 4 Mar 2021 20:56:33 +0000 (21:56 +0100)]
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`

3 years agoRollup merge of #82088 - Nicholas-Baron:shorten_html_render, r=GuillaumeGomez
Guillaume Gomez [Thu, 4 Mar 2021 20:56:27 +0000 (21:56 +0100)]
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.

3 years agoRollup merge of #76716 - GuillaumeGomez:stop-complains-on-doc-hidden, r=jyn514
Guillaume Gomez [Thu, 4 Mar 2021 20:56:27 +0000 (21:56 +0100)]
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`

3 years agoAlso use INVALID_DOC_ATTRIBUTE for "unknown doc attribute" warnings
Guillaume Gomez [Thu, 4 Mar 2021 20:48:07 +0000 (21:48 +0100)]
Also use INVALID_DOC_ATTRIBUTE for "unknown doc attribute" warnings

3 years agoAdd tracking issue for assert_matches.
Mara Bos [Thu, 4 Mar 2021 20:33:31 +0000 (21:33 +0100)]
Add tracking issue for assert_matches.

3 years agoAdd tests for #[doc(test(...)] check
Guillaume Gomez [Tue, 2 Mar 2021 20:10:30 +0000 (21:10 +0100)]
Add tests for #[doc(test(...)] check

3 years agoAdd extra check for #[doc(test(...)] attribute
Guillaume Gomez [Tue, 2 Mar 2021 20:10:05 +0000 (21:10 +0100)]
Add extra check for #[doc(test(...)] attribute

3 years agoAdd new edition 2021 link: INVALID_DOC_ATTRIBUTE
Guillaume Gomez [Wed, 3 Mar 2021 22:00:17 +0000 (23:00 +0100)]
Add new edition 2021 link: INVALID_DOC_ATTRIBUTE

3 years agoUse cache access levels
Guillaume Gomez [Tue, 2 Mar 2021 10:59:37 +0000 (11:59 +0100)]
Use cache access levels

3 years agoNo more need for borrow call
Guillaume Gomez [Tue, 23 Feb 2021 20:53:28 +0000 (21:53 +0100)]
No more need for borrow call

3 years agoPass TyCtxt directly instead of DocContext in librustdoc::visit_ast::inherits_doc_hidden
Guillaume Gomez [Tue, 23 Feb 2021 14:19:13 +0000 (15:19 +0100)]
Pass TyCtxt directly instead of DocContext in librustdoc::visit_ast::inherits_doc_hidden

3 years agoMove visibility check inside the should_have_doc_example function
Guillaume Gomez [Mon, 15 Feb 2021 13:17:43 +0000 (14:17 +0100)]
Move visibility check inside the should_have_doc_example function

3 years agoUpdate missing code example test
Guillaume Gomez [Sat, 13 Feb 2021 20:45:15 +0000 (21:45 +0100)]
Update missing code example test

3 years agoDon't warn for `missing_doc_examples` when item is #[doc(hidden)]
Guillaume Gomez [Sat, 13 Feb 2021 20:44:42 +0000 (21:44 +0100)]
Don't warn for `missing_doc_examples` when item is #[doc(hidden)]

3 years agoAuto merge of #82747 - JohnTitor:pin-es-check-version, r=Mark-Simulacrum
bors [Thu, 4 Mar 2021 19:24:21 +0000 (19:24 +0000)]
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.

3 years agoUpdate rustdoc documentation
Joshua Nelson [Tue, 2 Mar 2021 01:07:56 +0000 (20:07 -0500)]
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.

3 years agoDon't consume the expression in assert_matches!()'s failure case.
Mara Bos [Thu, 4 Mar 2021 18:36:36 +0000 (19:36 +0100)]
Don't consume the expression in assert_matches!()'s failure case.

3 years agoCorrected imports for render tests and mod files
Nicholas-Baron [Sun, 14 Feb 2021 22:11:55 +0000 (14:11 -0800)]
Corrected imports for render tests and mod files

Due to a rebase, some edits were needed in the mod file.

3 years agoMoved `write_shared` to its own file
Nicholas-Baron [Sun, 14 Feb 2021 07:17:38 +0000 (23:17 -0800)]
Moved `write_shared` to its own file

3 years agoFix comment with path to `symbols!` macro
Mateusz Gacek [Thu, 4 Mar 2021 18:13:53 +0000 (10:13 -0800)]
Fix comment with path to `symbols!` macro

3 years agoAdd diagnostic item to `Default` trait
Mateusz Gacek [Thu, 4 Mar 2021 18:09:02 +0000 (10:09 -0800)]
Add diagnostic item to `Default` trait

Required to resolve #6562 rust-clippy issue.

3 years agoMoved the `make_item_keywords` function to `context.rs` as it is only used there
Nicholas-Baron [Sun, 14 Feb 2021 07:03:07 +0000 (23:03 -0800)]
Moved the `make_item_keywords` function to `context.rs` as it is only used there

3 years agoMoved `print_item` and helpers to a separate file
Nicholas-Baron [Sun, 14 Feb 2021 06:23:05 +0000 (22:23 -0800)]
Moved `print_item` and helpers to a separate file

3 years agoMoved Context and its impls to a separate file
Nicholas-Baron [Sun, 14 Feb 2021 05:28:34 +0000 (21:28 -0800)]
Moved Context and its impls to a separate file

3 years agoFix assert_matches doc examples.
Mara Bos [Thu, 4 Mar 2021 17:41:43 +0000 (18:41 +0100)]
Fix assert_matches doc examples.

3 years agoAdd debug_assert_matches macro.
Mara Bos [Thu, 4 Mar 2021 17:12:33 +0000 (18:12 +0100)]
Add debug_assert_matches macro.

3 years agoAllow for multiple patterns and a guard in assert_matches.
Mara Bos [Thu, 4 Mar 2021 17:07:26 +0000 (18:07 +0100)]
Allow for multiple patterns and a guard in assert_matches.

3 years agoAdd assert_matches!(expr, pat).
Mara Bos [Thu, 4 Mar 2021 16:55:23 +0000 (17:55 +0100)]
Add assert_matches!(expr, pat).

3 years agoRemove RefCell around module_trait_cache
Joshua Nelson [Mon, 22 Feb 2021 14:21:47 +0000 (09:21 -0500)]
Remove RefCell around module_trait_cache

3 years agoDon't require a `DocContext` for `report_diagnostic`
Joshua Nelson [Mon, 22 Feb 2021 14:31:41 +0000 (09:31 -0500)]
Don't require a `DocContext` for `report_diagnostic`

This is needed for the next commit, which needs access to the `cx` from
within the `decorate` closure.

- Change `as_local_hir_id` to an associated function, since it only
  needs a `TyCtxt`
- Change `source_span_for_markdown_range` to only take a `TyCtxt`

3 years agoAdd tracking issue for map_try_insert.
Mara Bos [Thu, 4 Mar 2021 15:54:28 +0000 (16:54 +0100)]
Add tracking issue for map_try_insert.

3 years agoRemove unnecessary bound from HashMap::try_insert.
Mara Bos [Thu, 4 Mar 2021 15:46:41 +0000 (16:46 +0100)]
Remove unnecessary bound from HashMap::try_insert.

3 years agoFixes -Zpolymorphize for src/test/ui/const-generics/auxiliary/crayte.rs
Oli Scherer [Thu, 4 Mar 2021 15:44:20 +0000 (15:44 +0000)]
Fixes -Zpolymorphize for src/test/ui/const-generics/auxiliary/crayte.rs

3 years agoTypo
Oli Scherer [Thu, 4 Mar 2021 14:48:17 +0000 (14:48 +0000)]
Typo

3 years agoSpread tracing instrumentation into the polymorphization logic
Oli Scherer [Thu, 4 Mar 2021 12:59:18 +0000 (12:59 +0000)]
Spread tracing instrumentation into the polymorphization logic

3 years agoIgnore file length tidy warning in hash/map.rs.
Mara Bos [Thu, 4 Mar 2021 15:25:24 +0000 (16:25 +0100)]
Ignore file length tidy warning in hash/map.rs.

3 years agoAuto merge of #81451 - nikic:llvm-12, r=nagisa
bors [Thu, 4 Mar 2021 15:16:44 +0000 (15:16 +0000)]
Auto merge of #81451 - nikic:llvm-12, r=nagisa

Upgrade to LLVM 12

This implements the necessary adjustments to make rustc work with LLVM 12. I didn't encounter any major issues so far.

r? `@cuviper`

3 years agoImplement Error for OccupiedError.
Mara Bos [Thu, 4 Mar 2021 14:57:26 +0000 (15:57 +0100)]
Implement Error for OccupiedError.

3 years agoImprove Debug implementations of OccupiedError.
Mara Bos [Thu, 4 Mar 2021 14:56:38 +0000 (15:56 +0100)]
Improve Debug implementations of OccupiedError.

3 years agoAdd HashMap::try_insert and hash_map::OccupiedError.
Mara Bos [Thu, 4 Mar 2021 14:34:47 +0000 (15:34 +0100)]
Add HashMap::try_insert and hash_map::OccupiedError.

3 years agoAdd BTreeMap::try_insert and btree_map::OccupiedError.
Mara Bos [Thu, 4 Mar 2021 14:34:47 +0000 (15:34 +0100)]
Add BTreeMap::try_insert and btree_map::OccupiedError.

3 years agoRemove a dead code path
Oli Scherer [Thu, 4 Mar 2021 12:21:36 +0000 (12:21 +0000)]
Remove a dead code path