Commit graph

9266 commits

Author SHA1 Message Date
Matthias Krüger
81f3ae8997
Rollup merge of #90628 - ken-matsui:clarify-error-messages-caused-by-reexporting-pub-crate-visibility-to-outside, r=oli-obk
Clarify error messages caused by re-exporting `pub(crate)` visibility to outside

This PR clarifies error messages and suggestions caused by re-exporting pub(crate) visibility outside the crate.

Here is a small example ([Rust Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=e2cd0bd4422d4f20e6522dcbad167d3b)):

```rust
mod m {
    pub(crate) enum E {}
}
pub use m::E;

fn main() {}
```

This code is compiled to:

```
error[E0365]: `E` is private, and cannot be re-exported
 --> prog.rs:4:9
  |
4 | pub use m::E;
  |         ^^^^ re-export of private `E`
  |
  = note: consider declaring type or module `E` with `pub`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0365`.
```

However, enum `E` is actually public to the crate, not private totally—nevertheless, rustc treats `pub(crate)` and private visibility as the same on the error messages. They are not clear and should be segmented distinctly.

By applying changes in this PR, the error message below will be the following message that would be clearer:

```
error[E0365]: `E` is only public to inside of the crate, and cannot be re-exported outside
 --> prog.rs:4:9
  |
4 | pub use m::E;
  |         ^^^^ re-export of crate public `E`
  |
  = note: consider declaring type or module `E` with `pub`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0365`.
```
2021-11-20 10:21:13 +01:00
Matthias Krüger
7354bb331e
Rollup merge of #90575 - m-ou-se:compatible-variant-improvements, r=estebank
Improve suggestions for compatible variants on type mismatch.

Fixes #90553.

