Commit Graph

23007 Commits

Author SHA1 Message Date
bors
9bdb4881c7 Auto merge of #109119 - lcnr:trait-system-cleanup, r=compiler-errors
a general type system cleanup

removes the helper functions `traits::fully_solve_X` as they add more complexity then they are worth. It's confusing which of these helpers should be used in which context.

changes the way we deal with overflow to always add depth in `evaluate_predicates_recursively`. It may make sense to actually fully transition to not have `recursion_depth` on obligations but that's probably a bit too much for this PR.

also removes some other small - and imo unnecessary - helpers.

r? types
2023-03-22 05:33:18 +00:00
bors
5fa73a75ce Auto merge of #109087 - cjgillot:sparse-bb-clear, r=davidtwco
Only clear written-to locals in ConstProp

This aims to revert the regression in https://github.com/rust-lang/rust/pull/108872

Clearing all locals at the end of each bb is very costly.
This PR goes back to the original implementation of recording which locals are modified.
2023-03-22 02:49:04 +00:00
bors
1db9c061d3 Auto merge of #109453 - matthiaskrgr:rollup-odn02wu, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #96391 (Windows: make `Command` prefer non-verbatim paths)
 - #108164 (Drop all messages in bounded channel when destroying the last receiver)
 - #108729 (fix: modify the condition that `resolve_imports` stops)
 - #109336 (Constrain const vars to error if const types are mismatched)
 - #109403 (Avoid ICE of attempt to add with overflow in emitter)
 - #109415 (Refactor `handle_missing_lit`.)
 - #109441 (Only implement Fn* traits for extern "Rust" safe function pointers and items)
 - #109446 (Do not suggest bounds restrictions for synthesized RPITITs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-21 20:56:38 +00:00
Matthias Krüger
94d2028abd
Rollup merge of #109446 - spastorino:new-rpitit-17, r=compiler-errors
Do not suggest bounds restrictions for synthesized RPITITs

Before this PR we were getting ...

```
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
 --> tests/ui/async-await/in-trait/missing-send-bound.rs:5:12
  |
5 | #![feature(async_fn_in_trait)]
  |            ^^^^^^^^^^^^^^^^^
  |
  = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
  = note: `#[warn(incomplete_features)]` on by default

error: future cannot be sent between threads safely
  --> tests/ui/async-await/in-trait/missing-send-bound.rs:17:20
   |
17 |     assert_is_send(test::<T>());
   |                    ^^^^^^^^^^^ future returned by `test` is not `Send`
   |
   = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `impl Future<Output = ()>`
note: future is not `Send` as it awaits another future which is not `Send`
  --> tests/ui/async-await/in-trait/missing-send-bound.rs:13:5
   |
13 |     T::bar().await;
   |     ^^^^^^^^ await occurs here on type `impl Future<Output = ()>`, which is not `Send`
note: required by a bound in `assert_is_send`
  --> tests/ui/async-await/in-trait/missing-send-bound.rs:21:27
   |
21 | fn assert_is_send(_: impl Send) {}
   |                           ^^^^ required by this bound in `assert_is_send`
help: consider further restricting the associated type
   |
