Commit Graph

169691 Commits

Author SHA1 Message Date
bors
1a97162cb2 Auto merge of #94732 - nnethercote:infallible-encoder, r=bjorn3
Make `Encodable` and `Encoder` infallible.

A follow-up to #93066.

r? `@ghost`
2022-06-08 10:24:12 +00:00
bors
e45d9973b2 Auto merge of #97860 - Dylan-DPC:rollup-t3vxos8, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #97595 (Remove unwrap from get_vtable)
 - #97597 (Preserve unused pointer to address casts)
 - #97819 (Recover `import` instead of `use` in item)
 - #97823 (Recover missing comma after match arm)
 - #97851 (Use repr(C) when depending on struct layout in ptr tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-08 08:05:47 +00:00
Dylan DPC
1660b4b70c
Rollup merge of #97851 - saethlin:use-repr-c, r=thomcc
Use repr(C) when depending on struct layout in ptr tests

The test depends on the layout of this struct `Pair`, so it should use `repr(C)` instead of the default `repr(Rust)`.
2022-06-08 07:37:33 +02:00
Dylan DPC
a90c5a3c69
Rollup merge of #97823 - compiler-errors:missing-comma-match-arm, r=estebank
Recover missing comma after match arm

If we're missing a comma after a match arm expression, try parsing another pattern and a following `=>`. If we find both of those, then recover by suggesting to insert a `,`.

Fixes #80112
2022-06-08 07:37:32 +02:00
Dylan DPC
a64a9829c8
Rollup merge of #97819 - compiler-errors:use-import, r=wesleywiser
Recover `import` instead of `use` in item

When we definitely don't have a macro invocation (i.e. when we don't have `import ::`), then it's more productive to parse `import` as if it was incorrectly mistaken for `use`.

Not sure if this needs to be a verbose suggestion, but it renders strangely when it's not verbose:
```
error: expected item, found `import`
 --> /home/michael/test.rs:1:1
  |
1 | import std::{io::{self, Write}, rc::Rc};
  | ^^^^^^ help: items are imported using the `use` keyword: `use`
```

Happy to change it to `span_suggestion` instead of `span_suggestion_verbose` though.

Fixes #97788
2022-06-08 07:37:31 +02:00
Dylan DPC
d380b457d8
Rollup merge of #97597 - tmiasko:simplify-locals-side-effects, r=RalfJung,JakobDegen
Preserve unused pointer to address casts

Fixes #97421.

cc `@RalfJung`
2022-06-08 07:37:30 +02:00
Dylan DPC
148a44a001
Rollup merge of #97595 - ouz-a:issue-97381, r=compiler-errors
Remove unwrap from get_vtable

This avoids ICE on issue #97381 I think the bug is a bit deeper though, it compiles fine when `v` is `&v` which makes me think `Deref` is causing some issue with borrowck but it's fine I guess since this thing crashes since `nightly-2020-09-17` 😅
2022-06-08 07:37:29 +02:00
bors
64a7aa7016 Auto merge of #97447 - nnethercote:improve-folding, r=jackh726
Folding revamp

r? `@ghost`
2022-06-08 05:36:40 +00:00
Michael Goulet
b7ed860108 recover import instead of use in item 2022-06-07 19:14:03 -07:00
bors
47aee31b2a Auto merge of #97849 - matthiaskrgr:rollup-1yodhvw, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #97829 (Add regresion test for #95307)
 - #97831 (Remove `AlwaysLiveLocals` wrapper struct)
 - #97832 (Change `Direction::{is_forward,is_backward}` functions into constants)
 - #97840 (RustWrapper: adapt to APInt API changes in LLVM 15)
 - #97845 (Use more targeted suggestion when confusing i8 with std::i8)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-08 00:26:37 +00:00
Nicholas Nethercote
b983e42936 Rename rustc_serialize::opaque::Encoder as MemEncoder.
This avoids the name clash with `rustc_serialize::Encoder` (a trait),
and allows lots qualifiers to be removed and imports to be simplified
(e.g. fewer `as` imports).
2022-06-08 09:50:44 +10:00
Ben Kimock
5dd5244423 Use repr(C) when depending on struct layout in ptr tests 2022-06-07 19:24:09 -04:00
Nicholas Nethercote
90db033955 Folding revamp.
This commit makes type folding more like the way chalk does it.

Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods.
- `fold_with` is the standard entry point, and defaults to calling
  `super_fold_with`.
- `super_fold_with` does the actual work of traversing a type.
- For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead
  calls into a `TypeFolder`, which can then call back into
  `super_fold_with`.

