Commit graph

138501 commits

Author SHA1 Message Date
Dylan DPC cc01bbe8f0
Rollup merge of #82259 - osa1:issue82156, r=petrochenkov
Fix popping singleton paths in when generating E0433

Fixes #82156

---

This was introduced with #72923, so pinging `@Patryk27` for reviews.
2021-02-19 02:49:11 +01:00
Dylan DPC c244546626
Rollup merge of #82245 - estebank:issue-78653, r=matthewjasper
Do not ICE when evaluating locals' types of invalid `yield`

When a `yield` is outside of a generator, check its value regardless to
avoid an ICE while trying to get all locals' types in writeback.

Fix #78653.
2021-02-19 02:49:09 +01:00
Dylan DPC 30f39fee9d
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)`.
2021-02-19 02:49:08 +01:00
Dylan DPC f8b61d852c
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.
2021-02-19 02:49:07 +01:00
Dylan DPC c821063a53
Rollup merge of #81873 - mark-i-m:unlock, r=m-ou-se
Add Mutex::unlock

Tracking issue: https://github.com/rust-lang/rust/issues/81872

Discussion: https://github.com/rust-lang/rust/pull/79434#issuecomment-757135874

r? `@m-ou-se`
2021-02-19 02:49:06 +01:00
Dylan DPC f468fd1d23
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?
2021-02-19 02:49:00 +01:00
Dylan DPC 94ab4078da
Rollup merge of #79747 - camelid:irrefut-lint-link, r=varkor
Add explanations and suggestions to `irrefutable_let_patterns` lint

Fixes #79716.
2021-02-19 02:48:59 +01:00
Camelid 5d2a2a1caa Add explanations and suggestions to irrefutable_let_patterns lint 2021-02-18 16:21:16 -08:00
bors 0148b971c9 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.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-18 19:45:42 +00:00
mark e92e5fd787 add Mutex::unlock 2021-02-18 11:56:19 -06:00
Gus Wynn 3e7ea401cd ignore file length 2021-02-18 08:17:43 -08:00
Ömer Sinan Ağacan 9889e44470 Fix popping singleton paths in when generating E0433
Fixes #82156
2021-02-18 19:13:40 +03:00
Dylan DPC efdcb4301b
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`.
2021-02-18 16:57:43 +01:00
Dylan DPC 555db2da70
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.
2021-02-18 16:57:42 +01:00
Dylan DPC 5ca94cd00a
Rollup merge of #82246 - jesusprubio:add-long-explanation-e0549, r=GuillaumeGomez
Add long explanation for E0549

Helps with #61137
2021-02-18 16:57:41 +01:00
Dylan DPC 04df75a429
Rollup merge of #82236 - matthiaskrgr:useless_conv, r=jyn514
avoid converting types into themselves (clippy::useless_conversion)
2021-02-18 16:57:40 +01:00
Dylan DPC 01104b5c29
Rollup merge of #82218 - rylev:copy-pdbs, r=Mark-Simulacrum
Make sure pdbs are copied along with exe and dlls when bootstrapping

This makes it easier to find the pdbs when wanting to debug the compiler on Windows.
2021-02-18 16:57:38 +01:00
Dylan DPC b3d3251271
Rollup merge of #82215 - TaKO8Ki:replace-if-let-while-let, r=varkor
Replace if-let and while-let with `if let` and `while let`

This pull request replaces if-let and while-let with `if let` and `while let`.

closes https://github.com/rust-lang/rust/issues/82205
2021-02-18 16:57:37 +01:00
Dylan DPC f01b339dae
Rollup merge of #82194 - estebank:arbitrary-bounds-suggestion, r=petrochenkov
In some limited cases, suggest `where` bounds for non-type params

Partially address #81971.
2021-02-18 16:57:36 +01:00
Dylan DPC 928819a9f7
Rollup merge of #82112 - BoxyUwU:tumbleweed, r=varkor
const_generics: Dont evaluate array length const when handling yet another error

