Commit Graph

24142 Commits

Author SHA1 Message Date
John Bobbo
47fb8e6c70
Deny the unsafe_op_in_unsafe_fn lint in
`rustc_arena`.
2023-04-28 21:00:54 -07:00
bors
7a96158b53 Auto merge of #110967 - matthiaskrgr:rollup-vfbl7gm, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #110877 (Provide better type hints when a type doesn't support a binary operator)
 - #110917 (only error combining +whole-archive and +bundle for rlibs)
 - #110921 (Use `NonNull::new_unchecked` and `NonNull::len` in `rustc_arena`.)
 - #110927 (Encoder/decoder cleanups)
 - #110944 (share BinOp::Offset between CTFE and Miri)
 - #110948 (run-make test: using single quotes to not trigger the shell)
 - #110957 (Fix an ICE in conflict error diagnostics)
 - #110960 (fix false negative for `unused_mut`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-04-28 23:13:42 +00:00
Matthias Krüger
34ef13b15b
Rollup merge of #110960 - lukas-code:unused-mut, r=compiler-errors
fix false negative for `unused_mut`

fixes https://github.com/rust-lang/rust/issues/110849

We want to avoid double diagnostics for code like this, but only if an error actually occurs:
```rust
fn main() {
    let mut x: (i32, i32);
    x.0 = 1;
}
```

The first commit fixes the lint and the second one removes all the unused `mut`s it found.
2023-04-28 22:56:47 +02:00
Matthias Krüger
235d088412
Rollup merge of #110957 - WaffleLapkin:reach_generator_conflict_error, r=cjgillot
Fix an ICE in conflict error diagnostics

Fixes  #110929
r? ``@cjgillot``
2023-04-28 22:56:47 +02:00
Matthias Krüger
03da9dbea0
Rollup merge of #110944 - RalfJung:offset, r=compiler-errors
share BinOp::Offset between CTFE and Miri

r? ``@oli-obk``
2023-04-28 22:56:46 +02:00
Matthias Krüger
37076ebbe5
Rollup merge of #110927 - nnethercote:Encoder-Decoder-cleanups, r=scottmcm
Encoder/decoder cleanups

Best reviewed one commit at a time.

r? ``@scottmcm``
2023-04-28 22:56:45 +02:00
Matthias Krüger
4751c85e50
Rollup merge of #110921 - JohnBobbo96:rustc_arena_nonnull, r=Nilstrieb
Use `NonNull::new_unchecked` and `NonNull::len` in `rustc_arena`.

This avoids a few extra dereferences as well as an `unwrap`.