With the new approach, `TypeFoldable` has `fold_with` and
`TypeSuperFoldable` has `super_fold_with`.
- `fold_with` is still the standard entry point, *and* it does the
  actual work of traversing a type, for all types except types of
  interest.
- `super_fold_with` is only implemented for the types of interest.

Benefits of the new model.
- I find it easier to understand. The distinction between types of
  interest and other types is clearer, and `super_fold_with` doesn't
  exist for most types.
- With the current model is easy to get confused and implement a
  `super_fold_with` method that should be left defaulted. (Some of the
  precursor commits fixed such cases.)
- With the current model it's easy to call `super_fold_with` within
  `TypeFolder` impls where `fold_with` should be called. The new
  approach makes this mistake impossible, and this commit fixes a number
  of such cases.
- It's potentially faster, because it avoids the `fold_with` ->
  `super_fold_with` call in all cases except types of interest. A lot of
  the time the compile would inline those away, but not necessarily
  always.
2022-06-08 09:24:03 +10:00
Nicholas Nethercote
7480b501b4 Avoid some unnecessary returns. 2022-06-08 09:22:23 +10:00
Nicholas Nethercote
23880a058b Add try_fold_uenevaluted.
We already have `visit_unevaluated`, so this improves consistency.

Also, define `TypeFoldable for Unevaluated<'tcx, ()>` in terms of
`TypeFoldable for Unevaluated<'tcx>`, which is neater.
2022-06-08 09:22:23 +10:00
Nicholas Nethercote
6ba2dfd330 Add TypeVisitor::visit_mir_const.
Because `TypeFoldable::try_fold_mir_const` exists, and even though
`visit_mir_const` isn't needed right now, the consistency makes the code
easier to understand.
2022-06-08 09:22:23 +10:00
Nicholas Nethercote
ca7585ab9a Remove EarlyBinder::{try_fold_with,visit_with}.
For most types the default impls of these methods are good enough, and
`EarlyBinder` is one such type.
2022-06-08 09:22:23 +10:00
Nicholas Nethercote
28be201d2f Use super_visit_with in a couple of visit_binder methods.
Because it's equivalent but simpler to what's currently there.
2022-06-08 09:22:23 +10:00
Nicholas Nethercote
465d198c74 Rename TypeVisitor::visit_unevaluated_const.
To match the corresponding type name.
2022-06-08 09:22:23 +10:00
Nicholas Nethercote
dc08bc51f2 Move finish out of the Encoder trait.
This simplifies things, but requires making `CacheEncoder` non-generic.
2022-06-08 09:21:05 +10:00
Matthias Krüger
c2d84852e5
Rollup merge of #97845 - estebank:spancito, r=compiler-errors
Use more targeted suggestion when confusing i8 with std::i8

r? `@compiler-errors`
2022-06-07 23:55:29 +02:00
Matthias Krüger
5870156d85
Rollup merge of #97840 - durin42:llvm-15-apint, r=nikic
RustWrapper: adapt to APInt API changes in LLVM 15

In https://reviews.llvm.org/D125556 upstream changed sext() and zext()
to allow some no-op cases, which previously required use of the *OrSelf()
methods, which I assume is what was going on here. The *OrSelf() methods
got removed in https://reviews.llvm.org/D125559 after two weeks of
deprecation because they came with some bonus (probably-undesired)
behavior. Since the behavior of sext() and zext() changed slightly, I
kept the old *OrSelf() calls in LLVM 14 and earlier, and only use the
new version in LLVM 15.

r? `@nikic`
2022-06-07 23:55:28 +02:00
Matthias Krüger
796c466cea
Rollup merge of #97832 - tmiasko:const-direction, r=cjgillot
Change `Direction::{is_forward,is_backward}` functions into constants

Make it explicit that the analysis direction is constant.

This also makes the value immediately available for optimizations.
Previously those functions were neither inline nor generic and so their
definition was unavailable when using data flow framework from other
crates.
2022-06-07 23:55:27 +02:00
Matthias Krüger
c9cf8aeab8
Rollup merge of #97831 - tmiasko:rm-always-live-locals-struct, r=davidtwco
Remove `AlwaysLiveLocals` wrapper struct

It is just a wrapper around a `BitSet` and
doesn't have any functionality of its own.
2022-06-07 23:55:26 +02:00
Matthias Krüger
36e9cbc0be
Rollup merge of #97829 - JohnTitor:issue-95307, r=compiler-errors
Add regresion test for #95307

Closes #95307
r? `@compiler-errors`
2022-06-07 23:55:25 +02:00
bors
b17e9d76f2 Auto merge of #97081 - oli-obk:outlives_query_fast_path, r=jackh726
Re-use the type op instead of calling the implied_outlives_bounds query directly

