Commit Graph

3205 Commits

Author SHA1 Message Date
Michael Goulet ee9727e263 Don't suggest dereferencing to unsized type 2023-09-07 04:52:00 +00:00
bors aeddd2ddfd Auto merge of #115529 - chenyukang:yukang-fix-115402-overflowsize, r=compiler-errors
Fix error report for size overflow from transmute

Fixes #115402

The span in the error reporting always points to the `dst`, this is an old issue, I may open another PR to fix it.
2023-09-06 02:37:41 +00:00
yukang 00010eda8b Fix error report for size overflow from transmute 2023-09-06 06:48:34 +08:00
lcnr 98fa0c93ee unconstrained region vars: do not ICE ICE baby 2023-09-05 11:15:05 +02:00
Matthias Krüger f5e6aa3c4a
Rollup merge of #115519 - compiler-errors:next-solver-assoc-ice, r=lcnr
Don't ICE on associated type projection without feature gate in new solver

Self-explanatory, we should avoid ICEs when the feature gate is not enabled. Continue to ICE when the feature gate *is* enabled, though.

Fixes #115500
2023-09-05 07:15:16 +02:00
bors 9c609ae158 Auto merge of #115467 - compiler-errors:assoc-ty-object-safety, r=oli-obk
Do not require associated types with Self: Sized to uphold bounds when confirming object candidate

RPITITs and associated types that have `Self: Sized` bounds are opted out of the `dyn Trait` well-formedness check that happens during confirmation. This ensures that we can actually *use* `dyn Trait`s that have associated types that, e.g., have GATs and RPITITs and other naughty things as long as those are opted-out of object safety via a `Self: Sized` bound.

Fixes #115464

This seems like a natural part of https://github.com/rust-lang/rust/pull/112319#issuecomment-1592574451, and I don't think needs re-litigation.

r? `@oli-obk`
2023-09-05 01:09:48 +00:00
Michael Goulet 8c667febbd Don't ICE on associated type projection without feature gate 2023-09-03 19:43:58 +00:00
Michael Goulet 07fc644132 Do not require associated types with Self: Sized to uphold bounds when confirming object candidate 2023-09-02 05:08:38 +00:00
Michael Goulet 7a6b52bf0d RPITITs are considered object-safe, they're always on Self:Sized methods 2023-09-02 04:58:23 +00:00
cui fliter 42e550781c Signed-off-by: cui fliter <imcusg@gmail.com>
remove the repetitive word

Signed-off-by: cui fliter <imcusg@gmail.com>
2023-09-02 07:40:44 +08:00
bors 96f62fce00 Auto merge of #113201 - oli-obk:recursive_type_alias, r=estebank,compiler-errors
Permit recursive weak type aliases

I saw #63097 and thought "we can do ~~better~~ funnier". So here it is. It's not useful, but it's certainly something. This may actually become feasible with lazy norm (so in 5 years (constant, not reducing over time)).

r? `@estebank`

cc `@GuillaumeGomez`
2023-09-01 07:10:21 +00:00
Matthias Krüger 0b62835043
Rollup merge of #115373 - lqd:come-on-bors, r=compiler-errors
Fix bors missing a commit when merging #115355

