Commit Graph

35358 Commits

Author SHA1 Message Date
Michael Scholten
3c5e88c7d1 Improved the compiler code with clippy 2024-04-24 09:41:44 +02:00
bors
c67277301c Auto merge of #124277 - matthiaskrgr:rollup-zdb93i4, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #123680 (Deny gen keyword in `edition_2024_compat` lints)
 - #124057 (Fix ICE when ADT tail has type error)
 - #124168 (Use `DefiningOpaqueTypes::Yes` in rustdoc, where the `InferCtxt` is guaranteed to have no opaque types it can define)
 - #124197 (Move duplicated code in functions in `tests/rustdoc-gui/notable-trait.goml`)
 - #124200 (Improve handling of expr->field errors)
 - #124220 (Miri: detect wrong vtables in wide pointers)
 - #124266 (remove an unused type from the reentrant lock tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-23 06:23:20 +00:00
Matthias Krüger
8039488e59
Rollup merge of #124220 - RalfJung:interpret-wrong-vtable, r=oli-obk
Miri: detect wrong vtables in wide pointers

Fixes https://github.com/rust-lang/miri/issues/3497.
Needed to catch the UB that https://github.com/rust-lang/rust/pull/123572 will start exploiting.

r? `@oli-obk`
2024-04-23 06:24:57 +02:00
Matthias Krüger
5800e2a6f9
Rollup merge of #124200 - scrabsha:sasha/->, r=compiler-errors,fmease
Improve handling of expr->field errors

The current message for "`->` used for field access" is the following:

```rust
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `->`
 --> src/main.rs:2:6
  |
2 |     a->b;
  |      ^^ expected one of 8 possible tokens
```

([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7f8b6f4433aa7866124123575456f54e))

This PR tries to address this by adding a dedicated error message and recovery. The proposed error message is:

```
error: `->` used for field access or method call
 --> ./tiny_test.rs:2:6
  |
2 |     a->b;
  |      ^^ help: try using `.` instead
  |
  = help: the `.` operator will dereference the value if needed
```

(feel free to bikeshed it as much as necessary)
2024-04-23 06:24:57 +02:00
Matthias Krüger
326cd5cb68
Rollup merge of #124168 - oli-obk:define_opaque_types12, r=lcnr
Use `DefiningOpaqueTypes::Yes` in rustdoc, where the `InferCtxt` is guaranteed to have no opaque types it can define

r? `@lcnr`

I manually checked there it's always `tcx.infer_ctxt().build()`
2024-04-23 06:24:56 +02:00
Matthias Krüger
8859631b40
Rollup merge of #124057 - gurry:124031-ice-layout-errored, r=compiler-errors
Fix ICE when ADT tail has type error

Fixes #124031
2024-04-23 06:24:55 +02:00
Matthias Krüger
d5cfc5c07a
Rollup merge of #123680 - compiler-errors:gen-kw, r=Nadrieril
Deny gen keyword in `edition_2024_compat` lints

Splits the `keyword_idents` lint into two -- `keyword_idents_2018` and `keyword_idents_2024` -- since each corresponds to a future-compat warning in a different edition. Group these together into a new `keyword_idents` lint group, and add the latter to the `rust_2024_compatibility` so that `gen` is ready for the 2024 edition.

cc `@traviscross` `@ehuss`
2024-04-23 06:24:55 +02:00
bors
a77f76e263 Auto merge of #123992 - compiler-errors:no-has-typeck-results, r=jackh726
`has_typeck_results` doesnt need to be a query

self-explanatory
2024-04-23 04:13:33 +00:00
bors
aca749eefc Auto merge of #121801 - zetanumbers:async_drop_glue, r=oli-obk
Add simple async drop glue generation