r? `@ghost`
2022-06-07 21:44:40 +00:00
Nicholas Nethercote
1acbe7573d Use delayed error handling for Encodable and Encoder infallible.
There are two impls of the `Encoder` trait: `opaque::Encoder` and
`opaque::FileEncoder`. The former encodes into memory and is infallible, the
latter writes to file and is fallible.

Currently, standard `Result`/`?`/`unwrap` error handling is used, but this is a
bit verbose and has non-trivial cost, which is annoying given how rare failures
are (especially in the infallible `opaque::Encoder` case).

This commit changes how `Encoder` fallibility is handled. All the `emit_*`
methods are now infallible. `opaque::Encoder` requires no great changes for
this. `opaque::FileEncoder` now implements a delayed error handling strategy.
If a failure occurs, it records this via the `res` field, and all subsequent
encoding operations are skipped if `res` indicates an error has occurred. Once
encoding is complete, the new `finish` method is called, which returns a
`Result`. In other words, there is now a single `Result`-producing method
instead of many of them.

This has very little effect on how any file errors are reported if
`opaque::FileEncoder` has any failures.

Much of this commit is boring mechanical changes, removing `Result` return
values and `?` or `unwrap` from expressions. The more interesting parts are as
follows.
- serialize.rs: The `Encoder` trait gains an `Ok` associated type. The
  `into_inner` method is changed into `finish`, which returns
  `Result<Vec<u8>, !>`.
- opaque.rs: The `FileEncoder` adopts the delayed error handling
  strategy. Its `Ok` type is a `usize`, returning the number of bytes
  written, replacing previous uses of `FileEncoder::position`.
- Various methods that take an encoder now consume it, rather than being
  passed a mutable reference, e.g. `serialize_query_result_cache`.
2022-06-08 07:01:26 +10:00
Nicholas Nethercote
582b9cbc45 Don't pass in a vector to Encoder::new.
It's not necessary.
2022-06-08 07:01:26 +10:00
Nicholas Nethercote
92b1ab8d57 Remove an unnecessary encoder operation. 2022-06-08 07:01:26 +10:00
Esteban Küber
8542dd02a8 Use more targeted suggestion when confusing i8 with std::i8 2022-06-07 13:39:21 -07:00
bors
5435ed6916 Auto merge of #97835 - Dylan-DPC:rollup-0ae3pwp, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #95948 (Improve the safety docs for `CStr`)
 - #97325 (Fix precise field capture of univariant enums)
 - #97817 (⬆️ rust-analyzer)
 - #97821 (Remove confusing sentence from `Mutex` docs)
 - #97826 (Add more information for rustdoc-gui tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-07 19:00:02 +00:00
Augie Fackler
1c26dd0db4 RustWrapper: adapt to APInt API changes in LLVM 15
In https://reviews.llvm.org/D125556 upstream changed sext() and zext()
to allow some no-op cases, which previously required use of the *OrSelf()
methods, which I assume is what was going on here. The *OrSelf() methods
got removed in https://reviews.llvm.org/D125559 after two weeks of
deprecation because they came with some bonus (probably-undesired)
behavior. Since the behavior of sext() and zext() changed slightly, I
kept the old *OrSelf() calls in LLVM 14 and earlier, and only use the
new version in LLVM 15.

r? @nikic
2022-06-07 14:47:57 -04:00
Tomasz Miąsko
6277c3a944 Preserve unused pointer to address casts 2022-06-07 17:33:16 +02:00
Dylan DPC
4851ec729a
Rollup merge of #97826 - GuillaumeGomez:rustdoc-gui-tests-info, r=Dylan-DPC
Add more information for rustdoc-gui tests

It was missing `--no-sandbox` in the `--help` message and the README was a bit outdated.

cc `@jsha` (I recall you asking some questions about passing arguments to the rustdoc gui tester so here it).

r? `@notriddle`
2022-06-07 17:25:45 +02:00
Dylan DPC
f12605b9ef
Rollup merge of #97821 - Nilstrieb:mutex-docs, r=Dylan-DPC
Remove confusing sentence from `Mutex` docs

The docs were saying something about "statically initializing" the
mutex, and it's not clear what this means. Remove that part to avoid
confusion.
2022-06-07 17:25:44 +02:00
Dylan DPC
32d945d9bd
Rollup merge of #97817 - lnicola:rust-analyzer-2022-06-07, r=lnicola
⬆️ rust-analyzer

r? ``@ghost``
2022-06-07 17:25:43 +02:00
Dylan DPC
fd76e0eee0
Rollup merge of #97325 - tmiasko:capture-enum-field, r=arora-aman
Fix precise field capture of univariant enums