Same ICE as #82009 except triggered by a different error.
cc ``@lcnr``
r? ``@varkor``
2021-02-18 16:57:35 +01:00
Dylan DPC 66211f6657
Rollup merge of #82066 - matthewjasper:trait-ref-fix, r=jackh726
Ensure valid TraitRefs are created for GATs

This fixes `ProjectionTy::trait_ref` to use the correct substs. Places that need all of the substs have been updated to not use `trait_ref`.

r? ````@jackh726````
2021-02-18 16:57:34 +01:00
Dylan DPC 55ab2e3879
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.

Closes #78165.

``@rustbot`` label: A-libtest T-libs
2021-02-18 16:57:33 +01:00
Nathan Nguyen 8a5c5681da nhwn: optimize counting digits in line numbers 2021-02-18 08:20:07 -06:00
Eduard-Mihai Burtescu 6165d1cc72 Print -Ztime-passes (and misc stats/logs) on stderr, not stdout. 2021-02-18 14:13:38 +02:00
bors cb2effd44e 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).

No functional changes intended.
2021-02-18 10:13:36 +00:00
Vadim Petrochenkov 4a88165124 ast: Keep expansion status for out-of-line module items
Also remove `ast::Mod` which is mostly redundant now
2021-02-18 13:07:49 +03:00
Vadim Petrochenkov eb65f15c78 ast: Stop using Mod in Crate
Crate root is sufficiently different from `mod` items, at least at syntactic level.

Also remove customization point for "`mod` item or crate root" from AST visitors.
2021-02-18 13:07:49 +03:00
Jesús Rubio 3c4fe1e3db
Update compiler/rustc_error_codes/src/error_codes/E0549.md
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2021-02-18 10:03:01 +01:00
Jesús Rubio 0e01c41c02
Update compiler/rustc_error_codes/src/error_codes/E0549.md
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2021-02-18 09:38:42 +01:00
Jesús Rubio 5112cf0282
Update compiler/rustc_error_codes/src/error_codes/E0549.md
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2021-02-18 09:23:21 +01:00
bors 25a2c13e9d Auto merge of #82249 - JohnTitor:rollup-3jbqija, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #82055 (Add diagnostics for specific cases for const/type mismatch err)
 - #82155 (Use !Sync std::lazy::OnceCell in usefulness checking)
 - #82202 (add specs for riscv32/riscv64 musl targets)
 - #82203 (Move some tests to more reasonable directories - 4)
 - #82211 (make `suggest_setup` help messages better)
 - #82212 (Remove redundant rustc_data_structures path component)
 - #82240 (remove useless ?s (clippy::needless_question_marks))
 - #82243 (Add more intra-doc links to std::io)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-18 07:22:30 +00:00
Yuki Okushi 21283dae9e
Rollup merge of #82243 - pickfire:patch-5, r=jyn514
Add more intra-doc links to std::io
2021-02-18 15:57:34 +09:00
Yuki Okushi ce6367f479
Rollup merge of #82240 - matthiaskrgr:qmark, r=Dylan-DPC
remove useless ?s (clippy::needless_question_marks)

Example code:
```rust
fn opts() -> Option<String> {
    let s: Option<String> = Some(String::new());
    Some(s?) // this can just be "s"
}
```
2021-02-18 15:57:33 +09:00
Yuki Okushi 53b5c6b58d
Rollup merge of #82212 - est31:graph_graph_graph, r=oli-obk
Remove redundant rustc_data_structures path component
2021-02-18 15:57:32 +09:00
Yuki Okushi 9e60e7e379
Rollup merge of #82211 - henryboisdequin:make-setup-msgs-better, r=jyn514
make `suggest_setup` help messages better

When I first built the compiler and didn't create a `config.toml.example`, the following was emitted:

```
help: consider running `x.py setup` or copying `config.toml.example`
```

I ran `x.py setup` but got an error so in this PR I made the help messages a little clearer.
2021-02-18 15:57:30 +09:00
Yuki Okushi fe15494857
Rollup merge of #82203 - c410-f3r:tests-tests-tests, r=Dylan-DPC
Move some tests to more reasonable directories - 4