This is a prototype of the async drop glue generation for some simple types. Async drop glue is intended to behave very similar to the regular drop glue except for being asynchronous. Currently it does not execute synchronous drops but only calls user implementations of `AsyncDrop::async_drop` associative function and awaits the returned future. It is not complete as it only recurses into arrays, slices, tuples, and structs and does not have same sensible restrictions as the old `Drop` trait implementation like having the same bounds as the type definition, while code assumes their existence (requires a future work).

This current design uses a workaround as it does not create any custom async destructor state machine types for ADTs, but instead uses types defined in the std library called future combinators (deferred_async_drop, chain, ready_unit).

Also I recommend reading my [explainer](https://zetanumbers.github.io/book/async-drop-design.html).

This is a part of the [MCP: Low level components for async drop](https://github.com/rust-lang/compiler-team/issues/727) work.

Feature completeness:

 - [x] `AsyncDrop` trait
 - [ ] `async_drop_in_place_raw`/async drop glue generation support for
   - [x] Trivially destructible types (integers, bools, floats, string slices, pointers, references, etc.)
   - [x] Arrays and slices (array pointer is unsized into slice pointer)
   - [x] ADTs (enums, structs, unions)
   - [x] tuple-like types (tuples, closures)
   - [ ] Dynamic types (`dyn Trait`, see explainer's [proposed design](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#async-drop-glue-for-dyn-trait))
   - [ ] coroutines (https://github.com/rust-lang/rust/pull/123948)
 - [x] Async drop glue includes sync drop glue code
 - [x] Cleanup branch generation for `async_drop_in_place_raw`
 - [ ] Union rejects non-trivially async destructible fields
 - [ ] `AsyncDrop` implementation requires same bounds as type definition
 - [ ] Skip trivially destructible fields (optimization)
 - [ ] New [`TyKind::AdtAsyncDestructor`](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#adt-async-destructor-types) and get rid of combinators
 - [ ] [Synchronously undroppable types](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#exclusively-async-drop)
 - [ ] Automatic async drop at the end of the scope in async context
2024-04-23 02:10:23 +00:00
Guillaume Gomez
a60ccc1876
Rollup merge of #124252 - michaelwoerister:better-forbidden-read-ice, r=oli-obk
Improve ICE message for forbidden dep-graph reads.

The new message mentions the main context that the ICE might occur in and it mentions the query/dep-node that is being read.

cc https://github.com/rust-lang/rust/pull/123781, where this would have been helpful.
2024-04-22 20:26:00 +02:00
Guillaume Gomez
6a326d889a
Rollup merge of #124230 - reitermarkus:generic-nonzero-stable, r=dtolnay
Stabilize generic `NonZero`.

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

r? `@dtolnay`
2024-04-22 20:26:00 +02:00
Guillaume Gomez
17c28799f3
Rollup merge of #124217 - Zalathar:pre-branch, r=oli-obk
coverage: Prepare for improved branch coverage

When trying to rebase my new branch coverage work (including #124154) on top of the introduction of MC/DC coverage (#123409), I found it a lot harder than anticipated. With the benefit of hindsight, the branch coverage code and MC/DC code have become more interdependent than I'm happy with.

This PR therefore disentangles them a bit, so that it will be easier for both areas of code to evolve independently without interference.

---

This PR also includes a few extra branch coverage tests that I had sitting around from my current branch coverage work. They mostly just demonstrate that certain language constructs listed in #124118 currently don't have branch coverage support.

``@rustbot`` label +A-code-coverage
2024-04-22 20:25:59 +02:00
Guillaume Gomez
e984447405
Rollup merge of #124183 - compiler-errors:unnecessary-by-ref, r=oli-obk
Stop taking `ParamTy`/`ParamConst`/`EarlyParamRegion`/`AliasTy` by ref

It's unnecessary and is annoying when we have it by value.
2024-04-22 20:25:59 +02:00
Guillaume Gomez
1a12ec41e9
Rollup merge of #124178 - GuillaumeGomez:llvm-backend, r=oli-obk
[cleanup] [llvm backend] Prevent creating the same `Instance::mono` multiple times

Just a little thing I came across while going through the code.

r? ```@oli-obk```
2024-04-22 20:25:58 +02:00
Markus Reiter
33e68aadc9
Stabilize generic NonZero. 2024-04-22 18:48:47 +02:00
Michael Goulet
7789874e6e Deny gen keyword in edition_2024_compat lints 2024-04-22 11:51:50 -04:00
Sasha Pourcelot
98332c108b Improve handling of expr->field errors
The current message for "`->` used for field access" is the following:

```rust
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `->`
 --> src/main.rs:2:6
  |
2 |     a->b;
  |      ^^ expected one of 8 possible tokens
```

(playground link[1])

This PR tries to address this by adding a dedicated error message and recovery. The proposed error message is:

```
error: `->` used for field access or method call
 --> ./tiny_test.rs:2:6
  |
2 |     a->b;
  |      ^^ help: try using `.` instead
  |
  = help: the `.` operator will dereference the value if needed
```

(feel free to bikeshed it as much as necessary)

[1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7f8b6f4433aa7866124123575456f54e

Signed-off-by: Sasha Pourcelot <sasha.pourcelot@protonmail.com>
2024-04-22 17:47:35 +02:00
Oli Scherer
6bff7f45f1 Use DefiningOpaqueTypes::Yes, as the InferCtxt we use has no opaque types it may define 2024-04-22 13:11:29 +00:00
Michael Woerister
6146a51f17 Add more context to the forbidden dep-graph read ICE error message. 2024-04-22 14:54:28 +02:00
Daria Sukhonina
67980dd6fb
Fix typo in the has_surface_drop's doc comment
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2024-04-22 15:44:01 +03:00
Daria Sukhonina
a9c7465997 Fix copy-paste typo in the comment within consider_builtin_async_destruct_candidate 2024-04-22 15:42:07 +03:00
Daria Sukhonina
0881e3e531 Exhaustivelly match TyKind in consider_builtin_async_destruct_candidate 2024-04-22 15:41:08 +03:00
bors
7f2fc33da6 Auto merge of #115120 - icedrocket:ignore-strip-on-msvc, r=michaelwoerister
Ignore `-C strip` on MSVC

tl;dr - Define `-Cstrip` to only ever affect the binary; no other build artifacts.

This is necessary to improve cross-platform behavior consistency: if someone wanted debug information to be contained only in separate files on all platforms, they would set `-Cstrip=symbols` and `-Csplit-debuginfo=packed`, but this would result in no PDB files on MSVC.

Resolves #114215
2024-04-22 12:05:39 +00:00
Zalathar
2b6adb06fb coverage: Separate branch pairs from other mapping kinds
This clears the way for larger changes to how branches are handled by the
coverage instrumentor, in order to support branch coverage for more language
constructs.
2024-04-22 21:55:34 +10:00
Zalathar
b5a22be6a3 coverage: Move some helper code into BranchInfoBuilder 2024-04-22 21:55:33 +10:00
Zalathar
97bf553682 coverage: Detach MC/DC branch spans from regular branch spans
MC/DC's reliance on the existing branch coverage types is making it much harder
to improve branch coverage.
2024-04-22 21:55:33 +10:00
Michael Woerister
c373ec07c4 Improve ICE message for forbidden dep-graph reads. 2024-04-22 12:11:07 +02:00
bors
32885838c0 Auto merge of #124112 - beetrees:incremental-os-str, r=Nadrieril
Fix ICE when there is a non-Unicode entry in the incremental crate directory

Fix the ICE that occurs when there is a non-Unicode entry in the incremental crate directory by replacing uses of `to_string_lossy` + `assert_no_characters_lost` with `to_str`. The added test would cause the compiler to ICE before this PR.
2024-04-22 04:00:58 +00:00
Gurinder Singh
06cd79bb5b Fix ICE when ADT tail has type error 2024-04-22 09:12:36 +05:30
bors
fb898629a2 Auto merge of #124241 - matthiaskrgr:rollup-xhu90xr, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #123840 (Add an intrinsic for `ptr::from_raw_parts(_mut)`)
 - #124224 (cleanup: unnecessary clone during lower generics args)
 - #124229 (Add gnullvm targets to manifest)
 - #124231 (remove from reviewers)
 - #124235 (Move some tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-21 21:08:03 +00:00
Matthias Krüger
cd92422180
Rollup merge of #124224 - bvanjoi:cleanup, r=fmease
cleanup: unnecessary clone during lower generics args
2024-04-21 21:56:32 +02:00
Matthias Krüger
67872e740e
Rollup merge of #123840 - scottmcm:aggregate-kind-rawptr, r=cjgillot
Add an intrinsic for `ptr::from_raw_parts(_mut)`

Fixes #123174
cc `@CAD97` `@saethlin`
r? `@cjgillot`

As suggested in https://github.com/rust-lang/rust/pull/123190#issuecomment-2028717967, this adds a new `AggregateKind::RawPtr` for creating a pointer from its data pointer and its metadata.

That means that `slice::from_raw_parts` and friends no longer need to hard-code pointer layout into `libcore`, and because it no longer does union hacks the MIR is shorter and more amenable to optimizations.
2024-04-21 21:56:32 +02:00
bors
1b3fba066c Auto merge of #124203 - lukas-code:delete-deleting-caches, r=compiler-errors
fix normalizing in different `ParamEnv`s with the same `InferCtxt`

This PR changes the key of the projection cache from just `AliasTy` to `(AliasTy, ParamEnv)` to allow normalizing in different `ParamEnv`s without resetting caches. Previously, normalizing the same alias in different param envs would always reuse the cached result from the first normalization, which is incorrect if the projection clauses in the param env have changed.

Fixing this bug allows us to get rid of `InferCtxt::clear_caches`, which was only used by the `AutoTraitFinder`, because it requires normalizing in different param envs.

r? `@fmease`
2024-04-21 19:05:08 +00:00
Scott McMurray
1398fe7a5e Address more PR feedback 2024-04-21 11:08:38 -07:00
Scott McMurray
bb8d6f790b Address PR feedback 2024-04-21 11:08:37 -07:00
Scott McMurray
5e1d16ca55 Also handle AggregateKind::RawPtr in cg_cranelift 2024-04-21 11:08:37 -07:00
Scott McMurray
9520cebfc5 InstSimplify from_raw_parts(p, ())p as _ 2024-04-21 11:08:37 -07:00
Scott McMurray
de64ff76f8 Use it in the library, and InstSimplify it away in the easy places 2024-04-21 11:08:37 -07:00
Scott McMurray
4f4442655e Add an intrinsic that lowers to AggregateKind::RawPtr 2024-04-21 11:08:37 -07:00
Scott McMurray
e6b2b764ec Add AggregateKind::RawPtr and enough support to compile 2024-04-21 11:08:37 -07:00
bors
f22a0c2d9f Auto merge of #123594 - Urgau:fix-non_local_def-lint-overflow, r=lcnr
Fix trait solver overflow with `non_local_definitions` lint

This PR fixes the trait solver overflow with the `non_local_definitions` lint reported in https://github.com/rust-lang/rust/issues/123573 using the suggestion from `@lcnr:` https://github.com/rust-lang/rust/issues/123573#issuecomment-2041348320 to use the next trait solver.

~~I have not (yet) tried to create a minimized repro~~ ``@compiler-errors`` did the minimization (thanks you) but I have manually tested on the `starlark-rust` project that it fixes the issue.

Fixes #123573
r? `@lcnr`
2024-04-21 17:02:03 +00:00
Lukas Markeffsky
5a2b335e49 also remap RPITITs nested in other types back to their opaques 2024-04-21 18:04:50 +02:00
bohan
2d5a226f8f cleanup: unnecessary clone during lower generics args 2024-04-21 20:40:44 +08:00
Guillaume Gomez
43d5e00bac
Rollup merge of #124198 - compiler-errors:improve-ty-ct-param-span, r=Nadrieril
Flip spans for precise capturing syntax not capturing a ty/const param, and for implicit captures of lifetime params

Make the primary span point to the opaque, rather than the param which might be very far away (e.g. in an impl header hundreds of lines above).
2024-04-21 13:30:26 +02:00
Ralf Jung
875f0c2da0 Miri: detect wrong vtables in wide pointers 2024-04-21 13:04:51 +02:00
beetrees
71f751d139
Fix ICE when there is a non-Unicode entry in the incremental crate directory 2024-04-21 11:24:55 +01:00
bors
b9be3c47e5 Auto merge of #117457 - daxpedda:wasm-nontrapping-fptoint, r=wesleywiser
Stabilize Wasm target features that are in phase 4 and 5

This stabilizes the Wasm target features that are known to be working and in [phase 4 and 5](04fa8c810e).

Feature stabilized:
- [Non-trapping float-to-int conversions](https://github.com/WebAssembly/nontrapping-float-to-int-conversions)
- [Import/Export of Mutable Globals](https://github.com/WebAssembly/mutable-global)
- [Sign-extension operators](https://github.com/WebAssembly/sign-extension-ops)
- [Bulk memory operations](https://github.com/WebAssembly/bulk-memory-operations)
- [Extended Constant Expressions](https://github.com/WebAssembly/extended-const)

Features not stabilized:
- [Multi-value](https://github.com/WebAssembly/multi-value): requires rebuilding `std` #73755.
- [Reference Types](https://github.com/WebAssembly/reference-types): no point stabilizing without #103516.
- [Threads](https://github.com/webassembly/threads): requires rebuilding `std` #77839.
- [Relaxed SIMD](https://github.com/WebAssembly/relaxed-simd): separate PR #117468.
- [Multi Memory](https://github.com/WebAssembly/multi-memory): not implemented.

See https://github.com/rust-lang/rust/pull/117457#issuecomment-1787648070 for more context.

Documentation: https://github.com/rust-lang/reference/pull/1420
Tracking issue: https://github.com/rust-lang/rust/issues/44839
2024-04-21 06:32:10 +00:00
许杰友 Jieyou Xu (Joe)
b3f9117a2d
Rollup merge of #124191 - dtolnay:fixup, r=compiler-errors
Give a name to each distinct manipulation of pretty-printer FixupContext

There are only 7 distinct ways that the AST pretty-printer interacts with FixupContext: 3 constructors (including Default), 2 transformations, and 2 queries.

This PR turns these into associated functions which can be documented with examples.

This PR unblocks https://github.com/rust-lang/rust/pull/119427#discussion_r1439481201. In order to improve the pretty-printer's behavior regarding parenthesization of braced macro calls in match arms, which have different grammar than macro calls in statements, FixupContext needs to be extended with 2 new fields. In the previous approach, that would be onerous. In the new approach, all it entails is 1 new constructor (`FixupContext::new_match_arm()`).
2024-04-20 21:45:38 +01:00
许杰友 Jieyou Xu (Joe)
726361caf4
Rollup merge of #124132 - RalfJung:OpBundlesIndirect, r=Mark-Simulacrum
llvm RustWrapper: explain OpBundlesIndirect argument type

Follow-up to https://github.com/rust-lang/rust/pull/123941

r? ``@Mark-Simulacrum``
2024-04-20 21:45:37 +01:00
许杰友 Jieyou Xu (Joe)
ccd9880769
Rollup merge of #123967 - RalfJung:static_mut_refs, r=Nilstrieb
static_mut_refs: use raw pointers to remove the remaining FIXME

Using `SyncUnsafeCell` would not make a lot of sense IMO.
2024-04-20 21:45:35 +01:00