bors [Fri, 19 Feb 2021 16:39:03 +0000 (16:39 +0000)]
Auto merge of #82020 - jyn514:mut-passes, r=camelid,GuillaumeGomez
Make `Clean` take &mut DocContext
- Take `FnMut` in `rustc_trait_selection::find_auto_trait_generics`
- Take `&mut DocContext` in most of `clean`
- Collect the iterator in auto_trait_impls instead of iterating lazily; the lifetimes were really bad.
This combined with https://github.com/rust-lang/rust/pull/82018 should hopefully help with https://github.com/rust-lang/rust/pull/82014 by allowing `cx.cache.exported_traits` to be modified in `register_res`. Previously it had to use interior mutability, which required either adding a RefCell to `cache.exported_traits` on *top* of the existing `RefCell<Cache>` or mixing reads and writes between `cx.exported_traits` and `cx.cache.exported_traits`. I don't currently have that working but I expect it to be reasonably easy to add after this.
bors [Fri, 19 Feb 2021 08:24:01 +0000 (08:24 +0000)]
Auto merge of #82281 - Dylan-DPC:rollup-raob2tu, r=Dylan-DPC
Rollup of 10 pull requests
Successful merges:
- #79747 (Add explanations and suggestions to `irrefutable_let_patterns` lint)
- #81496 (name async generators something more human friendly in type error diagnostic)
- #81873 (Add Mutex::unlock)
- #82093 (Add tests for Atomic*::fetch_{min,max})
- #82238 (ast: Keep expansion status for out-of-line module items)
- #82245 (Do not ICE when evaluating locals' types of invalid `yield`)
- #82259 (Fix popping singleton paths in when generating E0433)
- #82261 (rustdoc: Support argument files)
- #82274 (libtest: Fix unwrap panic on duplicate TestDesc)
- #82275 (Update cargo)
Dylan DPC [Fri, 19 Feb 2021 01:49:13 +0000 (02:49 +0100)]
Rollup merge of #82274 - andersk:test-unwrap, r=Mark-Simulacrum
libtest: Fix unwrap panic on duplicate TestDesc
It is possible for different tests to collide to the same `TestDesc` when macros are involved. That is a bug, but it didn’t cause a panic until #81367. For now, change the code to ignore this problem.
Dylan DPC [Fri, 19 Feb 2021 01:49:12 +0000 (02:49 +0100)]
Rollup merge of #82261 - ojeda:rustdoc-argfile, r=jyn514
rustdoc: Support argument files
Factors out the `rustc_driver` logic that handles argument files so that rustdoc supports them as well, e.g.:
rustdoc `@argfile`
This is needed to be able to generate docs for projects that already use argument files when compiling them, e.g. projects that pass a huge number of `--cfg` arguments.
Dylan DPC [Fri, 19 Feb 2021 01:49:08 +0000 (02:49 +0100)]
Rollup merge of #82238 - petrochenkov:nocratemod, r=Aaron1011
ast: Keep expansion status for out-of-line module items
I.e. whether a module `mod foo;` is already loaded from a file or not.
This is a pre-requisite to correctly treating inner attributes on such modules (https://github.com/rust-lang/rust/issues/81661).
With this change AST structures for `mod` items diverge even more for AST structure for the crate root, which previously used `ast::Mod`.
Therefore this PR removes `ast::Mod` from `ast::Crate` in the first commit, these two things are sufficiently different from each other, at least at syntactic level.
Customization points for visiting a "`mod` item or crate root" were also removed from AST visitors (`fn visit_mod`).
`ast::Mod` itself was refactored away in the second commit in favor of `ItemKind::Mod(Unsafe, ModKind)`.
Dylan DPC [Fri, 19 Feb 2021 01:49:07 +0000 (02:49 +0100)]
Rollup merge of #82093 - bjorn3:more_atomic_tests, r=kennytm
Add tests for Atomic*::fetch_{min,max}
This ensures that all atomic operations except for fences are tested. This has been useful to test my work on using atomic instructions for atomic operations in cg_clif instead of a global lock.
Dylan DPC [Fri, 19 Feb 2021 01:49:00 +0000 (02:49 +0100)]
Rollup merge of #81496 - guswynn:expected_async_block, r=oli-obk
name async generators something more human friendly in type error diagnostic
fixes #81457
Some details:
1. I opted to load the generator kind from the hir in TyCategory. I also use 1 impl in the hir for the descr
2. I named both the source of the future, in addition to the general type (`future`), not sure what is preferred
3. I am not sure what is required to make sure "generator" is not referred to anywhere. A brief `rg "\"generator\"" showed me that most diagnostics correctly distinguish from generators and async generator, but the `descr` of `DefKind` is pretty general (not sure how thats used)
4. should the descr impl of AsyncGeneratorKind use its display impl instead of copying the string?
Miguel Ojeda [Thu, 18 Feb 2021 15:15:24 +0000 (16:15 +0100)]
rustdoc: Support argument files
Factors out the `rustc_driver` logic that handles argument files
so that rustdoc supports them as well, e.g.:
rustdoc @argfile
This is needed to be able to generate docs for projects that
already use argument files when compiling them, e.g. projects
that pass a huge number of `--cfg` arguments.
Anders Kaseorg [Thu, 18 Feb 2021 20:41:08 +0000 (12:41 -0800)]
libtest: Fix unwrap panic on duplicate TestDesc.
It is possible for different tests to collide to the same TestDesc
when macros are involved. That is a bug, but it didn’t cause a panic
until #81367. For now, change the code to ignore this problem.
bors [Thu, 18 Feb 2021 19:45:42 +0000 (19:45 +0000)]
Auto merge of #82263 - Dylan-DPC:rollup-cypm2uw, r=Dylan-DPC
Rollup of 10 pull requests
Successful merges:
- #81546 ([libtest] Run the test synchronously when hitting thread limit)
- #82066 (Ensure valid TraitRefs are created for GATs)
- #82112 (const_generics: Dont evaluate array length const when handling yet another error )
- #82194 (In some limited cases, suggest `where` bounds for non-type params)
- #82215 (Replace if-let and while-let with `if let` and `while let`)
- #82218 (Make sure pdbs are copied along with exe and dlls when bootstrapping)
- #82236 (avoid converting types into themselves (clippy::useless_conversion))
- #82246 (Add long explanation for E0549)
- #82248 (Optimize counting digits in line numbers during error reporting)
- #82256 (Print -Ztime-passes (and misc stats/logs) on stderr, not stdout.)
Dylan DPC [Thu, 18 Feb 2021 15:57:43 +0000 (16:57 +0100)]
Rollup merge of #82256 - eddyb:time-passes-stderr, r=varkor
Print -Ztime-passes (and misc stats/logs) on stderr, not stdout.
I've tried not to change anything that looked similar to `rustc --print`, where people might use automation, and/or any "bulk" prints, such as dumping an entire Graphviz (`dot`) graph on stdout.
The reason I want `-Ztime-passes` to be on stderr like debug logging is I can get a complete (and correctly interleaved) view just by looking at stderr, which is merely a convenience when running `rustc`/Cargo directly, but even more important when it's nested in a build script, as Cargo will split the build script output into stdout (named `output`) and `stderr`.
Dylan DPC [Thu, 18 Feb 2021 15:57:42 +0000 (16:57 +0100)]
Rollup merge of #82248 - nhwn:optimize-counting-digits, r=varkor
Optimize counting digits in line numbers during error reporting
Replaces `.to_string().len()` with simple loop and integer division, which avoids an unnecessary allocation.
Although I couldn't figure out how to directly profile `rustc`'s error reporting, I ran a microbenchmark on my machine (2.9 GHz Dual-Core Intel Core i5) on the two strategies for `0..100_000`, and the results seem promising:
```
test to_string_len ... bench: 12,124,792 ns/iter (+/- 700,652)
test while_loop ... bench: 30,333 ns/iter (+/- 562)
```
The x86_64 disassembly reduces integer division to a multiplication + shift, so I don't think there's any problems with using integer division.
For more (micro)optimization, it would be nice if we could avoid the initial check to see if the line number is nonzero, but I don't think `self.get_max_line_num(span, children)` _guarantees_ a nonzero line number.
Dylan DPC [Thu, 18 Feb 2021 15:57:33 +0000 (16:57 +0100)]
Rollup merge of #81546 - hyd-dev:libtest-run-out-of-threads, r=Mark-Simulacrum
[libtest] Run the test synchronously when hitting thread limit
libtest currently panics if it hits the thread limit. This often results in spurious test failures (<code>thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" }'</code> ... `error: test failed, to rerun pass '--lib'`). This PR makes it continue to run the test synchronously if it runs out of threads.
bors [Thu, 18 Feb 2021 10:13:36 +0000 (10:13 +0000)]
Auto merge of #81574 - tmiasko:p, r=oli-obk
Precompute ancestors when checking privacy
Precompute ancestors of the old error node set so that check for private
types and traits in public interfaces can in constant time determine if
the current item has any descendants in the old error set.
This removes disparity in compilation time between public and private type
aliases reported in #50614 (from 30 s to 5 s, in an example making extensive use
of private type aliases).
Yuki Okushi [Thu, 18 Feb 2021 06:57:27 +0000 (15:57 +0900)]
Rollup merge of #82155 - tmiasko:once, r=matthewjasper
Use !Sync std::lazy::OnceCell in usefulness checking
The `rustc_data_structures::sync::OnceCell` is thread-safe when building
a parallel compiler. This is unnecessary for the purposes of pattern
usefulness checking. Use `!Sync` `std::lazy::OnceCell` instead.
bors [Thu, 18 Feb 2021 04:22:16 +0000 (04:22 +0000)]
Auto merge of #81172 - SimonSapin:ptr-metadata, r=oli-obk
Implement RFC 2580: Pointer metadata & VTable
RFC: https://github.com/rust-lang/rfcs/pull/2580
~~Before merging this PR:~~
* [x] Wait for the end of the RFC’s [FCP to merge](https://github.com/rust-lang/rfcs/pull/2580#issuecomment-759145278).
* [x] Open a tracking issue: https://github.com/rust-lang/rust/issues/81513
* [x] Update `#[unstable]` attributes in the PR with the tracking issue number
----
This PR extends the language with a new lang item for the `Pointee` trait which is special-cased in trait resolution to implement it for all types. Even in generic contexts, parameters can be assumed to implement it without a corresponding bound.
For this I mostly imitated what the compiler was already doing for the `DiscriminantKind` trait. I’m very unfamiliar with compiler internals, so careful review is appreciated.
This PR also extends the standard library with new unstable APIs in `core::ptr` and `std::ptr`:
```rust
pub trait Pointee {
/// One of `()`, `usize`, or `DynMetadata<dyn SomeTrait>`
type Metadata: Copy + Send + Sync + Ord + Hash + Unpin;
}
unsafe impl<Dyn: ?Sized> Send for DynMetadata<Dyn> {}
unsafe impl<Dyn: ?Sized> Sync for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Debug for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Unpin for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Copy for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Clone for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Eq for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> PartialEq for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Ord for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> PartialOrd for DynMetadata<Dyn> {}
impl<Dyn: ?Sized> Hash for DynMetadata<Dyn> {}
```
API differences from the RFC, in areas noted as unresolved questions in the RFC:
* Module-level functions instead of associated `from_raw_parts` functions on `*const T` and `*mut T`, following the precedent of `null`, `slice_from_raw_parts`, etc.
* Added `to_raw_parts`
bors [Thu, 18 Feb 2021 01:31:10 +0000 (01:31 +0000)]
Auto merge of #82241 - Dylan-DPC:rollup-munmzg5, r=Dylan-DPC
Rollup of 8 pull requests
Successful merges:
- #77728 (Expose force_quotes on Windows.)
- #80572 (Add a `Result::into_ok_or_err` method to extract a `T` from `Result<T, T>`)
- #81860 (Fix SourceMap::start_point)
- #81869 (Simplify pattern grammar, improve or-pattern diagnostics)
- #81898 (Fix debug information for function arguments of type &str or slice.)
- #81972 (Placeholder lifetime error cleanup)
- #82007 (Implement reborrow for closure captures)
- #82021 (Spell out nested Self type in lint message)
Dylan DPC [Wed, 17 Feb 2021 22:51:19 +0000 (23:51 +0100)]
Rollup merge of #82007 - sexxi-goose:reborrow, r=nikomatsakis
Implement reborrow for closure captures
The strategy for captures is detailed here with examples: https://hackmd.io/PzxYMPY4RF-B9iH9uj9GTA
Key points:
- We only need to reborrow a capture in case of move closures.
- If we mutate something via a `&mut` we store it as a `MutBorrow`/`UniqueMuBorrow` of the path containing the `&mut`,
- Similarly, if it's read via `&` ref we just store it as a `ImmBorrow` of the path containing the `&` ref.
- If a path doesn't deref a `&mut`, `&`, then that path is captured by Move.
- If the use of a path results in a move when the closure is called, then that path is truncated before any deref and the truncated path is moved into the closure.
- In the case of non-move closure if a use of a path results in a move, then the path is truncated before any deref and the truncated path is moved into the closure.
Note that the implementation differs a bit from the document to allow for truncated path to be used in the ClosureKind analysis that happens as part of the first capture analysis pass.
Dylan DPC [Wed, 17 Feb 2021 22:51:18 +0000 (23:51 +0100)]
Rollup merge of #81972 - matthewjasper:hrtb-error-cleanup, r=nikomatsakis
Placeholder lifetime error cleanup
- Remove note of trait definition
- Avoid repeating the same self type
- Use original region names when possible
- Use this error kind more often
- Print closure signatures when they are suppose to implement `Fn*` traits
Dylan DPC [Wed, 17 Feb 2021 22:51:17 +0000 (23:51 +0100)]
Rollup merge of #81898 - nanguye2496:nanguye2496/fix_str_and_slice_visualization, r=varkor
Fix debug information for function arguments of type &str or slice.
Issue details:
When lowering MIR to LLVM IR, the compiler decomposes every &str and slice argument into a data pointer and a usize. Then, the original argument is reconstructed from the pointer and the usize arguments in the body of the function that owns it. Since the original argument is declared in the body of a function, it should be marked as a LocalVariable instead of an ArgumentVairable. This confusion causes MSVC debuggers unable to visualize &str and slice arguments correctly. (See https://github.com/rust-lang/rust/issues/81894 for more details).
Fix details:
Making sure that the debug variable for every &str and slice argument is marked as LocalVariable instead of ArgumentVariable in computing_per_local_var_debug_info. This change has been verified on VS Code debugger, VS debugger, WinDbg and LLDB.
This implements the change under FCP in https://github.com/rust-lang/rust/issues/81415. It allows nested or-patterns to contain a leading `|`, simplifying the [grammar for patterns](https://github.com/rust-lang/reference/pull/957/files?short_path=cc629f1#diff-cc629f15712821139bc706c63b3845ab59a008e2a998e08ffad42e3aebcbcbe2).
Along the way, we also improve the diagnostics around a few specially-handled cases, such as using `||` instead of `|`, using or-patterns in fn params, including the leading `|` in the pattern span, etc.
Dylan DPC [Wed, 17 Feb 2021 22:51:14 +0000 (23:51 +0100)]
Rollup merge of #81860 - osa1:issue81800, r=estebank
Fix SourceMap::start_point
`start_point` needs to return the *first* character's span, but it would
previously call `find_width_of_character_at_span` which returns the span
of the *last* character. The implementation is now fixed.
Other changes:
- Docs for start_point, end_point, find_width_of_character_at_span
updated
- Minor simplification in find_width_of_character_at_span code
Dylan DPC [Wed, 17 Feb 2021 22:51:13 +0000 (23:51 +0100)]
Rollup merge of #80572 - thomcc:ok_or_err, r=m-ou-se
Add a `Result::into_ok_or_err` method to extract a `T` from `Result<T, T>`
When updating code to handle the semi-recent deprecation of `compare_and_swap` in favor of `compare_exchange`, which returns `Result<T, T>`, I wanted this. I've also wanted it with code using `slice::binary_search` before.
The name (and perhaps the documentation) is the hardest part here, but this name seems consistent with the other Result methods, and equivalently memorable.
Dylan DPC [Wed, 17 Feb 2021 22:51:12 +0000 (23:51 +0100)]
Rollup merge of #77728 - lygstate:master, r=Amanieu
Expose force_quotes on Windows.
On Windows, the arg quotes and not quotes have different effect
for the program it called, if the program called are msys2/cygwin program.
Refer to
https://github.com/msys2/MSYS2-packages/issues/2176
bors [Wed, 17 Feb 2021 19:39:58 +0000 (19:39 +0000)]
Auto merge of #82235 - GuillaumeGomez:rollup-oflxc08, r=GuillaumeGomez
Rollup of 11 pull requests
Successful merges:
- #79981 (Add 'consider using' message to overflowing_literals)
- #82094 (To digit simplification)
- #82105 (Don't fail to remove files if they are missing)
- #82136 (Fix ICE: Use delay_span_bug for mismatched subst/hir arg)
- #82169 (Document that `assert!` format arguments are evaluated lazily)
- #82174 (Replace File::create and write_all with fs::write)
- #82196 (Add caveat to Path::display() about lossiness)
- #82198 (Use internal iteration in Iterator::is_sorted_by)
- #82204 (Update books)
- #82207 (rustdoc: treat edition 2021 as unstable)
- #82231 (Add long explanation for E0543)
9 commits in f02b09eb6e8af340ad1256a54adb7aae2ff3163e..361367c126290ac17cb4089f8d38fd8b2ac43f98
2021-01-22 01:53:02 -0800 to 2021-02-15 09:58:13 -0800
- Define turbofish in the glossary (rust-lang-nursery/reference#964)
- Remove enum variant expr (rust-lang-nursery/reference#963)
- One sentence is one line src/expressions/* (rust-lang-nursery/reference#962)
- Referencify bool type (rust-lang-nursery/reference#940)
- Fix typo in type cast expression table (rust-lang-nursery/reference#959)
- Define rust (rust-lang-nursery/reference#953)
- Remove "Memory Ownership" chapter (rust-lang-nursery/reference#952)
- Added setting nightly as a requirement for running tests (rust-lang-nursery/reference#955)
- Refactored build steps for better readability (rust-lang-nursery/reference#936)
## book
13 commits in e724bd826580ff95df48a8533af7dec1080693d4..db5e8a5105aa22979490dce30e33b68d8645761d
2021-01-20 08:19:49 -0600 to 2021-02-12 16:58:20 -0500
- Update to Rust 1.50
- Fix issue rust-lang/book#2574 - Improve the explanation about the behaviour of `read_line`. (rust-lang/book#2575)
- closures: replace "is called" with "is defined" (rust-lang/book#2556)
- Minor clarification: types -> values in ch16-04 (rust-lang/book#2587)
- fixed hidden code listing (rust-lang/book#2610)
- Merge remote-tracking branch 'origin/pr/2604'
- (rust-lang/book#2601)
- Merge remote-tracking branch 'origin/pr/2589'
- Fix text wrapping
- Some small rewordings I noticed while rereading just now
- (rust-lang/book#2592)
- Removed 'of' between type alias in Ch 19-04. (rust-lang/book#2581)
- Merge remote-tracking branch 'origin/pr/2554'
3 commits in b91a9a881ee007c12e74e844460ec407cf07a50f..1da3c411f17adb1ba5de1683bb6acee83362b54a
2020-11-02 11:02:03 -0600 to 2021-02-16 16:46:40 -0800
- Update link for no_std. (rust-lang-nursery/edition-guide#231)
- Add git link to the source. (rust-lang-nursery/edition-guide#228)
- Update musl libc link (rust-lang-nursery/edition-guide#230)
Guillaume Gomez [Wed, 17 Feb 2021 19:38:00 +0000 (20:38 +0100)]
Rollup merge of #82169 - not-an-aardvark:assert-lazy-format-expressions, r=sfackler
Document that `assert!` format arguments are evaluated lazily
It can be useful to do some computation in `assert!` format arguments, in order to get better error messages. For example:
```rust
assert!(
some_condition,
"The state is invalid. Details: {}",
expensive_call_to_get_debugging_info(),
);
```
It seems like `assert!` only evaluates the format arguments if the assertion fails, which is useful but doesn't appear to be documented anywhere. This PR documents the behavior and adds some tests.
Guillaume Gomez [Wed, 17 Feb 2021 19:37:57 +0000 (20:37 +0100)]
Rollup merge of #82105 - nagisa:nagisa/ensure-removed, r=petrochenkov
Don't fail to remove files if they are missing
In the backend we may want to remove certain temporary files, but in
certain other situations these files might not be produced in the first
place. We don't exactly care about that, and the intent is really that
these files are gone after a certain point in the backend.
Here we unify the backend file removing calls to use `ensure_removed`
which will attempt to delete a file, but will not fail if it does not
exist (anymore).
The tradeoff to this approach is, of course, that we may miss instances
were we are attempting to remove files at wrong paths due to some bug –
compilation would silently succeed but the temporary files would remain
there somewhere.
Guillaume Gomez [Wed, 17 Feb 2021 19:37:55 +0000 (20:37 +0100)]
Rollup merge of #82094 - gilescope:to_digit_speedup2, r=m-ou-se
To digit simplification
I found out the other day that all the ascii digits have the first four bits as one would hope them to. (Eg. char `2` ends `0b0010`). There are two bits to indicate it's in the digit range ( `0b0011_0000`). If it is a true digit then all the higher bits aside from these two will be 0 (as ascii is the lowest part of the unicode u32 spectrum). So XORing with `0b11_0000` should mean we either get the number 0-9 or alternativly we get a larger number in the u32 space. If we get something that's not 0-9 then it will be discarded as it will be greater than the radix.
The code seems so fast though that there's quite a lot of noise in the benchmarks so it's not that easy to prove conclusively that it's faster as well as less instructions.
The non-fast path I was toying with as well wondering if we could do this as then we'd only have one return and less instructions still:
```
match self {
'a'..='z' => self as u32 - 'a' as u32 + 10,
'A'..='Z' => self as u32 - 'A' as u32 + 10,
_ => { radix = 10; self as u32 ^ ASCII_DIGIT_MASK},
}
```
Here's the [godbolt](https://godbolt.org/z/883c9n).
( H/T to ``@byteshadow`` for pointing out xor was what I needed)
Yonggang Luo [Thu, 8 Oct 2020 22:26:31 +0000 (22:26 +0000)]
Expose force_quotes on Windows.
Quotes the arg and not quotes the arg have different effect on Windows when the program called
are msys2/cygwin program.
Refer to https://github.com/msys2/MSYS2-packages/issues/2176
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Joshua Nelson [Fri, 12 Feb 2021 06:59:20 +0000 (01:59 -0500)]
Make `Clean` take &mut DocContext
- Take `FnMut` in `rustc_trait_selection::find_auto_trait_generics`
- Take `&mut DocContext` in most of `clean`
- Collect the iterator in auto_trait_impls instead of iterating lazily; the lifetimes were really bad.
- Changes `fn sess` to properly return a borrow with the lifetime of `'tcx`, not the mutable borrow.