bors incorrectly merged an outdated version of PR #115355 (via rollup #115370):
- it [recorded r+](https://github.com/rust-lang/rust/pull/115355#issuecomment-1698372365) as approving commit 325b585259, and thus merged the original revision 7762ac7bb5
- but the branch at the time was at commit eefa07d69b, so bors missed the `compiler/rustc_trait_selection/src/solve/search_graph/mod.rs` cleanup in commit 0e1e964a34 😓

Thankfully the change that bors missed was small, and this new PR corrects the situation (as I'd rather avoid having confusing multiple merge commits of PR #115355 in the git history)

r? ``@compiler-errors``
2023-08-31 07:52:43 +02:00
Michael Goulet 4647aea7aa Don't record spans for predicates in coherence 2023-08-30 18:24:18 +00:00
Oli Scherer 5d850e0f50 Permit recursive weak type aliases 2023-08-30 11:55:03 +00:00
Rémy Rakic 72725529e1 clean up `local_overflow_limit` computation
fixes bors snafu where it merged an outdated commit and missed this
change
2023-08-30 09:43:36 +00:00
Rémy Rakic 7762ac7bb5 handle edge-case of a recursion limit of 0 2023-08-29 19:02:24 +00:00
bors 4e78abb437 Auto merge of #115326 - matthiaskrgr:rollup-qsoa8ar, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #115164 (MIR validation: reject in-place argument/return for packed fields)
 - #115240 (codegen_llvm/llvm_type: avoid matching on the Rust type)
 - #115294 (More precisely detect cycle errors from type_of on opaque)
 - #115310 (Document panic behavior across editions, and improve xrefs)
 - #115311 (Revert "Suggest using `Arc` on `!Send`/`!Sync` types")
 - #115317 (Devacationize oli-obk)
 - #115319 (don't use SnapshotVec in Graph implementation, as it looks unused; use Vec instead)
 - #115322 (Tweak output of `to_pretty_impl_header` involving only anon lifetimes)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-28 19:57:32 +00:00
Matthias Krüger 07a32e2dbd
Rollup merge of #115322 - estebank:list-tweak, r=compiler-errors
Tweak output of `to_pretty_impl_header` involving only anon lifetimes

Do not print `impl<> Foo for &Bar`.
2023-08-28 19:53:59 +02:00
Matthias Krüger 9b0abe3537
Rollup merge of #115311 - dtolnay:usearcself, r=compiler-errors
Revert "Suggest using `Arc` on `!Send`/`!Sync` types"

Closes https://github.com/rust-lang/rust/issues/114687. This is a clean revert of https://github.com/rust-lang/rust/pull/88936 + https://github.com/rust-lang/rust/pull/115210. The suggestion to Arc\<{Self}\> when Self does not implement Send is *always* wrong.

https://github.com/rust-lang/rust/pull/114842 is considering a way to make a more refined suggestion.
2023-08-28 19:53:57 +02:00
Matthias Krüger b4c63f06e8
Rollup merge of #115294 - compiler-errors:cycle-err, r=oli-obk
More precisely detect cycle errors from type_of on opaque

Not sure if this still needs work. Just putting it up for initial impressions, since it seems that a few people are frustrated with the increased error verbosity due to #113320.

Essentially we introduce a new sub-query for `type_of` specifically for opaques which returns a value that is able to distinguish "has errors" from "due to cycle recovery".

Fixes #115188

r? `@oli-obk`
2023-08-28 19:53:56 +02:00
Esteban Küber ecf2f68e45 Tweak output of `to_pretty_impl_header` involving only anon lifetimes
Do not print `impl<> Foo for &Bar`.
2023-08-28 17:17:11 +00:00
David Tolnay 823bacb6e3
Revert "Suggest using `Arc` on `!Send`/`!Sync` types"
This reverts commit 9de1a472b6.
2023-08-28 03:16:48 -07:00
Michael Goulet f8e0dcbf56 Better error message for object type with GAT 2023-08-28 01:05:34 +00:00
Michael Goulet bf53598828 More precisely detect cycle errors from type_of on opaque 2023-08-27 22:03:16 +00:00
Guillaume Gomez 8dfbc76f34
Rollup merge of #114974 - nbdd0121:vtable, r=b-naber
Add an (perma-)unstable option to disable vtable vptr

This flag is intended for evaluation of trait upcasting space cost for embedded use cases.

Compared to the approach in #112355, this option provides a way to evaluate end-to-end cost of trait upcasting. Rationale: https://github.com/rust-lang/rust/issues/112355#issuecomment-1658207769

## How this flag should be used (after merge)

Build your project with and without `-Zno-trait-vptr` flag. If you are using cargo, set `RUSTFLAGS="-Zno-trait-vptr"` in the environment variable. You probably also want to use `-Zbuild-std` or the binary built may be broken. Save both binaries somewhere.

### Evaluate the space cost

The option has a direct and indirect impact on vtable space usage. Directly, it gets rid of the trait vptr entry needed to store a pointer to a vtable of a supertrait. (IMO) this is a small saving usually. The larger saving usually comes with the indirect saving by eliminating the vtable of the supertrait (and its parent).

Both impacts only affects vtables (notably the number of functions monomorphized should , however where vtable reside can depend on your relocation model. If the relocation model is static, then vtable is rodata (usually stored in Flash/ROM together with text in embedded scenario). If the binary is relocatable, however, the vtable will live in `.data` (more specifically, `.data.rel.ro`), and this will need to reside in RAM (which may be a more scarce resource in some cases), together with dynamic relocation info living in readonly segment.

For evaluation, you should run `size` on both binaries, with and without the flag. `size` would output three columns, `text`, `data`, `bss` and the sum `dec` (and it's hex version). As explained above, both `text` and `data` may change. `bss` shouldn't usually change. It'll be useful to see:
* Percentage change in text + data (indicating required flash/ROM size)
* Percentage change in data + bss (indicating required RAM size)
2023-08-27 20:12:47 +02:00
lcnr 11716830ac instantiate response: no unnecessary new universe
this previously was a off-by-one error.
2023-08-18 23:55:28 +02:00
Gary Guo a7633b8a71 Add an (perma-)unstable option to disable vtable vptr
This flag is intended for evaluation of trait upcasting
space cost for embedded use cases.
2023-08-18 17:44:04 +01:00
bors a1e1dba9cc Auto merge of #114611 - nnethercote:type-system-chess, r=compiler-errors
Speed up compilation of `type-system-chess`

[`type-system-chess`](https://github.com/rust-lang/rustc-perf/pull/1680) is an unusual program that implements a compile-time chess position solver in the trait system(!)  This PR is about making it compile faster.

r? `@ghost`
2023-08-18 06:29:38 +00:00
Matthias Krüger 8db5a6d8ee
Rollup merge of #114819 - estebank:issue-78124, r=compiler-errors
Point at return type when it influences non-first `match` arm

When encountering code like

```rust
fn foo() -> i32 {
    match 0 {
        1 => return 0,
        2 => "",
        _ => 1,
    }
}
```

Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`.

Fix #78124.
2023-08-15 20:34:25 +02:00
Guillaume Gomez 31a41310ee
Rollup merge of #114831 - compiler-errors:next-solver-projection-subst-compat, r=lcnr
Check projection args before substitution in new solver

Don't ICE when an impl has the wrong kind of GAT arguments

r? lcnr
2023-08-15 14:29:50 +02:00
Guillaume Gomez da4e7bd0cd
Rollup merge of #114829 - compiler-errors:next-solver-only-unsize-to-dyn-once, r=lcnr
Separate `consider_unsize_to_dyn_candidate` from other unsize candidates

Move the unsize candidate assembly *just for* `T -> dyn Trait` out of `assemble_candidates_via_self_ty` so that we only consider it once, instead of for every normalization step of the self ty. This makes sure that we don't assemble several candidates that are equal modulo normalization when we really don't care about normalizing the self type of an `T: Unsize<dyn Trait>` goal anyways.

Fixes rust-lang/trait-system-refactor-initiative#57

r? lcnr
2023-08-15 14:29:49 +02:00
Guillaume Gomez 47bdda2b45
Rollup merge of #114828 - compiler-errors:next-solver-probe-upcasting, r=lcnr
Probe when assembling upcast candidates so they don't step on eachother's toes in new solver

Lack of a probe causes one candidate to disqualify the other due to inference side-effects.

r? lcnr
2023-08-15 14:29:49 +02:00
Guillaume Gomez e4b9e72e58
Rollup merge of #114827 - compiler-errors:next-solver-dyn-safe-candidates, r=lcnr
Only consider object candidates for object-safe dyn types in new solver

We apparently allow this per RFC2027 💀

r? lcnr
2023-08-15 14:29:48 +02:00
Michael Goulet 0e20155662 more nits 2023-08-15 03:44:21 +00:00
Michael Goulet ca49a37390 Reuse the selection context, compute failing obligations first in ambig mode 2023-08-15 03:40:19 +00:00
Michael Goulet d2a14df70e nits
Co-authored-by: lcnr <rust@lcnr.de>
2023-08-15 03:40:19 +00:00
Michael Goulet 56f5704ff8 Implement lint against coinductive impl overlap 2023-08-15 03:40:19 +00:00
Michael Goulet 2ae4bedd85 more span info 2023-08-15 03:40:19 +00:00
Michael Goulet 77c6c38add Check projection arguments before substitution 2023-08-15 01:03:33 +00:00
Michael Goulet 7d8563c602 Separate consider_unsize_to_dyn_candidate from other unsize candidates 2023-08-15 01:02:43 +00:00
Michael Goulet ab126c2a4e Probe when assembling upcast candidates so they don't step on eachother's toes 2023-08-15 01:02:13 +00:00
Michael Goulet e8ab56fbb4 Only consider object candidates for object-safe dyn types 2023-08-15 01:01:44 +00:00
Esteban Küber 55f8c66a60 Point at return type when it influences non-first `match` arm
When encountering code like

```rust
fn foo() -> i32 {
    match 0 {
        1 => return 0,
        2 => "",
        _ => 1,
    }
}
```

Point at the return type and not at the prior arm, as that arm has type
`!` which isn't influencing the arm corresponding to arm `2`.

Fix #78124.
2023-08-14 21:43:56 +00:00
Deadbeef f441fa08da Remove constness from `ImplSource::Param` 2023-08-14 02:17:30 +00:00
bors 7455aa5395 Auto merge of #114457 - lcnr:trait_ref_is_knowable-normalize, r=compiler-errors
normalize in `trait_ref_is_knowable` in new solver

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/51

Alternatively we could avoid normalizing the self type and do this at the end of the `assemble_candidates_via_self_ty` stack by splitting candidates into:
- applicable without normalizing self type
- applicable for aliases, even if they can be normalized
- applicable for stuff which cannot get normalized further

I don't think this would have any significant benefits and it also seems non-trivial to avoid normalizing only the self type in `trait_ref_is_knowable`.

r? `@compiler-errors`
2023-08-13 05:18:27 +00:00
lcnr 51762886f6 lower `evaluate_goal` stability check to `warn` 2023-08-12 20:37:53 +02:00
lcnr 9eeaf1fd13 normalize in `trait_ref_is_knowable` in new solver 2023-08-12 20:37:53 +02:00
lcnr bb76fde734 remove builtin impl for float and int infer 2023-08-11 19:08:11 +02:00
Michael Goulet 5f906897f6
Rollup merge of #114712 - compiler-errors:comment-nits, r=lcnr
Fix a couple of bad comments

A couple of nits I saw. Sorry, this really should be folded into some other PR of mine, but I will literally forget if I don't put these up now.
2023-08-10 21:17:10 -07:00
Michael Goulet 540afe202f Comment nits 2023-08-10 23:22:03 +00:00
lcnr d558353f28 make the provisional cache slightly less broken 2023-08-10 12:35:34 +02:00
Esteban Kuber 9de1a472b6 Suggest using `Arc` on `!Send`/`!Sync` types 2023-08-09 14:04:10 +00:00
Matthias Krüger 0c2f179901
Rollup merge of #114548 - fee1-dead-contrib:migrate-to-trans, r=davidtwco
Migrate a trait selection error to use diagnostic translation
2023-08-09 06:32:25 +02:00
bors f88a8b71ce Auto merge of #114545 - fee1-dead-contrib:lower-impl-effect, r=oli-obk
correctly lower `impl const` to bind to host effect param

r? `@oli-obk`
2023-08-08 19:23:41 +00:00
Nicholas Nethercote 8378487f27 Only dedup obligation after new ones have been added. 2023-08-08 15:38:20 +10:00
Nicholas Nethercote 3c99b3dbd0 Size the `deduped` set appropriately.
Avoids lots of resizing as the set fills up.
2023-08-08 15:38:20 +10:00
Nicholas Nethercote 1c583c0b91 Simplify the boolean logic in a closure.
And rename a closure argument.
2023-08-08 15:38:20 +10:00
Matthias Krüger 418b91a3d7
Rollup merge of #114594 - compiler-errors:new-solver-resolve-aliases, r=lcnr
Structurally normalize weak and inherent in new solver

It seems pretty obvious to me that we should be normalizing weak and inherent aliases too, since they can always be normalized. This PR still leaves open the question of what to do with opaques, though 💀

**Also**, we need to structurally resolve the target of a coercion, for the UI test to work.

r? `@lcnr`
2023-08-08 03:30:56 +02:00
Matthias Krüger 3cd0a109a8
Rollup merge of #114566 - fmease:type-alias-laziness-is-crate-specific, r=oli-obk
Store the laziness of type aliases in their `DefKind`

Previously, we would treat paths referring to type aliases as *lazy* type aliases if the current crate had lazy type aliases enabled independently of whether the crate which the alias was defined in had the feature enabled or not.

With this PR, the laziness of a type alias depends on the crate it is defined in. This generally makes more sense to me especially if / once lazy type aliases become the default in a new edition and we need to think about *edition interoperability*:

Consider the hypothetical case where the dependency crate has an older edition (and thus eager type aliases), it exports a type alias with bounds & a where-clause (which are void but technically valid), the dependent crate has the latest edition (and thus lazy type aliases) and it uses that type alias. Arguably, the bounds should *not* be checked since at any time, the dependency crate should be allowed to change the bounds at will with a *non*-major version bump & without negatively affecting downstream crates.

As for the reverse case (dependency: lazy type aliases, dependent: eager type aliases), I guess it rules out anything from slight confusion to mild annoyance from upstream crate authors that would be caused by the compiler ignoring the bounds of their type aliases in downstream crates with older editions.

---

This fixes #114468 since before, my assumption that the type alias associated with a given weak projection was lazy (and therefore had its variances computed) did not necessarily hold in cross-crate scenarios (which [I kinda had a hunch about](https://github.com/rust-lang/rust/pull/114253#discussion_r1278608099)) as outlined above. Now it does hold.

`@rustbot` label F-lazy_type_alias
r? `@oli-obk`
2023-08-08 03:30:56 +02:00
Michael Goulet fb9030d7dd Structurally normalize weak and inherent too 2023-08-07 19:05:59 +00:00
Matthias Krüger 2a643b2dc0
Rollup merge of #114196 - compiler-errors:bubble-pls, r=lcnr
Bubble up nested goals from equation in `predicates_for_object_candidate`

This used to be needed for https://github.com/rust-lang/rust/pull/114036#discussion_r1273987510, but since it's no longer, I'm opening this as a separate PR. This also fixes one ICEing UI test: (`tests/ui/unboxed-closures/issue-53448.rs`)

r? `@lcnr`
2023-08-07 16:47:54 +02:00
León Orell Valerian Liehr 5468336d6b
Store the laziness of type aliases in the DefKind 2023-08-07 15:54:31 +02:00
Deadbeef 1ca4bc966e Migrate a trait selection error to use diagnostic translation 2023-08-07 05:26:38 +00:00
Matthias Krüger d804b74c6c
Rollup merge of #114549 - chenyukang:yukang-review-resolve-part, r=petrochenkov
Style fix and refactor on resolve diagnostics

- coding style
- refactor api of `span_look_ahead`
2023-08-07 05:29:13 +02:00
yukang eb0fcc5ad1 refactor on span_look_ahead 2023-08-06 22:44:11 +08:00
Deadbeef 92f4c59e48 lower impl const to bind to host effect param 2023-08-06 13:34:53 +00:00
Michael Goulet 55bf810821 Also report when goals go from ok to error 2023-08-05 20:09:31 +00:00
Michael Goulet c0231962e5
Rollup merge of #114490 - kernelmethod:error-reporting-typos, r=compiler-errors
Fix a typo in the error reporting for sealed traits.

Fixes a typo in error reporting: "implelement" -> "implement"
2023-08-04 19:47:40 -07:00
Michael Goulet 097a49867c
Rollup merge of #114287 - lcnr:overflow, r=compiler-errors
update overflow handling in the new trait solver

implements https://hackmd.io/QY0dfEOgSNWwU4oiGnVRLw?view. I want to clean up this doc and add it to the rustc-dev-guide, but I think this PR is ready for merge as is, even without the dev-guide entry.

r? `@compiler-errors`
2023-08-04 19:47:38 -07:00
kernelmethod d64968ba30 Fix a typo in the error reporting for sealed traits. 2023-08-05 00:38:52 +00:00
Matthias Krüger 99e4127d85
Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions

fixes #114388

Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.

r? compiler-errors
2023-08-04 21:31:57 +02:00
Matthias Krüger 5054e41b64
Rollup merge of #113945 - chenyukang:yukang-fix-113447-slice-2, r=cjgillot
Fix wrong span for trait selection failure error reporting

Fixes #113447
2023-08-04 21:31:55 +02:00
Nilstrieb 5706be1854 Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
2023-08-04 13:17:39 +02:00
bors 4f7bb9890c Auto merge of #114036 - compiler-errors:upcast-to-fewer-assocs, r=lcnr
Rework upcasting confirmation to support upcasting to fewer projections in target bounds

This PR implements a modified trait upcasting algorithm that is resilient to changes in the number of associated types in the bounds of the source and target trait objects.

It does this by equating each bound of the target trait ref individually against the bounds of the source trait ref, rather than doing them all together by constructing a new trait object.

#### The new way we do trait upcasting confirmation

1. Equate the target trait object's principal trait ref with one of the supertraits of the source trait object's principal.
fdcab310b2/compiler/rustc_trait_selection/src/traits/select/mod.rs (L2509-L2525)

2. Make sure that every auto trait in the *target* trait object is present in the source trait ref's bounds.
fdcab310b2/compiler/rustc_trait_selection/src/traits/select/mod.rs (L2559-L2562)

3. For each projection in the *target* trait object, make sure there is exactly one projection that equates with it in the source trait ref's bound. If there is more than one, bail with ambiguity.
fdcab310b2/compiler/rustc_trait_selection/src/traits/select/mod.rs (L2526-L2557)
    * Since there may be more than one that applies, we probe first to check that there is exactly one, then we equate it outside of a probe once we know that it's unique.

4. Make sure the lifetime of the source trait object outlives the lifetime of the target.

<details>
<summary>Meanwhile, this is how we used to do upcasting:</summary>

1. For each supertrait of the source trait object, take that supertrait, append the source object's projection bounds, and the *target* trait object's auto trait bounds, and make this into a new object type:
d12c6e947c/compiler/rustc_trait_selection/src/traits/select/confirmation.rs (L915-L929)

2. Then equate it with the target trait object:
d12c6e947c/compiler/rustc_trait_selection/src/traits/select/confirmation.rs (L936)

This will be a type mismatch if the target trait object has fewer projection bounds, since we compare the bounds structurally in relate:
d12c6e947c/compiler/rustc_middle/src/ty/relate.rs (L696-L698)

</details>

Fixes #114035
Also fixes #114113, because I added a normalize call in the old solver.

r? types
2023-08-04 10:55:22 +00:00
Matthias Krüger d6f714e44f
Rollup merge of #114355 - compiler-errors:resolve_vars_early, r=lcnr
resolve before canonicalization in new solver, ICE if unresolved

Fold the values with a resolver before canonicalization instead of making it happen within canonicalization.

This allows us to filter trivial region constraints from the external constraints.

r? ``@lcnr``
2023-08-04 09:18:59 +02:00
Michael Goulet f848fd3ae3 Remove trivial region constraints 2023-08-03 20:05:40 +00:00
Michael Goulet eaf8af5de8 resolve before canonicalization, ICE if unresolved 2023-08-03 20:05:40 +00:00
Michael Goulet 5bea48ba18 separate calculation and interning of external query constraints 2023-08-03 20:05:40 +00:00
Michael Goulet 7c942ccb0c Don't be incomplete 2023-08-03 18:21:11 +00:00
Michael Goulet 238beae5e5 Fix upcasting with normalization in old solver, add a test 2023-08-03 18:21:11 +00:00
Michael Goulet 4cc659eb3f short-circuit when proj def ids differ 2023-08-03 18:21:11 +00:00
Michael Goulet 1bb6ae5874 Rework upcasting 2023-08-03 18:21:11 +00:00
yukang cde8f06503 enable suggest convert to slice for binary operation 2023-08-04 00:14:13 +08:00
yukang 3635b48973 Fix wrong span for trait selection failure error reporting 2023-08-03 23:47:57 +08:00
lcnr baf076825c inline helper methods into `with_new_goal` 2023-08-03 15:15:48 +02:00
lcnr 8aca388af8 rewrite stack dependent overflow handling 2023-08-03 15:12:43 +02:00
lcnr a745cbb042 handle overflow in the `EvalCtxt` separately 2023-08-03 14:41:44 +02:00
lcnr c0468313cb add `ensure_sufficient_stack` to the new solver 2023-08-03 14:32:56 +02:00
lcnr ae3c353067 fix `make_ambiguous_response_no_constraints`
we previously had incorrect universes in the query response.
2023-08-03 14:30:13 +02:00
lcnr a090b4548d avoid more `ty::Binder:dummy` 2023-08-03 14:16:26 +02:00
lcnr 5992e9b2fe builtin impl confirmation wuhu 2023-08-03 14:08:50 +02:00
Deadbeef 4fec845c3f Remove constness from `TraitPredicate` 2023-08-02 15:38:00 +00:00
Nilstrieb 46f6b05eb7
Rollup merge of #114079 - compiler-errors:closure-upvars, r=oli-obk
Use `upvar_tys` in more places, make it return a list

Just a cleanup that fell out of a PR that I was gonna write, but that PR kinda got stuck.
2023-08-02 13:46:54 +02:00
bors 7a5d2d0138 Auto merge of #114358 - matthiaskrgr:rollup-d810m9e, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #114178 (Account for macros when suggesting a new let binding)
 - #114199 (Don't unsize coerce infer vars in select in new solver)
 - #114301 (Don't check unnecessarily that impl trait is RPIT)
 - #114314 (Tweaks to `adt_sized_constraint`)
 - #114322 (Fix invalid slice coercion suggestion reported in turbofish)
 - #114340 ([rustc_attr][nit] Replace `filter` + `is_some` with `map_or`.)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-02 04:30:51 +00:00
Matthias Krüger 1778c58905
Rollup merge of #114322 - Urgau:fix-issue-110063, r=compiler-errors
Fix invalid slice coercion suggestion reported in turbofish

This PR fixes the invalid slice coercion suggestion reported in turbofish and inferred generics by not emitting them.

Fixes https://github.com/rust-lang/rust/issues/110063
2023-08-02 06:22:49 +02:00
Matthias Krüger 3d29ce7484
Rollup merge of #114314 - compiler-errors:sized-crit, r=lcnr
Tweaks to `adt_sized_constraint`

fixes a comment, but also some other nits.

r? lcnr
2023-08-02 06:22:49 +02:00
bors 90bb4184f8 Auto merge of #114170 - lcnr:add-commmentz, r=compiler-errors
add `dropck_outlives` comments
2023-08-02 02:45:47 +00:00
Michael Goulet 99969d282b Use upvar_tys in more places, make it a list 2023-08-01 23:19:31 +00:00
Michael Goulet d21a335e8f Don't select infer -> dyn Trait 2023-08-01 23:12:03 +00:00
Michael Goulet 8696fa71b3 Convert adt_sized_constraint to early-binder, use list 2023-08-01 23:10:38 +00:00
Urgau a40829498e Rename `maybe_suggest_convert_to_slice` fn name to consistent naming 2023-08-01 12:34:31 +02:00
Urgau 87e8feaf50 Fix invalid slice coercion suggestion reported in turbofish 2023-08-01 12:34:31 +02:00
Matthias Krüger c73e232d20
Rollup merge of #114200 - compiler-errors:detect-tail-unsize-then-upcast, r=lcnr
Detect trait upcasting through struct tail unsizing in new solver select

Oops, we were able to hide trait upcasting behind a parent unsize goal that evaluated to `Certainty::Yes`. Let's do rematching for `Certainty::Yes` unsize goals with `BuiltinImplSource::Misc` sources (corresponding to all of the other unsize rules) to make sure we end up selecting any nested goals which may be satisfied via `BuiltinImplSource::TraitUpcasting` or `::TupleUnsizing`.

r? ``@lcnr``
2023-07-31 22:51:16 +02:00
Matthias Krüger b8f78fb47c
Rollup merge of #114169 - lcnr:unsize, r=compiler-errors
refactor builtin unsize handling, extend comments

r? `@compiler-errors`
2023-07-31 16:57:53 +02:00
Matthias Krüger 3ce90b1649 inline format!() args up to and including rustc_codegen_llvm 2023-07-30 14:22:50 +02:00
Michael Goulet 752e6e13ad Detect trait upcasting through struct tail unsizing 2023-07-29 06:40:36 +00:00
Michael Goulet 57407a3555 Bubble up nested goals from equation in predicates_for_object_candidate 2023-07-29 05:55:03 +00:00
bors 4734ac0943 Auto merge of #111916 - fee1-dead-contrib:noop-method-call-warn, r=compiler-errors
make `noop_method_call` warn by default

r? `@compiler-errors`
2023-07-29 01:40:50 +00:00
León Orell Valerian Liehr 9213aec762
Lower generic const items to HIR 2023-07-28 22:21:40 +02:00
lcnr 84043589a6 dropck_outlives comments 2023-07-28 13:16:36 +02:00
lcnr 17f87c5aff fix comment 2023-07-28 13:00:54 +02:00
lcnr f1753ff8f8 refactor builtin unsize handling, extend comments 2023-07-28 13:00:54 +02:00
bors e4c98caffe Auto merge of #113312 - Ddystopia:auto-trait-fun, r=lcnr
discard default auto trait impls if explicit ones exist (rebase of #85048)

Rebase of #85048
2023-07-28 10:41:00 +00:00
bors aafd75a9c5 Auto merge of #114134 - fee1-dead-contrib:rm-constness-from-param-env, r=oli-obk
Remove `constness` from `ParamEnv`

This should be replaced by keyword generics/effects. cc #110395

r? `@oli-obk`
2023-07-28 08:53:12 +00:00
Deadbeef e6b423aebb Remove `constness` from `ParamEnv` 2023-07-27 15:50:42 +00:00
Guillaume Gomez 0bebfa39cc
Rollup merge of #114117 - compiler-errors:return-to-uniq, r=lcnr
Restore region uniquification in the new solver 🎉

All of the bugs that were "due" to uniquification have been settled via other means (e.g. bidirectional alias-relate, param-env incompleteness, etc).

Firstly, revert the functional changes in #110180. 😸

Secondly, we need to ignore regions when considering if a goal has changed (the "has_changed" boolean returned from `evaluate_goal`) -- otherwise, because we're doing region uniquification, we may perpetually consider a goal to be changed. See the UI test I committed for an explanation.
2023-07-27 16:05:15 +02:00
bors 2efa46dc15 Auto merge of #114080 - compiler-errors:negative, r=spastorino
Don't treat negative trait predicates as always knowable

We don't need this. It was added in #90104 but I don't really know why. It's not sound afaict -- negative trait predicates need the same coherence-ambiguity/orphan check rules as positive ones.

r? `@lcnr`

cc `@spastorino,` do you remember why?
2023-07-27 07:29:00 +00:00
Michael Goulet 1ffc6ca9a5 Consider a goal as NOT changed if its response is identity modulo regions 2023-07-27 04:00:49 +00:00
Michael Goulet 99f60ec411 Revert "don't uniquify regions when canonicalizing"
This reverts commit 171f541470.
2023-07-27 03:16:34 +00:00
Michael Goulet 808e174dfc Don't treat negative trait predicates as always knowable 2023-07-26 01:35:51 +00:00
Matthias Krüger 0b13deb548
Rollup merge of #113661 - oli-obk:tait_wtf, r=lcnr
Double check that hidden types match the expected hidden type

Fixes https://github.com/rust-lang/rust/issues/113278 specifically, but I left a TODO for where we should also add some hardening.

It feels a bit like papering over the issue, but at least this way we don't get unsoundness, but just surprising errors. Errors will be improved and given spans before this PR lands.

r? `@compiler-errors` `@lcnr`
2023-07-25 23:34:07 +02:00
Michael Goulet a7ed9c1da7 Make everything builtin! 2023-07-25 16:08:58 +00:00
Michael Goulet de81007d13 Consolidate trait upcasting and unsize into one normalization 2023-07-25 15:15:25 +00:00
Michael Goulet c02d1a6553 Restore tuple unsizing feature gate 2023-07-25 15:15:25 +00:00
Michael Goulet 24eefd08e2 Make sure to detect trait upcasting coercion even after normalization 2023-07-25 15:15:25 +00:00
Michael Goulet 7e66c0b7ed Normalize the RHS of an unsize goal 2023-07-25 15:15:25 +00:00
bors fc8a3e357a Auto merge of #114024 - matthiaskrgr:rollup-uhdbq64, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #113969 (add dynamic for smir)
 - #113985 (Use erased self type when autoderefing for trait error suggestion)
 - #113987 (Comment stuff in the new solver)
 - #113992 (arm-none fixups)
 - #113993 (Optimize format usage)
 - #113994 (Optimize format usage)
 - #114006 (Update sparc-unknown-none-elf platform README)
 - #114021 (Add missing documentation for `Session::time`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-24 17:13:24 +00:00
Matthias Krüger 2660d5d977
Rollup merge of #113987 - compiler-errors:comments, r=lcnr
Comment stuff in the new solver

r? `@lcnr`
2023-07-24 17:47:09 +02:00
Matthias Krüger 15c723433f
Rollup merge of #113985 - compiler-errors:issue-113951, r=estebank
Use erased self type when autoderefing for trait error suggestion

Let's not try to pass something from `skip_binder` into autoderef.

Fixes #113951
2023-07-24 17:47:08 +02:00
Michael Goulet 3ad3bb64d9
lcnr's suggestions
Co-authored-by: lcnr <rust@lcnr.de>
2023-07-24 08:37:40 -07:00
bors cb6ab9516b Auto merge of #113956 - fmease:rustdoc-fix-x-crate-rpitits, r=GuillaumeGomez,compiler-errors
rustdoc: handle cross-crate RPITITs correctly

Filter out the internal associated types synthesized during the desugaring of RPITITs, they really shouldn't show up in the docs.

This also fixes #113929 since we're no longer invoking `is_impossible_associated_item` (renamed from `is_impossible_method`) which cannot handle them (leading to an ICE). I don't think it makes sense to try to make `is_impossible_associated_item` handle this exotic kind of associated type (CC original author `@compiler-errors).`

@ T-rustdoc reviewers, currently I'm throwing out ITIT assoc tys before cleaning assoc tys at each usage-site. I'm thinking about making `clean_middle_assoc_item` return an `Option<_>` instead and doing the check inside of it to prevent any call sites from forgetting the check for ITITs. Since I wasn't sure if you would like that approach, I didn't go through with it. Let me know what you think.

<details><summary>Explanation on why <code>is_impossible_associated_item(itit_assoc_ty)</code> leads to an ICE</summary>

Given the following code:

```rs
pub trait Trait { fn def<T>() -> impl Default {} }
impl Trait for () {}
```

The generated associated type looks something like (simplified):

```rs
type {opaque#0}<T>: Default = impl Default; // the name is actually `kw::Empty` but this is the `def_path_str` repr
```

The query `is_impossible_associated_item` goes through all predicates of the associated item – in this case `<T as Sized>` – to check if they contain any generic parameters from the (generic) associated type itself. For predicates that don't contain any *own* generics, it does further processing, part of which is instantiating the predicate with the generic arguments of the impl block (which is only correct if they truly don't contain any own generics since they wouldn't get instantiated this way leading to an ICE).

It checks if `parent_def_id(T) == assoc_ty_def_id` to get to know if `T` is owned by the assoc ty. Unfortunately this doesn't work for ITIT assoc tys. In this case, the parent of `T` is `Trait::def` (!) which is the associated function (I'm pretty sure this is very intentional) which is of course not equal to the assoc ty `Trait::{opaque#0}`.

</details>

`@rustbot` label A-cross-crate-reexports
2023-07-24 15:19:00 +00:00
Matthias Krüger af2b370100 more clippy::style fixes:
get_first
single_char_add_str
unnecessary_mut_passed
manual_map
manual_is_ascii_check
2023-07-23 23:39:04 +02:00
Michael Goulet f3553691a8 Comment stuff in the new solver 2023-07-23 12:30:52 -07:00
Michael Goulet d1380a1844 Use erased self type when autoderefing for trait error suggestion 2023-07-23 14:13:52 -04:00
Deadbeef 626efab67f fix 2023-07-23 09:58:31 +00:00
Matthias Krüger b594798ae3 fix clippy::useless_format 2023-07-23 11:14:52 +02:00
Matthias Krüger adf759bf6a fix couple of clippy findings:
filter_map_identity
iter_kv_map
needless_question_mark
redundant_at_rest_pattern
filter_next
derivable_impls
2023-07-23 10:50:14 +02:00
Matthias Krüger 8f4b81b146
Rollup merge of #113901 - compiler-errors:only-bidi-norm, r=lcnr
Get rid of subst-relate incompleteness in new solver

We shouldn't need subst-relate if we have bidirectional-normalizes-to in the new solver.

The only potential issue may happen if we have an unconstrained projection like `<Wrapper<?0> as Trait>::Assoc == <Wrapper<T> as Trait>::Assoc` where they both normalize to something that doesn't mention any substs, which would possibly prefer `?0 = T` if we fall back to subst-relate. But I'd prefer if we remove incompleteness until we can determine some case where we need them, and the bidirectional-normalizes-to seems better to have in general.

I can update https://github.com/rust-lang/trait-system-refactor-initiative/issues/26 and https://github.com/rust-lang/trait-system-refactor-initiative/issues/25 once this lands.

r? `@lcnr`
2023-07-22 19:57:36 +02:00
Matthias Krüger 0ed5f091a6
Rollup merge of #112508 - compiler-errors:trait-sig-lifetime-sugg-ice, r=cjgillot
Tweak spans for self arg, fix borrow suggestion for signature mismatch

1. Adjust a suggestion message that was annoying me
2. Fix #112503 by recording the right spans for the `self` part of the `&self` 0th argument
3. Remove the suggestion for adjusting a trait signature on type mismatch, bc that's gonna probably break all the other impls of the trait even if it fixes its one usage 😅
2023-07-22 19:57:35 +02:00
Michael Goulet e32011209d Get rid of subst-relate incompleteness in new solver 2023-07-22 15:33:37 +00:00
León Orell Valerian Liehr 5924043b86
rustdoc: handle cross-crate RPITITs correctly 2023-07-22 12:20:17 +02:00
David Tolnay 5bbf0a8306
Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"
This reverts commit 557359f925, reversing
changes made to 1e6c09a803.
2023-07-21 22:35:57 -07:00
bors c3c5a5c5f7 Auto merge of #113922 - matthiaskrgr:rollup-90cj2vv, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #113887 (new solver: add a separate cache for coherence)
 - #113910 (Add FnPtr ty to SMIR)
 - #113913 (error/E0691: include alignment in error message)
 - #113914 (rustc_target: drop duplicate code)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-21 16:52:21 +00:00
Oli Scherer 44e21503a8 Double check that hidden types match the expected hidden type 2023-07-21 13:19:36 +00:00
lcnr 303af36be7 new solver: add a separate cache for coherence 2023-07-21 09:34:10 +02:00
Moulins feb20f2fe7 Track ABI info. in `NaiveLayout`, and use it for `PointerLike` checks
THis significantly complicates `NaiveLayout` logic, but is necessary to
ensure that bounds like `NonNull<T>: PointerLike` hold in generic
contexts.

Also implement exact layout computation for structs.
2023-07-21 03:31:46 +02:00
bors 399b068235 Auto merge of #113856 - WaffleLapkin:vtablin', r=oli-obk
Refactor vtable encoding and optimize it for the case of multiple marker traits

This PR does two things
- Refactor `prepare_vtable_segments` (this was motivated by the other change, `prepare_vtable_segments` was quite hard to understand and while trying to edit it I've refactored it)
  - Mostly remove `loop`s labeled `break`s/`continue`s whenever there is a simpler solution
  - Also use `?`
- Make vtable format a bit more efficient wrt to marker traits
  - See the tests for an example

Fixes https://github.com/rust-lang/rust/issues/113840
cc `@crlf0710`

----

Review wise it's probably best to review each commit individually, as then it's more clear why the refactoring is correct.

I can split the last two commits (which change behavior) into a separate PR if it makes reviewing easier
2023-07-20 20:34:06 +00:00
lcnr 5c75bc5317 update doc comments 2023-07-20 12:01:34 +02:00
lcnr 2062f2ca82 review 2023-07-20 12:01:34 +02:00
lcnr 7c97a76b76 re-add comment 2023-07-20 11:05:52 +02:00
lcnr 2d99f40ec5 assembly: only consider blanket impls once 2023-07-20 11:05:52 +02:00
lcnr fdaec57a28 XSimplifiedType to SimplifiedType::X 2023-07-20 11:05:52 +02:00
Maybe Waffle 1f02c75718 Don't emit useless vptrs for marker traits 2023-07-19 12:06:31 +00:00
Maybe Waffle f33936c567 Fix comment 2023-07-19 11:53:41 +00:00
Maybe Waffle d87db8eb3f Simplify last `prepare_vtable_segments` loop even more 2023-07-19 11:53:41 +00:00
Maybe Waffle d567f0fc68 Slightly refactor 'exiting_out loop in `prepare_vtable_segments`
1. Hide the option as an iterator, so it's nicer to work with
2. Replace a loop with `find`
2023-07-19 11:53:31 +00:00
Maybe Waffle 364fc444a5 Refactor 'diving_in loop internals in `prepare_vtable_segments`
Less explicit loops -- easier to read.
2023-07-19 10:01:48 +00:00
Maybe Waffle f8f5d7aab2 Replace `if let` with `unwrap` in `prepare_vtable_segments`
Reasoning: if the stack is empty, the loop will be infinite,
so the assumption is that the stack can't be non empty. Unwrap
makes the assumption more clear (and removes an indentation level)
2023-07-19 09:51:35 +00:00
Maybe Waffle 348f26e409 Use `?` in `prepare_vtable_segments` 2023-07-19 09:45:26 +00:00
bors b657dc555b Auto merge of #113690 - aliemjay:opaque-defined-by-trait, r=compiler-errors
allow opaques to be defined by trait queries, again

This basically reverts #112963.

Moreover, all call-sites of `enter_canonical_trait_query` can now define opaque types, see the ui test `defined-by-user-annotation.rs`.

Fixes #113689

r? `@compiler-errors` `@oli-obk`
2023-07-19 05:40:58 +00:00
Michael Goulet 05f6890b3e Rename arg_iter to iter_instantiated 2023-07-17 21:04:12 +00:00
Matthias Krüger eca9c0101c
Rollup merge of #113651 - lcnr:parent-def-id, r=compiler-errors
self type param infer, avoid ICE

fixes #113610, which is caused by 33a2c2487a/compiler/rustc_hir_analysis/src/collect/generics_of.rs (L190-L205)
2023-07-17 12:58:53 +02:00
bors 4c7af429f3 Auto merge of #113336 - compiler-errors:new-solver-iat, r=lcnr
Add support for inherent projections in new solver

Not hard to support these, and it cuts out a really big chunk of failing UI tests with `--compare-mode=next-solver`

r? `@lcnr` (feel free to reassign, anyone can review this)
2023-07-17 01:06:36 +00:00
bors f1eab64d4f Auto merge of #113769 - matthiaskrgr:rollup-p6i1rco, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #113042 (Add Platform Support documentation for MIPS Release 6 targets)
 - #113539 (fixed typo)
 - #113614 (platform-support.md: It's now verified that NetBSD/riscv64 can self-h…)
 - #113750 (Add missing italicization to `sort_unstable_by_key` complexity )
 - #113755 (Normalize lazy type aliases when probing for ADTs)
 - #113756 (fix wrong link)
 - #113762 (Fix typo)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-16 23:14:36 +00:00
Matthias Krüger 2b4c194234
Rollup merge of #113539 - agnarrarendelle:master, r=workingjubilee
fixed typo

Hi, I have fixed a few typos in commands. Please review my pr.
2023-07-17 00:14:05 +02:00
bors 0e8e857b11 Auto merge of #113742 - compiler-errors:dont-short-circuit-intercrate-global-preds, r=lcnr
Don't call `predicate_must_hold`-esque functions during fulfillment in intercrate

Fixes #113415

Given that this only happens in `translate_substs`, I don't actually think that this is something that you can weaponize, but it's still sketchy regardless.

r? `@lcnr`
2023-07-16 21:30:37 +00:00
Michael Goulet c9ce51b5c7 Check GAT, IAT, and weak type where clauses during projection 2023-07-16 21:14:38 +00:00
Michael Goulet 085ae9e8b4 Add support for inherent projections 2023-07-16 21:14:38 +00:00
lcnr e449daad6c stop mentioning number of applicate implementations 2023-07-16 15:36:19 +02:00
Michael Goulet 8f178d1b0c Don't call predicate_must_hold during fulfillment in intercrate 2023-07-16 01:56:16 +00:00
Matthias Krüger da18cf8572
Rollup merge of #113625 - compiler-errors:structurally-norm-in-selection, r=lcnr
Structurally normalize in selection

We need to do this because of the fact that we're checking the `Ty::kind` on a type during selection, but goals passed into select are not necessarily normalized.

Right now, we're (kinda) unnecessarily normalizing the RHS of a trait upcasting goal, which is broken for different reasons (#113393). But I'm waiting for this PR to land before discussing that one.

r? `@lcnr`
2023-07-15 19:42:51 +02:00
bors ad963232d9 Auto merge of #113471 - compiler-errors:new-solver-norm-escaping, r=lcnr
Allow escaping bound vars during `normalize_erasing_regions` in new solver

Add `AllowEscapingBoundVars` to `deeply_normalize`, and use it in the new solver in the `query_normalize` routine.

Ideally, we'd make all `query_normalize` calls handle pass in `AllowEscapingBoundVars` individually, because really the only `query_normalize` call that needs `AllowEscapingBoundVars::Yes` is the one in `try_normalize_generic_arg_after_erasing_regions`, but I think that's kind of overkill. I am happy to be convinced otherwise, though.

r? `@lcnr`
2023-07-14 21:14:30 +00:00
Michael Goulet 7fb27e4717 Structurally normalize in selection 2023-07-14 18:40:18 +00:00
Matthias Krüger 0baf4406da
Rollup merge of #113698 - compiler-errors:rpitit-check, r=spastorino
Make it clearer that we're just checking for an RPITIT

Tiny nit to use `is_impl_trait_in_trait` more, to make it clearer that we're just checking whether a def-id is an RPITIT, rather than doing something meaningful with the `opt_rpitit_info`.

r? `@spastorino`
2023-07-14 19:33:29 +02:00
Michael Goulet 14672eba8b Make it clearer that we're just checking for an RPITIT 2023-07-14 15:18:48 +00:00
Michael Goulet 1ef85d82e0 assertion, comment 2023-07-14 15:03:21 +00:00
Michael Goulet 4bcca3294a Allow escaping bound vars during normalize_erasing_regions in new solver 2023-07-14 15:03:21 +00:00
Ali MJ Al-Nasrawy 281c2271be allow opaques to be defined by trait queries 2023-07-14 12:35:33 +00:00
Mahdi Dibaiee e55583c4b8 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Matthias Krüger dec104c7ad
Rollup merge of #113536 - lcnr:proof-tree-select, r=BoxyUwU
avoid building proof trees in select

otherwise we ICE because select isn't currently set up to print proof trees.

r? `````@BoxyUwU`````
2023-07-13 22:33:23 +02:00
bors a161ab00db Auto merge of #113637 - Mark-Simulacrum:bootstrap-bump, r=ozkanonur
Bump bootstrap to 1.72 beta
2023-07-13 18:15:14 +00:00
Matthias Krüger 893a5d2b32
Rollup merge of #113353 - compiler-errors:select-better, r=lcnr
Implement selection for `Unsize` for better coercion behavior

In order for much of coercion to succeed, we need to be able to deal with partial ambiguity of `Unsize` traits during selection. However, I pessimistically implemented selection in the new trait solver to just bail out with ambiguity if it was a built-in impl:
9227ff28af/compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs (L126)

This implements a proper "rematch" procedure for dealing with built-in `Unsize` goals, so that even if the goal is ambiguous, we are able to get nested obligations which are used in the coercion selection-like loop:
9227ff28af/compiler/rustc_hir_typeck/src/coercion.rs (L702)

Second commit just moves a `resolve_vars_if_possible` call to fix a bug where we weren't detecting a trait upcasting to occur.

r? ``@lcnr``
2023-07-13 12:19:22 +02:00
Mark Rousskov cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
Mark Rousskov 67b0cfc761 Flip cfg's for bootstrap bump 2023-07-12 21:38:55 -04:00
agnarrarendelle dcfcc77282 fixed typos 2023-07-12 01:25:47 +08:00
bors 0a2681cc49 Auto merge of #113470 - compiler-errors:new-solver-structurally-resolve-pat, r=lcnr
Structurally resolve in pattern matching when peeling refs in new solver

Let me know if you want me to commit the minimized test:
```rust
fn test() {}

fn test2() {}

fn main() {
    let tests: &[(_, fn())] = &[
        ("test", test),
        ("test2", test2),
    ];

    for (a, b) in tests {
        todo!();
    }
}
```

In that test above, the match scrutinee is `<std::vec::Iter<(&'static str, fn())> as Iterator>::Item`, which we cannot peel the refs from.

We also need to structurally resolve in the loop, since structural resolve is inherently shallow. I haven't come up with a test where this matters, but I can if you care.

Also,  I removed two other calls to `resolve_vars_with_obligations` in diagnostics code that I'm pretty convinced are not useful.

r? `@lcnr`
2023-07-11 15:29:47 +00:00
Michael Goulet 846d54f16c Structurally resolve in pattern matching when peeling refs in new solver 2023-07-11 02:40:59 +00:00
bors 8ca44ef9ca Auto merge of #112988 - spastorino:new-rpitit-24, r=compiler-errors
Replace RPITIT current impl with new strategy that lowers as a GAT

This PR replaces the current implementation of RPITITs with the new implementation that we had under -Zlower-impl-trait-in-trait-to-assoc-ty flag that lowers the RPIT as a GAT on the trait and on the impls that implement that trait.

Opening this PR as a draft because this goes after #112682, ~#112981~ and ~#112983~.
As soon as those are merged, I can rebase and we should run perf, crater and test a lot.

r? `@compiler-errors`
2023-07-10 19:01:30 +00:00
lcnr 4965caf9be avoid building proof trees in select 2023-07-10 15:17:01 +02:00
Santiago Pastorino 20429af7a3
Replace RPITIT current impl with new strategy that lowers as a GAT 2023-07-08 18:21:34 -03:00
bors 83964c156d Auto merge of #113491 - matthiaskrgr:rollup-mueqz7h, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #113005 (Don't call `query_normalize` when reporting similar impls)
 - #113064 (std: edit [T]::swap docs)
 - #113138 (Add release notes for 1.71.0)
 - #113217 (resolve typerelative ctors to adt)
 - #113254 (Use consistent formatting in Readme)
 - #113482 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-08 20:56:57 +00:00
Matthias Krüger 48a0d038fa
Rollup merge of #113005 - compiler-errors:dont-query-normalize, r=cjgillot
Don't call `query_normalize` when reporting similar impls

Firstly, It's sketchy to be using `query_normalize` at all during HIR typeck -- it's asking for an ICE 😅. Secondly, we're normalizing an impl trait ref that potentially has parameter types in `ty::ParamEnv::empty()`, which is kinda sketchy as well.

The only UI test change from removing this normalization is that we don't evaluate anonymous constants in impls, which end up giving us really ugly suggestions:

```
error[E0277]: the trait bound `[X; 35]: Default` is not satisfied
 --> /home/gh-compiler-errors/test.rs:4:5
  |
4 |     <[X; 35] as Default>::default();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[X; 35]`
  |
  = help: the following other types implement trait `Default`:
            &[T]
            &mut [T]
            [T; 32]
            [T; core::::array::{impl#30}::{constant#0}]
            [T; core::::array::{impl#31}::{constant#0}]
            [T; core::::array::{impl#32}::{constant#0}]
            [T; core::::array::{impl#33}::{constant#0}]
            [T; core::::array::{impl#34}::{constant#0}]
          and 27 others
```

So just fold the impls with a `BottomUpFolder` that calls `ty::Const::eval`. This doesn't work totally correctly with generic-const-exprs, but it's fine for stable code, and this is error reporting after all.
2023-07-08 20:53:27 +02:00
Matthias Krüger f3f1b0394d
Rollup merge of #113335 - compiler-errors:reveal-opaques-in-new-solver, r=lcnr
Reveal opaques in new solver

We were testing against the wrong reveal mode 😨

Also a couple of misc commits that I don't want to really put in separate prs

r? ``@lcnr``
2023-07-08 15:49:46 +02:00
bors ce519c5945 Auto merge of #113474 - compiler-errors:rollup-07x1up7, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #113413 (Add needs-triage to all new issues)
 - #113426 (Don't ICE in `resolve_bound_vars` when associated return-type bounds are in bad positions)
 - #113427 (Remove `variances_of` on RPITIT GATs, remove its one use-case)
 - #113441 (miri: check that assignments do not self-overlap)
 - #113453 (Remove unused from_method from rustc_on_unimplemented)
 - #113456 (Avoid calling report_forbidden_specialization for RPITITs)
 - #113466 (Update cargo)
 - #113467 (Fix comment of `fn_can_unwind`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-08 10:46:29 +00:00
Michael Goulet 37a05d8054
Rollup merge of #113453 - spastorino:new-rpitit-30, r=compiler-errors
Remove unused from_method from rustc_on_unimplemented

Fixes #113439

`on_unimplemented_note` was calling `item_name` for RPITITs and that produced ICEs. I've added a regression test for that but also have removed `from_method` symbol entirely because it wasn't even used and by doing that the `item_name` call was also removed.

r? ``@compiler-errors``
2023-07-07 22:12:17 -07:00
Michael Goulet 77c3cf1bfd Implement selection for unsize for better coercion behavior 2023-07-08 03:41:22 +00:00
bors d4096e0412 Auto merge of #112652 - oli-obk:tait_only_in_sig, r=compiler-errors
Require TAITs to be mentioned in the signatures of functions that register hidden types for them

r? `@lcnr` `@compiler-errors`

This implements the lang team decision from [the TAIT design meeting](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/design.20meeting.202023-05-31.20TAITs/near/362518164).
2023-07-08 03:22:54 +00:00
Santiago Pastorino 3aec8d4227
Remove unused from_method symbol 2023-07-07 15:57:30 -03:00
Michael Goulet f55b046931 Normalize opaques during codegen in new solver 2023-07-07 16:02:25 +00:00
bors cb80ff132a Auto merge of #113245 - lukas-code:unsizing-sanity-check, r=the8472
sanity check field offsets in unsizeable structs

As promised in https://github.com/rust-lang/rust/pull/112062#issuecomment-1567494994, this PR extends the layout sanity checks to ensure that structs fields don't move around when unsizing and prevent issues like https://github.com/rust-lang/rust/issues/112048 in the future. Like most other layout sanity checks, this only runs on compilers with debug assertions enabled.

Here is how it looks when it fails:
```text
error: internal compiler error: compiler/rustc_ty_utils/src/layout.rs:533:21: unsizing GcNode<std::boxed::Box<i32>> changed field order!
                                Layout { size: Size(32 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: Aggregate { sized: true }, fields: Arbitrary { offsets: [Size(0 bytes), Size(8 bytes), Size(24 bytes)], memory_index: [0, 1, 2] }, largest_niche: Some(Niche { offset: Size(24 bytes), value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), variants: Single { index: 0 } }
                                Layout { size: Size(24 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: Aggregate { sized: false }, fields: Arbitrary { offsets: [Size(16 bytes), Size(0 bytes), Size(24 bytes)], memory_index: [1, 0, 2] }, largest_niche: None, variants: Single { index: 0 } }
```

r? `@the8472`
2023-07-07 15:42:29 +00:00