When constructing a MIR from a THIR field expression, introduce an
additional downcast projection before accessing a field of an enum.

When rebasing a place builder on top of a captured place, account for
the fact that a single HIR enum field projection corresponds to two MIR
projection elements: a downcast element and a field element.

Fixes #95271.
Fixes #96299.
Fixes #96512.
Fixes #97378.

r? ``@nikomatsakis`` ``@arora-aman``
2022-06-07 17:25:43 +02:00
Dylan DPC
a9c4a7e1aa
Rollup merge of #95948 - Nilstrieb:improve-cstr-safety-docs, r=RalfJung
Improve the safety docs for `CStr`

Namely, the two functions `from_ptr` and `from_bytes_with_nul_unchecked`.
Before, these functions didn't state the requirements clearly enough,
and I was not immediately able to find them like for other functions.

This doesn't change the content of the docs, but simply rewords them for
clarity.

note: I'm not entirely sure about the '`ptr` must be valid for reads of `u8`.', there might be room for improvement for this (and maybe for the other docs as well 😄)
2022-06-07 17:25:42 +02:00
Yuki Okushi
786c8b4419
Add regresion test for #95307 2022-06-08 00:13:12 +09:00
Tomasz Miąsko
39de03d844 Change Direction::{is_forward,is_backward} functions into constants
Make it explicit that the analysis direction is constant.

This also makes the value immediately available for optimizations.
Previously those functions were neither inline nor generic and so their
definition was unavailable when using data flow framework from other
crates.
2022-06-07 17:02:55 +02:00
Tomasz Miąsko
631d767fee Remove AlwaysLiveLocals wrapper struct
It is just a wrapper around a `BitSet` and
doesn't have any functionality of its own.
2022-06-07 16:54:00 +02:00
Nilstrieb
0dda42bc14 Improve the safety docs for CStr
Namely, the two functions `from_ptr` and `from_bytes_with_nul_unchecked`.
Before, this functions didn't state the requirements clearly enough,
and I was not immediately able to find them like for other functions.

This doesn't change the content of the docs, but simply rewords them for
clarity.
2022-06-07 16:42:26 +02:00
Dylan DPC
e224185409
Update library/std/src/sync/mutex.rs
Co-authored-by: Weiyi Wang <wwylele@gmail.com>
2022-06-07 15:15:19 +02:00
bors
7fe2c4b00d Auto merge of #97825 - Dylan-DPC:rollup-ya51k1k, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #97058 (Various refactors to the incr comp workproduct handling)
 - #97301 (Allow unstable items to be re-exported unstably without requiring the feature be enabled)
 - #97738 (Fix ICEs from zsts within unsized types with non-zero offsets)
 - #97771 (Remove SIGIO reference on Haiku)
 - #97808 (Add some unstable target features for the wasm target codegen)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-07 11:08:58 +00:00
Guillaume Gomez
5799e7de16 Update rustdoc-gui README 2022-06-07 11:49:35 +02:00
Guillaume Gomez
232c2d6c25 Update help message for rustdoc-gui runner 2022-06-07 11:49:22 +02:00
Dylan DPC
95266530d5
Rollup merge of #97808 - alexcrichton:wasm-features, r=petrochenkov
Add some unstable target features for the wasm target codegen

I was experimenting with cross-language LTO for the wasm target recently
between Rust and C and found that C was injecting the `+mutable-globals`
flag on all functions. When specifying the corresponding
`-Ctarget-feature=+mutable-globals` feature to Rust it prints a warning
about an unknown feature. I've added the `mutable-globals` feature plus
another few I know of to the list of known features for wasm targets.
These features all continue to be unstable to source code as they were
before.
2022-06-07 11:41:09 +02:00
Dylan DPC
f32a4f06ab
Rollup merge of #97771 - rtzoeller:haiku_no_sigio, r=kennytm
Remove SIGIO reference on Haiku

Haiku doesn't define SIGIO. The nix crate already employs this workaround:
5dedbc7850/src/sys/signal.rs (L92-L94)
2022-06-07 11:41:09 +02:00
Dylan DPC
62c260de8c
Rollup merge of #97738 - Kixiron:zst-panic, r=eddyb
Fix ICEs from zsts within unsized types with non-zero offsets

- Fixes #97732
- Fixes ICEs while compiling `alloc` with `-Z randomize-layout`

r? ``@eddyb``
2022-06-07 11:41:08 +02:00
Dylan DPC
2035b50d80
Rollup merge of #97301 - semicoleon:unstable-reexport, r=petrochenkov
Allow unstable items to be re-exported unstably without requiring the feature be enabled

Closes #94972

The diagnostic may need some work still, and I haven't added a test yet
2022-06-07 11:41:07 +02:00