cc #81941
2021-02-18 15:57:29 +09:00
Yuki Okushi 135a05c5ae
Rollup merge of #82202 - kraj:kraj/riscv-musl, r=estebank
add specs for riscv32/riscv64 musl targets

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2021-02-18 15:57:28 +09:00
Yuki Okushi 9d33abdc2a
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.
2021-02-18 15:57:27 +09:00
Yuki Okushi 0c25d154bd
Rollup merge of #82055 - JulianKnodt:ty_where_const, r=estebank
Add diagnostics for specific cases for const/type mismatch err

For now, this adds at least more information so better diagnostics can be emitted for const mismatch errors.

I'm not sure what exactly we want to emit, so I've left notes there temporarily, also to see if this is the right approach

r? ```@lcnr```
cc: ```@estebank```
2021-02-18 15:57:26 +09:00
Jesus Rubio 5ae392f3c6 Add long explanation for E0549 2021-02-18 06:53:01 +01:00
Esteban Küber 3eb454aabe Do not ICE when evaluating locals' types of invalid yield
When a `yield` is outside of a generator, check its value regardless to
avoid an ICE while trying to get all locals' types in writeback.

Fix #78653.
2021-02-17 20:44:00 -08:00
bors d1462d8558 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;
}

pub trait Thin = Pointee<Metadata = ()>;

pub const fn metadata<T: ?Sized>(ptr: *const T) -> <T as Pointee>::Metadata {}

pub const fn from_raw_parts<T: ?Sized>(*const (), <T as Pointee>::Metadata) -> *const T {}
pub const fn from_raw_parts_mut<T: ?Sized>(*mut (),<T as Pointee>::Metadata) -> *mut T {}

impl<T: ?Sized> NonNull<T> {
    pub const fn from_raw_parts(NonNull<()>, <T as Pointee>::Metadata) -> NonNull<T> {}

    /// Convenience for `(ptr.cast(), metadata(ptr))`
    pub const fn to_raw_parts(self) -> (NonNull<()>, <T as Pointee>::Metadata) {}
}

impl<T: ?Sized> *const T {
    pub const fn to_raw_parts(self) -> (*const (), <T as Pointee>::Metadata) {}
}

impl<T: ?Sized> *mut T {
    pub const fn to_raw_parts(self) -> (*mut (), <T as Pointee>::Metadata) {}
}

/// `<dyn SomeTrait as Pointee>::Metadata == DynMetadata<dyn SomeTrait>`
pub struct DynMetadata<Dyn: ?Sized> {
    // Private pointer to vtable
}

impl<Dyn: ?Sized> DynMetadata<Dyn> {
    pub fn size_of(self) -> usize {}
    pub fn align_of(self) -> usize {}
    pub fn layout(self) -> crate::alloc::Layout {}
}

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`
2021-02-18 04:22:16 +00:00
Ivan Tham 250eeb4c3c
Add missing link from stdio doc 2021-02-18 09:58:15 +08:00
bors cbf666dbc1 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)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-18 01:31:10 +00:00
Dylan DPC f7501b6d5e
Rollup merge of #82021 - csmoe:issue-78600, r=tmandry
Spell out nested Self type in lint message

Closes #78600
r? `@tmandry`
2021-02-17 23:51:20 +01:00
Dylan DPC 0b2f2b9413
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.

Closes: https://github.com/rust-lang/project-rfc-2229/issues/31

r? ````@nikomatsakis````
2021-02-17 23:51:19 +01:00
Dylan DPC cdd93fd3e2
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

Works towards #57374

r? ```@nikomatsakis```
2021-02-17 23:51:18 +01:00
Dylan DPC f79be2c6de
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.
2021-02-17 23:51:17 +01:00
Dylan DPC 91e5384fc0
Rollup merge of #81869 - mark-i-m:leading-vert, r=petrochenkov
Simplify pattern grammar, improve or-pattern diagnostics

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.

r? `@petrochenkov`
2021-02-17 23:51:16 +01:00
Dylan DPC d223250662
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

Fixes #81800
2021-02-17 23:51:14 +01:00