Before:
![image](https://user-images.githubusercontent.com/783247/140385675-6ff41090-eca2-41bc-b161-99c5dabfec61.png)

After:
![image](https://user-images.githubusercontent.com/783247/140385748-20cf26b5-ea96-4e56-8af2-5fe1ab16fd3b.png)

r? `````@estebank`````
2021-11-20 10:21:12 +01:00
bors
50f2c29200 Auto merge of #90535 - tmiasko:clone-from, r=oli-obk
Implement `clone_from` for `State`

Data flow engine uses `clone_from` for domain values.  Providing an
implementation of `clone_from` will avoid some intermediate memory
allocations.

Extracted from #90413.

r? `@oli-obk`
2021-11-20 04:12:03 +00:00
Ken Matsui
33ab5123e2
Clarify error messages caused by re-exporting pub(crate) visibility to outside 2021-11-20 10:47:33 +09:00
Matthias Krüger
cf69f9e220
Rollup merge of #90999 - RalfJung:miri_simd, r=oli-obk
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types

The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do.

The new helper methods will also be needed for https://github.com/rust-lang/miri/issues/1912.

r? ``````@oli-obk``````
2021-11-20 01:09:41 +01:00
bors
18fa4342fc Auto merge of #90996 - the8472:obligation-hashes2, r=matthewjasper
Optimize `impl Hash for ObligationCauseData` by not hashing `ObligationCauseCode` variant fields

Split out from #90913 since it's a [clear performance win](https://perf.rust-lang.org/compare.html?start=ad442399756573dccacb314b6bf8079964bcc72a&end=223f5e877fe93b5f437c2d703f883797913cd2b7) and should be easier to review.

It speeds up hashing for `Obligation` [deduplication](c9c4b5d727/compiler/rustc_trait_selection/src/traits/select/mod.rs (L2355-L2356)) by only hashing the discriminant of the `ObligationCauseCode` enum instead of its contents. That shouldn't affect hash quality much since there are several other fields in `Obligation` which should be unique enough, especially the predicate itself which is hashed as an interned pointer.
2021-11-19 11:50:51 +00:00
bors
e8423e6c44 Auto merge of #91033 - JohnTitor:rollup-sr9zg6o, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #89258 (Make char conversion functions unstably const)
 - #90578 (add const generics test)
 - #90633 (Refactor single variant `Candidate` enum into a struct)
 - #90800 (bootstap: create .cargo/config only if not present)
 - #90942 (windows: Return the "Not Found" error when a path is empty)
 - #90947 (Move some tests to more reasonable directories - 9.5)
 - #90961 (Suggest removal of arguments for unit variant, not replacement)
 - #90990 (Arenas cleanup)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-19 06:13:29 +00:00
Yuki Okushi
1576a7cc81
Rollup merge of #90990 - nnethercote:arenas-cleanup, r=oli-obk
Arenas cleanup

I was looking closely at the arenas code and here are some small improvement to readability.
2021-11-19 13:06:38 +09:00
Yuki Okushi
c74ff8b563
Rollup merge of #90961 - estebank:suggest-removal-of-call, r=nagisa
Suggest removal of arguments for unit variant, not replacement
2021-11-19 13:06:37 +09:00
Yuki Okushi
48947eafda
Rollup merge of #90633 - tmiasko:candidate-struct, r=nagisa
Refactor single variant `Candidate` enum into a struct

`Candidate` enum has only a single `Ref` variant.  Refactor it into a
struct and reduce overall indentation of the code by two levels.

No functional changes.
2021-11-19 13:06:34 +09:00
bors
ce3f3a5ffa Auto merge of #90329 - nbdd0121:typeck, r=nagisa
Try all stable method candidates first before trying unstable ones

Currently we try methods in this order in each step:
* Stable by value
* Unstable by value
* Stable autoref
* Unstable autoref
* ...

This PR changes it to first try pick methods without any unstable candidates, and if none is found, try again to pick unstable ones.

Fix #90320
CC #88971, hopefully would allow us to rename the "unstable_*" methods for integer impls back.

`@rustbot` label T-compiler T-libs-api
2021-11-19 03:00:46 +00:00
Nicholas Nethercote
0a89598dbd Add some comments.
Also use `Default::default()` in one `TypedArena::default()`, for
consistency with `DroplessArena::default()`.
2021-11-19 07:52:59 +11:00
bors
cc946fcd32 Auto merge of #91019 - JohnTitor:rollup-q95ra7r, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #90386 (Add `-Zassert-incr-state` to assert state of incremental cache)
 - #90438 (Clean up mess for --show-coverage documentation)
 - #90480 (Mention `Vec::remove` in `Vec::swap_remove`'s docs)
 - #90607 (Make slice->str conversion and related functions `const`)
 - #90750 (rustdoc: Replace where-bounded Clean impl with simple function)
 - #90895 (require full validity when determining the discriminant of a value)
 - #90989 (Avoid suggesting literal formatting that turns into member access)
 - #91002 (rustc: Remove `#[rustc_synthetic]`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-18 20:23:26 +00:00
Yuki Okushi
08c1639fd9
Rollup merge of #91002 - petrochenkov:nosynth, r=davidtwco
rustc: Remove `#[rustc_synthetic]`

This function parameter attribute was introduced in https://github.com/rust-lang/rust/pull/44866 as an intermediate step in implementing `impl Trait`, it's not necessary or used anywhere by itself.

Noticed while reviewing https://github.com/rust-lang/rust/pull/90947.
2021-11-19 02:22:59 +09:00
Yuki Okushi
dfbbb3b900
Rollup merge of #90989 - notriddle:notriddle/rustc-suggest-float-ending-in-dot, r=sanxiyn
Avoid suggesting literal formatting that turns into member access

Fixes #90974
2021-11-19 02:22:59 +09:00
Yuki Okushi
0a2b7d71d9
Rollup merge of #90895 - RalfJung:read-discriminant-valid, r=oli-obk
require full validity when determining the discriminant of a value

This resolves (for now) the semantic question that came up in https://github.com/rust-lang/rust/pull/89764: arguably, reading the discriminant of a value is 'using' that value, so we are in our right to demand full validity. Reading a discriminant is somewhat special in that it works for values of *arbitrary* type; all the other primitive MIR operations work on specific types (e.g. `bool` or an integer) and basically implicitly require validity as part of just "doing their job".

The alternative would be to just require that the discriminant itself is valid, if any -- but then what do we do for types that do not have a discriminant, which kind of validity do we check? [This code](81117ff930/compiler/rustc_codegen_ssa/src/mir/place.rs (L206-L215)) means we have to at least reject uninhabited types, but I would rather not special case that.

I don't think this can be tested in CTFE (since validity is not enforced there), I will add a compile-fail test to Miri:
```rust
#[allow(enum_intrinsics_non_enums)]
fn main() {
    let i = 2u8;
    std::mem::discriminant(unsafe { &*(&i as *const _ as *const bool) }); // UB
}
```

(I tried running the check even on the CTFE machines, but then it runs during ConstProp and that causes all sorts of problems. We could run it for ConstEval but not ConstProp, but that simply does not seem worth the effort currently.)

r? ``@oli-obk``
2021-11-19 02:22:58 +09:00
Yuki Okushi
728b3f2356
Rollup merge of #90386 - pierwill:assert-incr-state-85864, r=Aaron1011
Add `-Zassert-incr-state` to assert state of incremental cache

Closes #85864.
2021-11-19 02:22:54 +09:00
bors
b6f580acc0 Auto merge of #90382 - alexcrichton:wasm64-libstd, r=joshtriplett
std: Get the standard library compiling for wasm64

This commit goes through and updates various `#[cfg]` as appropriate to
get the wasm64-unknown-unknown target behaving similarly to the
wasm32-unknown-unknown target. Most of this is just updating various
conditions for `target_arch = "wasm32"` to also account for `target_arch
= "wasm64"` where appropriate. This commit also lists `wasm64` as an
allow-listed architecture to not have the `restricted_std` feature
enabled, enabling experimentation with `-Z build-std` externally.

The main goal of this commit is to enable playing around with
`wasm64-unknown-unknown` externally via `-Z build-std` in a way that's
similar to the `wasm32-unknown-unknown` target. These targets are
effectively the same and only differ in their pointer size, but wasm64
is much newer and has much less ecosystem/library support so it'll still
take time to get wasm64 fully-fledged.
2021-11-18 17:19:27 +00:00
Ralf Jung
2f1a1f530b fix CTFE/Miri simd_insert/extract on array-style repr(simd) types 2021-11-18 09:10:35 -05:00
Vadim Petrochenkov
91e02177a1 rustc: Remove #[rustc_synthetic]
This function parameter attribute was introduced in https://github.com/rust-lang/rust/pull/44866 as an intermediate step in implementing `impl Trait`, it's not necessary or used anywhere by itself.
2021-11-18 14:32:29 +08:00
Michael Howell
a7261c32f4 Avoid suggesting literal formatting that turns into member access
Fixes #90974
2021-11-17 17:23:15 -07:00
Matthias Krüger
469faa2b66
Rollup merge of #90901 - rukai:improve_manuallydrop_help, r=estebank
Improve ManuallyDrop suggestion

closes https://github.com/rust-lang/rust/issues/90585
* Fixes the recommended change to use ManuallyDrop as per the issue
* Changes the note to a help
* improves the span so it only points at the type.
2021-11-17 15:58:06 +01:00
Matthias Krüger
fb660de28e
Rollup merge of #90900 - andjo403:removeLlvm12Check, r=nikic
Remove workaround for the forward progress handling in LLVM

this workaround was only needed for LLVM < 12 and the minimum LLVM version was updated to 12 in #90175
2021-11-17 15:58:05 +01:00
Matthias Krüger
23ad7a7697
Rollup merge of #90884 - Nilstrieb:fix-span-trivial-trait-bound, r=estebank
Fix span for non-satisfied trivial trait bounds

The spans for "trait bound not satisfied" errors in trivial trait bounds referenced the entire item (fn, impl, struct) before.
Now they only reference the obligation itself (`String: Copy`)

Address #90869
2021-11-17 15:58:04 +01:00
Matthias Krüger
ab958a7ab0
Rollup merge of #90861 - 5225225:nonprinting-char, r=davidtwco
Print escaped string if char literal has multiple characters, but only one printable character

Fixes #90857

I'm not sure about the error message here, it could get rather long and *maybe* using the names of characters would be better? That wouldn't help the length any, though.
2021-11-17 15:58:02 +01:00
Matthias Krüger
d7b86880d2
Rollup merge of #90667 - rukai:improve_static_lifetime_diagnostics, r=estebank
Improve diagnostics when a static lifetime is expected

Makes progress towards https://github.com/rust-lang/rust/issues/90600

The diagnostics here were previously entirely removed due to giving a misleading suggestion but if we instead provide an informative label in that same location it should better help the user understand the situation.

I included the example from the issue as it demonstrates an area where the diagnostics are still lacking.
Happy to remove that if its just adding noise atm.
2021-11-17 15:57:57 +01:00
Matthias Krüger
07342828c5
Rollup merge of #89610 - guswynn:must_use_future, r=wesleywiser
warn on must_use use on async fn's

As referenced in #78149

This only works on `async` fn's for now, I can also look into if I can get `Box<dyn Future>` and `impl Future` working at this level (hir)
2021-11-17 15:57:56 +01:00
Matthias Krüger
3f550078c9
Rollup merge of #90935 - jhpratt:alphabetize-features, r=joshtriplett
Alphabetize language features

This should significantly reduce the frequency of merge conflicts.

r? ````@joshtriplett````

````@rustbot```` label: +A-contributor-roadblock +S-waiting-on-review
2021-11-16 23:58:25 +01:00
Matthias Krüger
eb9859f00d
Rollup merge of #90933 - compiler-errors:master, r=estebank
Fix await suggestion on non-future type

Remove a match block that would suggest to add `.await` in the case where the expected type's `Future::Output` equals the found type. We only want to suggest `.await`ing in the opposite case (the found type's `Future::Output` equals the expected type).

The code sample is here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6ba6b83d4dddda263553b79dca9f6bcb

Before:
```
➜  ~ rustc --edition=2021 --crate-type=lib test.rs
error[E0308]: `match` arms have incompatible types
 --> test.rs:4:14
  |
2 |       let x = match 1 {
  |  _____________-
3 | |         1 => other(),
  | |              ------- this is found to be of type `impl Future`
4 | |         2 => other().await,
  | |              ^^^^^^^^^^^^^ expected opaque type, found enum `Result`
5 | |     };
  | |_____- `match` arms have incompatible types
  |
  = note: expected type `impl Future`
             found enum `Result<(), ()>`
help: consider `await`ing on the `Future`
  |
4 |         2 => other().await.await,
  |                           ++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
```

After:
```
➜  ~ rustc +stage1 --edition=2021 --crate-type=lib test.rs
error[E0308]: `match` arms have incompatible types
 --> test.rs:4:14
  |
2 |       let x = match 1 {
  |  _____________-
3 | |         1 => other(),
  | |              ------- this is found to be of type `impl Future`
4 | |         2 => other().await,
  | |              ^^^^^^^^^^^^^ expected opaque type, found enum `Result`
5 | |     };
  | |_____- `match` arms have incompatible types
  |
  = note: expected type `impl Future`
             found enum `Result<(), ()>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
```

Fixes #90931
2021-11-16 23:58:24 +01:00
Matthias Krüger
c63cf076b5
Rollup merge of #90787 - JohnTitor:inline-sorted-index-map, r=oli-obk
Add `#[inline]`s to `SortedIndexMultiMap`

They're small enough and good candidates to add `#[inline]` generally.
2021-11-16 23:58:22 +01:00
Nicholas Nethercote
552073701f Remove unnecessary lifetime argument from arena macros.
Because it's always `'tcx`. In fact, some of them use a mixture of
passed-in `$tcx` and hard-coded `'tcx`, so no other lifetime would even
work.

This makes the code easier to read.
2021-11-17 09:38:30 +11:00
Michael Goulet
fc816c37b7 Fix await suggestion better 2021-11-16 13:30:01 -08:00
Alex Crichton
97cd27ab1d Add emscripten to the "wasm" family of targets 2021-11-16 13:10:35 -08:00
Esteban Kuber
4ca4e094ab Suggest removal of arguments for unit variant, not replacement 2021-11-16 20:40:35 +00:00
Mara Bos
09e4a75f29 Use span_suggestions instead of multipart_suggestions. 2021-11-16 19:53:00 +01:00
Mara Bos
b331b66082 Improve compatible enum variant suggestions. 2021-11-16 19:52:58 +01:00
Mara Bos
453e2423e6 Improve suggestion for unit Option/Result at the end of a block. 2021-11-16 19:52:58 +01:00
Mara Bos
483cff7ed3 Add SourceMap::indentation_before. 2021-11-16 19:52:58 +01:00
Wesley Wiser
83ce771c0f Update compiler/rustc_passes/src/check_attr.rs
Co-authored-by: Yuki Okushi <jtitor@2k36.org>
2021-11-16 11:43:13 -05:00
bors
d914f17ca7 Auto merge of #90919 - nnethercote:rm-DropArena, r=Mark-Simulacrum
Remove `DropArena`.

Most arena-allocate types that impl `Drop` get their own `TypedArena`, but a
few infrequently used ones share a `DropArena`. This sharing adds complexity
but doesn't help performance or memory usage. Perhaps it was more effective in
the past prior to some other improvements to arenas.

This commit removes `DropArena` and the sharing of arenas via the `few`
attribute of the `arena_types` macro. This change removes over 100 lines of
code and nine uses of `unsafe` (one of which affects the parallel compiler) and
makes the remaining code easier to read.
2021-11-16 11:48:37 +00:00
bors
934624fe5f Auto merge of #90945 - JohnTitor:rollup-wc35xss, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #86455 (check where-clause for explicit `Sized` before suggesting `?Sized`)
 - #90801 (Normalize both arguments of `equate_normalized_input_or_output`)
 - #90803 (Suggest `&str.chars()` on attempt to `&str.iter()`)
 - #90819 (Fixes incorrect handling of TraitRefs when emitting suggestions.)
 - #90910 (fix getting the discriminant of a zero-variant enum)
 - #90925 (rustc_mir_build: reorder bindings)
 - #90928 (Use a different server for checking clock drift)
 - #90936 (Add a regression test for #80772)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-11-16 08:22:55 +00:00
5225225
09e59c2875 Inline printable function 2021-11-16 08:06:31 +00:00
5225225
52199c93bb Suggest removing the non-printing characters 2021-11-16 08:06:30 +00:00
5225225
de05d3ec31 Print full char literal on error if any are non-printing 2021-11-16 08:06:30 +00:00
Yuki Okushi
cdc12ba5a3
Rollup merge of #90925 - krasimirgg:rustc_mir_build_fix, r=petrochenkov
rustc_mir_build: reorder bindings

No functional changes intended.

I'm playing around with building compiler components using nightly rust
(2021-11-02) in a non-standard way. I encountered the following error while
trying to build rustc_mir_build:

```
error[E0597]: `wildcard` does not live long enough
    --> rust/src/nightly/compiler/rustc_mir_build/src/build/matches/mod.rs:1767:82
     |
1767 |         let mut otherwise_candidate = Candidate::new(expr_place_builder.clone(), &wildcard, false);
     |                                                                                  ^^^^^^^^^ borrowed value does not live long enough
...
1799 |     }
     |     -
     |     |
     |     `wildcard` dropped here while still borrowed
     |     borrow might be used here, when `guard_candidate` is dropped and runs the destructor for type `Candidate<'_, '_>`
     |
     = note: values in a scope are dropped in the opposite order they are defined
```

I believe this flags an issue that may become an error in the future.
Swapping the order of `wildcard` and `guard_candidate` resolves it.
2021-11-16 15:59:42 +09:00
Yuki Okushi
6d9c3a1b97
Rollup merge of #90910 - RalfJung:const-discriminant-empty-enum, r=petrochenkov
fix getting the discriminant of a zero-variant enum

Fixes https://github.com/rust-lang/rust/issues/89765
2021-11-16 15:59:41 +09:00
Yuki Okushi
d44cec3453
Rollup merge of #90819 - JakobDegen:issue-90804, r=petrochenkov
Fixes incorrect handling of TraitRefs when emitting suggestions.

Closes #90804 , although there were more issues here that were hidden by the thing that caused this ICE.

Underlying problem was that substitutions were being thrown out, which not only leads to an ICE but also incorrect diagnostics. On top of that, in some cases the self types from the root obligations were being mixed in with those from derived obligations.

This makes a couple diagnostics arguable worse ("`B<C>` does not implement `Copy`" instead of "`C` does not implement `Copy`") but the worse diagnostics are at least still correct and that downside is in my opinion clearly outweighed by the benefits of fixing the ICE and unambiguously wrong diagnostics.
2021-11-16 15:59:40 +09:00
Yuki Okushi
b17de50a41
Rollup merge of #90803 - TaKO8Ki:suggest-chars-on-attempt-to-iter, r=estebank
Suggest `&str.chars()` on attempt to `&str.iter()`

closes #90786
2021-11-16 15:59:39 +09:00
Yuki Okushi
21bff4a4c1
Rollup merge of #90801 - b-naber:missing_normalization_equate_inputs_output, r=jackh726
Normalize both arguments of `equate_normalized_input_or_output`

Fixes https://github.com/rust-lang/rust/issues/90638
Fixes https://github.com/rust-lang/rust/issues/90612

Temporary fix for a more complex underlying problem stemming from an inability to normalize closure substs during typecheck.

r? ````@jackh726````
2021-11-16 15:59:39 +09:00
Yuki Okushi
ebef3ce25b
Rollup merge of #86455 - tlyu:check-where-before-suggesting-unsized, r=estebank
check where-clause for explicit `Sized` before suggesting `?Sized`

Fixes #85945.

Based on #86454.

``@rustbot`` label +A-diagnostics +A-traits +A-typesystem +D-papercut +T-compiler
2021-11-16 15:59:38 +09:00