According to the docs for [`NonNull::len`](https://doc.rust-lang.org/std/ptr/struct.NonNull.html#method.len) this also ensures that:

> This function is safe, even when the non-null raw slice cannot be dereferenced to a slice because the pointer does not have a valid address.

I am also fairly sure that the `unwrap` is unneeded in this case, as the docs for [`Box::into_raw`](https://doc.rust-lang.org/std/boxed/struct.Box.html#method.into_raw) also state:

> Consumes the Box, returning a wrapped raw pointer.
**The pointer will be properly aligned and non-null.**
2023-04-28 22:56:45 +02:00
Matthias Krüger
33f15e899d
Rollup merge of #110917 - Be-ing:whole_archive_with_staticlib_fix, r=petrochenkov
only error combining +whole-archive and +bundle for rlibs

Fixes https://github.com/rust-lang/rust/issues/110912

Checking `flavor == RlibFlavor::Normal` was accidentally lost in 601fc8b36b
https://github.com/rust-lang/rust/pull/105601

That caused combining +whole-archive and +bundle link modifiers on non-rlib crates to fail with a confusing error message saying that combination is unstable for rlibs. In particular, this caused the build to fail when +whole-archive was used on staticlib crates, even though +whole-archive effectively does nothing on non-bin crates because the final linker invocation is left to an external build system.

cc ``@petrochenkov``
2023-04-28 22:56:44 +02:00
Matthias Krüger
aba9fb4696
Rollup merge of #110877 - compiler-errors:binop-err, r=cjgillot
Provide better type hints when a type doesn't support a binary operator

For example, when checking whether `vec![A] == vec![A]` holds, we first evaluate the LHS's ty, then probe for any `PartialEq` implementations for that. If none is found, we report an error by evaluating `Vec<A>: PartialEq<?0>` for fulfillment errors, but the RHS is not yet evaluated and remains an inference variable `?0`!

To fix this, we evaluate the RHS and equate it to that RHS infer var `?0`, so that we are able to provide more detailed fulfillment errors for why `Vec<A>: PartialEq<Vec<A>>` doesn't hold (namely, the nested obligation `A: PartialEq<A>` doesn't hold).

Fixes #95285
Fixes #110867
2023-04-28 22:56:44 +02:00
bors
f495605381 Auto merge of #110901 - GuillaumeGomez:inlined-repr-rustdoc, r=notriddle
rustdoc: Fix missing `repr` attribute in doc(inline) on foreign items

Fixes https://github.com/rust-lang/rust/issues/110698.

r? `@notriddle`
2023-04-28 20:33:33 +00:00
Lukas Markeffsky
fc63926e18 remove unused muts 2023-04-28 20:19:48 +02:00
Maybe Waffle
754a62c306 Fix an ICE in conflict errors diagnostics 2023-04-28 17:37:56 +00:00
Lukas Markeffsky
69c71dacda fix false negative for unused_mut 2023-04-28 19:35:40 +02:00
Ralf Jung
586d17d330 share BinOp::Offset between CTFE and Miri 2023-04-28 16:00:08 +02:00
bors
43a78029b4 Auto merge of #110837 - scottmcm:offset-for-add, r=compiler-errors
Use MIR's `Offset` for pointer `add` too

~~Status: draft while waiting for #110822 to land, since this is built atop that.~~
~~r? `@ghost~~`

Canonical Rust code has mostly moved to `add`/`sub` on pointers, which take `usize`, instead of `offset` which takes `isize`.  (And, relatedly, when `sub_ptr` was added it turned out it replaced every single in-tree use of `offset_from`, because `usize` is just so much more useful than `isize` in Rust.)

Unfortunately, `intrinsics::offset` could only accept `*const` and `isize`, so there's a *huge* amount of type conversions back and forth being done.  They're identity conversions in the backend, but still end up producing quite a lot of unhelpful MIR.

This PR changes `intrinsics::offset` to accept `*const` *and* `*mut` along with `isize` *and* `usize`.  Conveniently, the backends and CTFE already handle this, since MIR's `BinOp::Offset` [already supports all four combinations](adaac6b166/compiler/rustc_const_eval/src/transform/validate.rs (L523-L528)).

To demonstrate the difference, I added some `mir-opt/pre-codegen/` tests around slice indexing.  Here's the difference to `[T]::get_mut`, since it uses `<*mut _>::add` internally:
```diff
`@@` -79,30 +70,21 `@@` fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
         StorageLive(_12);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageLive(_9);                 // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         _9 = _8 as *mut u32 (PtrToPtr);  // scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_13);                // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _13 = _2 as isize (IntToInt);    // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_14);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageLive(_15);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _15 = _9 as *const u32 (Pointer(MutToConstPointer)); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _14 = Offset(move _15, _13);     // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_15);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        _7 = move _14 as *mut u32 (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_14);                // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
-        StorageDead(_13);                // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
+        _7 = Offset(_9, _2);             // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
         StorageDead(_9);                 // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageDead(_12);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
         StorageDead(_11);                // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL
```
1c1c8e442a (diff-a841b6a4538657add3f39bc895744331453d0625e7aace128b1f604f0b63c8fdR80)
2023-04-28 09:26:59 +00:00
Nicholas Nethercote
23e91d4d73 Remove some unnecessary derives.
I was curious about how many `Encodable`/`Decodable` derives we have.
Some grepping revealed that it's over 500 of each, but the number of
`Encodable` ones was higher, which was weird. Most of the
`Encodable`-only ones were in `hir.rs`. This commit removes them all,
plus some other unnecessary derives in that file and others that I found
via trial and error.
2023-04-28 18:34:55 +10:00
Nicholas Nethercote
a676dfa888 Remove MemDecoder::read_byte.
It's just a synonym for `read_u8`.
2023-04-28 18:34:55 +10:00
Nicholas Nethercote
7a16d25365 Add some provided methods to Encoder/Decoder.
The methods for `i8`, `bool`, `char`, `str` are the same for all impls,
because they layered on top of other methods.
2023-04-28 18:34:54 +10:00
Nicholas Nethercote
fa133f5354 Remove a low-value assertion.
Checking that `read_raw_bytes(len)` changes the position by `len` is a
reasonable thing for a test, but isn't much use in just one of the
zillion `Decodable` impls.
2023-04-28 18:34:52 +10:00
bors
2fce229086 Auto merge of #110924 - matthiaskrgr:rollup-jvznpq2, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #110766 (More core::fmt::rt cleanup.)
 - #110873 (Migrate trivially translatable `rustc_parse` diagnostics)
 - #110904 (rustdoc: rebind bound vars to type-outlives predicates)
 - #110913 (Add some missing built-in lints)
 - #110918 (`remove_dir_all`: try deleting the directory even if `FILE_LIST_DIRECTORY` access is denied)
 - #110920 (Fix unavailable url)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-04-28 06:32:01 +00:00
Scott McMurray
e1da77c76d Also use mir::Offset for pointer add 2023-04-27 22:44:42 -07:00
Matthias Krüger
901bab70d3
Rollup merge of #110913 - compiler-errors:missing-lints, r=Nilstrieb
Add some missing built-in lints

(and also sort them, so this is best reviewed one commit at a time)

Fixes #110911

I wonder if there's a good way to detect when a lint is built-in (i.e. not associated to a lint pass). If so, it needs to be added to this list, or else we're unable to `allow` or `deny` it. Leaving that for future work, I guess...
2023-04-28 07:34:03 +02:00
Matthias Krüger
29f5ec3640
Rollup merge of #110873 - clubby789:migrate-rustc-parse-trivial, r=compiler-errors
Migrate trivially translatable `rustc_parse` diagnostics

cc #100717

Migrate diagnostics in `rustc_parse` which are emitted in a single statement. I worked on this by expanding the lint introduced in #108760, although that isn't included here as there is much more work to be done to satisfy it
2023-04-28 07:34:02 +02:00
Matthias Krüger
cf911ac757
Rollup merge of #110766 - m-ou-se:fmt-rt, r=jyn514
More core::fmt::rt cleanup.

- Removes the `V1` suffix from the `Argument` and `Flag` types.

- Moves more of the format_args lang items into the `core::fmt::rt` module. (The only remaining lang item in `core::fmt` is `Arguments` itself, which is a public type.)

Part of https://github.com/rust-lang/rust/issues/99012

Follow-up to https://github.com/rust-lang/rust/pull/110616
2023-04-28 07:34:02 +02:00
John Bobbo
618841b815
Use NonNull::new_unchecked and NonNull::len in
`rustc_arena`.
2023-04-27 19:48:37 -07:00
Yuki Okushi
c464be96f8
Rollup merge of #110893 - BoxyUwU:inline_const_nits, r=compiler-errors
remove inline const deadcode in typeck

inline consts get typeck'd with their parent so this is not reachable
2023-04-28 10:52:00 +09:00
Nicholas Nethercote
37c9e45186 Add a comment explaining the lack of Decoder::read_enum_variant.
Because I was wondering about it, and this may save a future person from
also wondering.
2023-04-28 09:51:00 +10:00
Nicholas Nethercote
b51deba9ac Remove MemDecoder::read_raw_bytes_inherent.
It's unnecessary. Note that `MemDecoder::read_raw_bytes` how has a `&'a
[u8]` return type, the same as what `read_raw_bytes_inherent` had.
2023-04-28 09:50:21 +10:00
bors
1a6ae3d692 Auto merge of #110916 - matthiaskrgr:rollup-g3c33zc, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #105745 (docs(std): clarify remove_dir_all errors)
 - #106456 (Correct `std::prelude` comment)
 - #106599 (Change memory ordering in System wrapper example)
 - #110838 (More `Typefoldable`/`TypeVisitable` cleanups)
 - #110851 (compiletest: emit assembly-output header in error)
 - #110853 (compiletest: add bpf-linker assembly support)
 - #110878 (Add `known-bug` tests for 4 unsound issues)
 - #110886 (`DepGraph` cleanups)
 - #110905 (Remove invalid value from scraped-examples.md)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-04-27 20:42:46 +00:00
Matthias Krüger
50ccd17db6
Rollup merge of #110886 - nnethercote:dep-graph-cleanups, r=cjgillot
`DepGraph` cleanups

r? `@cjgillot`
2023-04-27 21:34:17 +02:00
Matthias Krüger
57e9a4be48
Rollup merge of #110838 - nnethercote:more-Folder-Visitable-cleanups, r=lcnr
More `Typefoldable`/`TypeVisitable` cleanups

r? ``@lcnr``
2023-04-27 21:34:14 +02:00
Be Wilson
6a89e9451f only error with +whole-archive,+bundle for rlibs
Fixes https://github.com/rust-lang/rust/issues/110912

Checking `flavor == RlibFlavor::Normal` was accidentally lost in
601fc8b36b
https://github.com/rust-lang/rust/pull/105601

That caused combining +whole-archive and +bundle link modifiers on
non-rlib crates to fail with a confusing error message saying that
combination is unstable for rlibs. In particular, this caused the
build to fail when +whole-archive was used on staticlib crates, even
though +whole-archive effectively does nothing on non-bin crates because
the final linker invocation is left to an external build system.
2023-04-27 14:33:36 -05:00
Michael Goulet
0279922157 Add a few more missing lints 2023-04-27 18:43:03 +00:00
Michael Goulet
3793263c7d Sort hardwired lints 2023-04-27 18:35:27 +00:00
Michael Goulet
183c7904e9 Add invalid_macro_export_arguments to built-in macro list 2023-04-27 18:33:39 +00:00
bors
c14882f74e Auto merge of #107782 - Zoxc:worker-local, r=cjgillot
Move the WorkerLocal type from the rustc-rayon fork into rustc_data_structures

This PR moves the definition of the `WorkerLocal` type from `rustc-rayon` into `rustc_data_structures`. This is enabled by the introduction of the `Registry` type which allows you to group up threads to be used by `WorkerLocal` which is basically just an array with an per thread index. The `Registry` type mirrors the one in Rayon and each Rayon worker thread is also registered with the new `Registry`. Safety for `WorkerLocal` is ensured by having it keep a reference to the registry and checking on each access that we're still on the group of threads associated with the registry used to construct it.

Accessing a `WorkerLocal` is micro-optimized due to it being hot since it's used for most arena allocations.

Performance is slightly improved for the parallel compiler:
<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check</td><td align="right">1.9992s</td><td align="right">1.9949s</td><td align="right"> -0.21%</td></tr><tr><td>🟣 <b>hyper</b>:check</td><td align="right">0.2977s</td><td align="right">0.2970s</td><td align="right"> -0.22%</td></tr><tr><td>🟣 <b>regex</b>:check</td><td align="right">1.1335s</td><td align="right">1.1315s</td><td align="right"> -0.18%</td></tr><tr><td>🟣 <b>syn</b>:check</td><td align="right">1.8235s</td><td align="right">1.8171s</td><td align="right"> -0.35%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check</td><td align="right">6.9047s</td><td align="right">6.8930s</td><td align="right"> -0.17%</td></tr><tr><td>Total</td><td align="right">12.1586s</td><td align="right">12.1336s</td><td align="right"> -0.21%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9977s</td><td align="right"> -0.23%</td></tr></table>

cc `@SparrowLii`
2023-04-27 17:43:09 +00:00
Guillaume Gomez
adee37a080 repr attribute needs to be stored to be used in doc(inline) by rustdoc 2023-04-27 16:40:59 +02:00
Matthias Krüger
52d550b20e
Rollup merge of #110872 - Jules-Bertholet:err-67981, r=wesleywiser
Nicer ICE for #67981

Provides a slightly nicer ICE for #67981, documenting the problem. A proper fix will be necessary before `#![feature(unsized_fn_params)]` can be stabilized.

The problem is that the design of the `"rust-call"` ABI is fundamentally not compatible with `unsized_fn_params`. `"rust-call"` functions need to collect their arguments into a tuple, but if the arguments are not `Sized`, said tuple is potentially not even a valid type—and if it is, it requires `alloca` to create.

``@rustbot`` label +A-abi +A-codegen +F-unboxed_closures +F-unsized_fn_params
2023-04-27 15:10:56 +02:00
Matthias Krüger
563eb04c5d
Rollup merge of #110864 - compiler-errors:into-future-stable, r=jackh726
`IntoFuture::into_future` is no longer unstable

We don't need to gate the `IntoFuture::into_future` call in `.await` lowering anymore.

``@bors`` rollup
2023-04-27 15:10:55 +02:00
Matthias Krüger
63fbb05839
Rollup merge of #110816 - clubby789:rustc-passes-diagnostics, r=compiler-errors
Migrate `rustc_passes` to translatable diagnostics

cc #100717
2023-04-27 15:10:54 +02:00
Matthias Krüger
b1ff6e3e10
Rollup merge of #110814 - WaffleLapkin:sprinkle_#inline, r=Nilstrieb
Sprinkle some `#[inline]` in `rustc_data_structures::tagged_ptr`

This is based on `nm --demangle (rustc +a --print sysroot)/lib/librustc_driver-*.so | rg CopyTaggedPtr` which shows many methods that should probably be inlined. May fix the regression in https://github.com/rust-lang/rust/pull/110795.

r? ```@Nilstrieb```
2023-04-27 15:10:53 +02:00
Boxy
bdb956e9b0 nits 2023-04-27 12:13:28 +01:00
bors
6ce22733b9 Auto merge of #110882 - BoxyUwU:rename-some-ty-flags, r=compiler-errors
rename `NEEDS_SUBST` and `NEEDS_INFER`

implements rust-lang/compiler-team#617
2023-04-27 09:55:37 +00:00
Nicholas Nethercote
793b2ffb67 Factor out common code in intern_node.
There are three very similar blocks in this function.
2023-04-27 17:50:02 +10:00
Nicholas Nethercote
207cec017f Clean up with_task.
Currently it creates an `Option` and then does `map`/`unwrap_or` and
`map_or_else` on it, which is hard to read.

This commit simplifies things by moving more code into the two arms of
the if/else.
2023-04-27 17:48:15 +10:00
Boxy
842419712a rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
Boxy
f04b8fe0af rename needs_infer to has_infer 2023-04-27 08:35:19 +01:00
Nicholas Nethercote
4b85aa99ad Add a comment about TypeFoldable and slices. 2023-04-27 16:21:20 +10:00
bors
8b8110e146 Auto merge of #110728 - cjgillot:no-false-optes, r=oli-obk
Do not bother optimizing impossible functions.

This is currently checked by `ConstProp`, but I see no reason to restrict it to ConstProp only.
2023-04-27 04:29:49 +00:00
Michael Goulet
3125979b78 Fix a bad binop error when we need a call 2023-04-27 01:34:03 +00:00