16 | fn test2<T: Foo>() where impl Future<Output = ()>: Send {
   |                    ++++++++++++++++++++++++++++++++++++

error: aborting due to previous error; 1 warning emitted
```

and we want this output ...

```
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
  --> $DIR/missing-send-bound.rs:5:12
   |
LL | #![feature(async_fn_in_trait)]
   |            ^^^^^^^^^^^^^^^^^
   |
   = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
   = note: `#[warn(incomplete_features)]` on by default

error: future cannot be sent between threads safely
  --> $DIR/missing-send-bound.rs:17:20
   |
LL |     assert_is_send(test::<T>());
   |                    ^^^^^^^^^^^ future returned by `test` is not `Send`
   |
   = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `impl Future<Output = ()>`
note: future is not `Send` as it awaits another future which is not `Send`
  --> $DIR/missing-send-bound.rs:13:5
   |
LL |     T::bar().await;
   |     ^^^^^^^^ await occurs here on type `impl Future<Output = ()>`, which is not `Send`
note: required by a bound in `assert_is_send`
  --> $DIR/missing-send-bound.rs:21:27
   |
LL | fn assert_is_send(_: impl Send) {}
   |                           ^^^^ required by this bound in `assert_is_send`

error: aborting due to previous error; 1 warning emitted
```

r? `@compiler-errors`
2023-03-21 19:00:15 +01:00
Matthias Krüger
fef1fc4349
Rollup merge of #109441 - oli-obk:fn_trait_new_solver, r=compiler-errors
Only implement Fn* traits for extern "Rust" safe function pointers and items

Since calling the function via an `Fn` trait will assume `extern "Rust"` ABI and not do any safety checks, only safe `extern "Rust"` function can implement the `Fn` traits. This syncs the logic between the old solver and the new solver.

r? `@compiler-errors`
2023-03-21 19:00:14 +01:00
Matthias Krüger
96f35ed720
Rollup merge of #109415 - nnethercote:refactor-handle_missing_lit, r=petrochenkov
Refactor `handle_missing_lit`.

A small code readability improvement.

r? ```@petrochenkov```
2023-03-21 19:00:14 +01:00
Matthias Krüger
25b062d586
Rollup merge of #109403 - chenyukang:yukang/fix-109396, r=estebank
Avoid ICE of attempt to add with overflow in emitter

Fixes #109396
r? ```@estebank```
2023-03-21 19:00:13 +01:00
Matthias Krüger
081c607b0a
Rollup merge of #109336 - compiler-errors:constrain-to-ct-err, r=BoxyUwU
Constrain const vars to error if const types are mismatched

When equating two consts of different types, if either are const variables, constrain them to the correct const error kind.

This helps us avoid "successfully" matching a const against an impl signature but leaving unconstrained const vars, which will lead to incremental ICEs when we call const-eval queries during const projection.

Fixes #109296

The second commit in the stack fixes a regression in the first commit where we end up mentioning `[const error]` in an impl overlap error message. I think the error message changes for the better, but I could implement alternative strategies to avoid this without delaying the overlap error message...

r? `@BoxyUwU`
2023-03-21 19:00:12 +01:00
Matthias Krüger
ee330a3ff5
Rollup merge of #108729 - bvanjoi:fix-issue-97534, r=petrochenkov
fix: modify the condition that `resolve_imports` stops

close #97534
2023-03-21 19:00:12 +01:00
Santiago Pastorino
3b04ad2753
Do not suggest bounds restrictions for synthesized RPITITs 2023-03-21 13:18:32 -03:00
Michael Goulet
b1a957b0b9 query_keys_local is conditional on separate_provide_if_extern 2023-03-21 15:38:52 +00:00
Michael Goulet
d213114cb5 LocalCrate key 2023-03-21 15:38:52 +00:00
Michael Goulet
dcaf956de0 AsLocalKey trait 2023-03-21 15:38:52 +00:00
Michael Goulet
7e6506764b IdentitySubsts::identity_for_item takes Into<DefId> 2023-03-21 15:38:52 +00:00
Michael Goulet
979ef5981f Use LocalDefId in ItemCtxt 2023-03-21 15:38:52 +00:00
Michael Goulet
2eb1c08e43 Use local key in providers 2023-03-21 15:38:51 +00:00
nils
925fbcdf8a
Rollup merge of #109408 - RalfJung:retags, r=compiler-errors
not *all* retags might be explicit in Runtime MIR

In https://github.com/rust-lang/rust/pull/105317 I made Miri treat `Rvalue::Ref/AddrOf` as implicit retagging sites. This updates the MIR docs accordingly.

For `Rvalue::Ref` I think this makes a lot more sense: creating a new reference is their entire point, so we can avoid bloating the MIR with retags. Also this seems to be the best way to handle cases like `*ptr = &[mut] ...`, where doing a retag is somewhat questionable since maybe `*ptr` points to another place now?

For `Rvalue::AddrOf`, Stacked Borrows needs this because even raw ptrs need some retagging, but Tree Borrows doesn't do ant retagging here and I hope we'll end up with a model where raw pointers don't get retagged.
2023-03-21 13:00:25 +01:00
nils
b2e48edded
Rollup merge of #109390 - cbeuw:aggregate-lit, r=oli-obk
Custom MIR: Support aggregate expressions

Add support for tuple, array and ADT expressions in custom mir

r? `````@oli-obk````` or `````@tmiasko````` or `````@JakobDegen`````
2023-03-21 13:00:25 +01:00
nils
c0adce567e
Rollup merge of #109385 - lcnr:typo, r=Dylan-DPC
fix typo
2023-03-21 13:00:24 +01:00
nils
66ba60a445
Rollup merge of #109240 - compiler-errors:dont-binder-twice, r=oli-obk
Walk un-shifted nested `impl Trait` in trait when setting up default trait method assumptions

Fixes a double subtraction in some binder math in return-position `impl Trait` in trait handling code.

Fixes #109239
2023-03-21 13:00:23 +01:00
nils
e79b182fca
Rollup merge of #108896 - BoxyUwU:new_solver_add_goal_fn, r=lcnr
new solver: make all goal evaluation able to be automatically rerun

It is generally wrong to call `evaluate_goal` multiple times or `evaluate_goal` and `evaluate_all` for the same `QueryResult` without correctly handling rerunning the goals when inference makes progress. Not doing so will result in the assertion in `evaluate_goal` firing because rerunning the goal will lead to a more accurate `QueryResult`.

Currently there are lots of places that get this wrong and generally it is complex and error prone to handle correctly everywhere. This PR introduces a way to add goals to the `EvalCtxt` and then run all the added goals in a loop so that `evaluate_goal`/`evaluate_all` is not necessary to call manually.

There are a few complications for making everything work "right":
1. the `normalizes-to` hack that replaces the rhs with an unconstrained infer var requires special casing in the new `try_evaluate_added_goals` function similar to how `evaluate_goal`'s assertion special cases that hack.

2. `assemble_candidates_after_normalizing_self_ty`'s normalization step needs to be reran for each candidate otherwise the found candidates will potentially get a more accurate `QueryResult` when rerunning the projection/trait goal which can effect the `QueryResult` of the projection/trait goal.
This is implemented via `EvalCtxt::probe`'s closure's `EvalCtxt` inheriting the added goals of the `EvalCtxt` that `probe` is called on, allowing us to add goals in a probe, and then enter a nested probe for each candidate and evaluate added goals which include the normalization step's goals.

I made `make_canonical_response` evaluate added goals so that it will be hard to mess up the impl of the solver by forgetting to evaluate added goals. Right now the only way to mess this up would be to call `response_no_constraints` (which from the name is obviously weird).

The visibility of `evaluate_goal` means that it can be called from various `compute_x_goal` or candidate assembly functions, this is generally wrong and we should never call `evaluate_goal` manually, instead we should be calling `add_goal`/`add_goals`. This is solved by moving `evaluate_goal` `evaluate_canonical_goal` and `compute_goal` into `eval_ctxt`'s module and making them private so they cannot be called from elsewhere, forcing people to call `add_goal/s` and `evaluate_added_goals_and_make_canonical_resposne`/`try_evaluate_added_goals`

---

Other changes:
- removed the `&& false` that was introduced to the assertion in `evaluate_goal` in #108839
- remove a `!self.did_overflow()` requirement in `search_graph.is_empty()` which causes goals that overflow to ICE
- made `EvalCtxt::eq` take `&mut self` and add all the nested goals via `add_goals` instead of returning them as 99% of call sites just immediately called `EvalCtxt::add_goals` manually.

r? `````@lcnr`````
2023-03-21 13:00:22 +01:00
nils
0ef4da126a
Rollup merge of #108842 - compiler-errors:non_lifetime_binders-object-safe, r=b-naber
Enforce non-lifetime-binders in supertrait preds are not object safe

We can't construct vtables for these supertraits.
2023-03-21 13:00:22 +01:00
Oli Scherer
a00413f680 Also check function items' signatures for Fn* trait compatibility 2023-03-21 11:50:14 +00:00
Oli Scherer
91d913168c Deduplicate fn trait compatibility checks 2023-03-21 11:38:13 +00:00
Oli Scherer
fb9e171ab7 Only implement Fn* traits for extern "Rust" safe function pointers. 2023-03-21 11:11:32 +00:00
lcnr
b8541eb767 use the correct param env 2023-03-21 09:57:22 +01:00
lcnr
c63861b9d5 evaluate: improve and fix recursion depth handling 2023-03-21 09:57:22 +01:00
lcnr
791ce0b7b5 remove some trait solver helpers
they add more complexity then they are worth. It's confusing
which of these helpers should be used in which context.
2023-03-21 09:57:20 +01:00
bors
822c10feb7 Auto merge of #109046 - Zoxc:split-execute-job, r=cjgillot,michaelwoerister
Split `execute_job` into `execute_job_incr` and `execute_job_non_incr`

`execute_job` was a bit large, so this splits it in 2. Performance was neutral locally, but this may affect bootstrap times.
2023-03-20 23:53:09 +00:00
Michael Goulet
720cc40fa7 Enforce non-lifetime-binders in supertrait preds are not object safe 2023-03-20 22:38:57 +00:00
Nicholas Nethercote
93eeb12724 Refactor handle_missing_lit. 2023-03-21 09:28:52 +11:00
bors
44f5180584 Auto merge of #106610 - euclio:windows-rs, r=ChrisDenton
migrate compiler, bootstrap and compiletest to windows-rs

This PR migrates the compiler, bootstrap, and compiletest to use [windows-rs](https://github.com/microsoft/windows-rs) instead of winapi-rs. windows-rs is the bindings crate provided by Microsoft, and is actively maintained compared to winapi-rs. Not all ecosystem crates have migrated over yet, so there will be a period of time where both crates are used.

windows-rs also provides some nice ergonomics over winapi-rs to convert return values to `Result`s (which found a case where we forgot to check the return value of `CreateFileW`).
2023-03-20 20:05:45 +00:00
Ralf Jung
5058cc8e62 not *all* retags might be explicit in Runtime MIR 2023-03-20 19:36:01 +01:00
bors
febd59e122 Auto merge of #109384 - matthiaskrgr:rollup-hu348gs, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #109170 (Set `CMAKE_SYSTEM_NAME` for Linux targets)
 - #109266 (rustdoc: Correctly merge import's and its target's docs in one more case)
 - #109267 (Add tests for configure.py)
 - #109273 (Make `slice::is_sorted_by` implementation nicer)
 - #109277 (Fix generics_of for impl's RPITIT synthesized associated type)
 - #109307 (Ignore `Inlined` spans when computing caller location.)
 - #109364 (Only expect a GAT const param for `type_of` of GAT const arg)
 - #109365 (Update mdbook)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-20 17:33:20 +00:00
yukang
cbb8066321 Avoid ICE of attempt to add with overflow in emitter 2023-03-21 01:23:28 +08:00
Andy Russell
bb7c373fdf
migrate compiler, bootstrap, and compiletest to windows-rs 2023-03-20 13:19:35 -04:00
Andy Wang
f404f33c21
Use builtin_index instead of match
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2023-03-20 16:27:44 +01:00
Andy Wang
e24f5ac56b
Fix off-by-one in mir syntax doc 2023-03-20 15:27:40 +01:00
Andy Wang
8e4e55e524
Support aggregate expressions 2023-03-20 15:25:11 +01:00
bors
13b7aa4d7f Auto merge of #108524 - Zoxc:node-backtrace, r=cjgillot
Optimize dep node backtrace and ignore fatal errors

This attempts to optimize https://github.com/rust-lang/rust/pull/91742 while also passing through fatal errors.

r? `@cjgillot`
2023-03-20 11:54:00 +00:00
lcnr
5b4fa5bf98 fix typo 2023-03-20 10:46:43 +01:00
Matthias Krüger
f21c435801
Rollup merge of #109364 - compiler-errors:gat-const-arg, r=BoxyUwU
Only expect a GAT const param for `type_of` of GAT const arg

IDK why we were account for both `is_ty_or_const` instead of just for a const param, since we're computing the `type_of` a const param specifically.

Fixes #109300
2023-03-20 09:46:54 +01:00
Matthias Krüger
3efecba6e7
Rollup merge of #109307 - cjgillot:inline-location, r=compiler-errors
Ignore `Inlined` spans when computing caller location.

Fixes https://github.com/rust-lang/rust/issues/105538
2023-03-20 09:46:54 +01:00
Matthias Krüger
d86fd83ef6
Rollup merge of #109277 - spastorino:new-rpitit-14, r=compiler-errors
Fix generics_of for impl's RPITIT synthesized associated type

The only useful commit is the last one.

This makes `generics_of` for the impl side RPITIT copy from the trait's associated type and avoid the fn on the impl side which was previously wrongly used.
This solution is better but we still need to fix resolution of the generated generics.

r? ``@compiler-errors``
2023-03-20 09:46:53 +01:00
Matthias Krüger
eb1f8dc2cb
Rollup merge of #109370 - DaniPopes:issue-109334, r=Nilstrieb
fix ClashingExternDeclarations lint ICE

Fixes #109334

First "real" contribution, please let me know if I did something wrong.

As I understand it, it's OK if a `#[repr(transparent)]` type has no non-zero sized types (aka is a ZST itself) and the function should just return the type normally instead of panicking

r? `@Nilstrieb`
2023-03-20 07:10:34 +01:00
Matthias Krüger
cd9fadea5b
Rollup merge of #109362 - nnethercote:split-meta-stats-items, r=bjorn3
Split `items` from `-Zmeta-stats` in two.

Because it's one of the biggest sections.

r? `@bjorn3`
2023-03-20 07:10:34 +01:00
Matthias Krüger
5d3f460708
Rollup merge of #109301 - Ezrashaw:fix-ctf-ice, r=Nilstrieb
fix: fix ICE in `custom-test-frameworks` feature

Fixes #107454

Simple fix to emit error instead of ICEing. At some point, all the code in `tests.rs` should be refactored, there is a bit of duplication (this PR's code is repeated five times over lol).

r? `@Nilstrieb` (active on the linked issue?)
2023-03-20 07:10:31 +01:00
Matthias Krüger
ede3c39fe6
Rollup merge of #109249 - compiler-errors:new-rpitit-comments, r=spastorino
Update names/comments for new return-position impl trait in trait lowering strategy

r? `@spastorino`

totally cosmetic
2023-03-20 07:10:30 +01:00
Michael Goulet
4fd66d70cb Update some names and comments 2023-03-20 04:51:53 +00:00
Michael Goulet
239ec6cb11 drive-by: Fix a comment in TyCtxt::fold_regions and remove an unused method 2023-03-20 04:50:07 +00:00