276 Commits

Author SHA1 Message Date
Matthias Krüger
fc318986f3
Rollup merge of #148292 - adwinwhite:assemble_object_candidate, r=lcnr
Un-shadow object bound candidate in `NormalizesTo` goal if self_ty is trait object

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/244

r? lcnr
2025-11-06 12:29:58 +01:00
Adwin White
d2cfc47ed0 add test for alias self_ty 2025-11-05 21:29:39 +08:00
Matthias Krüger
844a41903e
Rollup merge of #148290 - oli-obk:push-qwxvxyopypry, r=nnethercote
Do not emit solver errors that contain error types

any follow-up errors are going to either be duplicates or often disappear if the error itself is fixed.

in this PR it mostly silences dyn-compat errors as all the other errors are already deduplicated outside of the test suite. The dyn compat errors are independent errors and I think if the dyn compatiblity depended on an error type it would not actually show, so this is PR is actually silencing independent errors, too.

I am opening this PR because I am seeing lots of `{type error}: const Trait` errors when adding more const checking. So instead of targetting just those specific errors, I wanted to try out fully avoiding such errors near the trait solver.

cc ````@rust-lang/types```` for thoughts
2025-11-02 09:10:38 +01:00
Esteban Küber
eeadffd926 When more than a single impl and less than 4 could apply, point at them
```
error[E0277]: the trait bound `[[u16; 3]; 2]: Bar` is not satisfied
  --> $DIR/issue-67185-2.rs:21:6
   |
LL | impl Foo for FooImpl {}
   |      ^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]`
   |
help: the following other types implement trait `Bar`
  --> $DIR/issue-67185-2.rs:9:1
   |
LL | impl Bar for [u16; 4] {}
   | ^^^^^^^^^^^^^^^^^^^^^ `[u16; 4]`
LL | impl Bar for [[u16; 3]; 3] {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ `[[u16; 3]; 3]`
note: required by a bound in `Foo`
  --> $DIR/issue-67185-2.rs:14:30
   |
LL | trait Foo
   |       --- required by a bound in this trait
LL | where
LL |     [<u8 as Baz>::Quaks; 2]: Bar,
   |                              ^^^ required by this bound in `Foo`
```
2025-10-31 20:44:01 +00:00
Adwin White
e2ac9d92d9 Apply suggestions 2025-10-31 20:31:49 +08:00
Oli Scherer
cac6f8760a Do not emit solver errors that contain error types 2025-10-31 08:17:44 +00:00
Adwin White
2fbb751985 Un-shadow object bound candidate in NormalizesTo goal 2025-10-30 20:22:45 +08:00
Matthias Krüger
1fe148371a
Rollup merge of #148173 - tiif:fix-opaque-ice, r=BoxyUwU
Emit delayed bug during wfck for stranded opaque

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/235

## Problem

The fundamental issue here is ``OpaqueTypeCollector`` operates on ``rustc_middle::Ty``, but ``check_type_wf`` operates on HIR.

Since [check_type_wf](2f7620a5cc/compiler/rustc_hir_analysis/src/check/wfcheck.rs (L2262)) operates on HIR, it can see the stranded opaque and tries to infer it's hidden type. But ``OpaqueTypeCollector`` operates on ``rustc_middle::Ty``, so the ``OpaqueTypeCollector`` can no longer see a stranded opaque, hence its hidden type could not be inferred.

As a result, the tests ICE'ed at 34a8c7368c/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs (L253)

## Proposed solution

This PR detects stranded opaque types during wf check and emit a delayed bug for it.

## Alternative solution

`@BoxyUwU` and I had considered rewriting ``OpaqueTypeCollector`` to be a HIR visitor instead of a ``rustc_middle::Ty`` visitor, but we believe a HIR-based ``OpaqueTypeCollector`` will not work and might not worth the cost of rewriting.

## Acknowledgement

This PR is a joint effort with `@BoxyUwU` :3
2025-10-28 17:49:29 +01:00
tiif
eb113533a3 Add test 2025-10-28 13:02:19 +00:00
Stuart Cook
1cf3dc6b5a
Rollup merge of #147840 - jdonszelmann:unsizing-coercions, r=lcnr
Rework unsizing coercions in the new solver

Replaces https://github.com/rust-lang/rust/pull/141926, contains:

- a commit adding tests that fail before this work
- the two commits from the previous PR
- a commit in which these tests are fixed
- finally, a fixup for an in my opinion rather large regression in diagnostics. It's still not perfect, but better?

I hope this is roughly what you had in mind

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/241 and https://github.com/rust-lang/trait-system-refactor-initiative/issues/238, adding tests for both

r? ````@lcnr````
2025-10-28 20:39:33 +11:00
Jana Dönszelmann
3d9cb043dd
prove both newly added tests are fixed by the changes 2025-10-27 12:00:41 +01:00
bors
cc63a0abde Auto merge of #148066 - lcnr:remove-perf-hack, r=BoxyUwU
remove a performance hack

This hack seems no longer used 🤔 nalgebra compiles without it.

Let's run perf to see whether it matters.

r? `@BoxyUwU`
2025-10-25 22:23:29 +00:00
David Wood
82a4049844
hir_analysis: add missing sizedness bounds
Default sizedness bounds were not being added to
`explicit_super_predicates_of` and `explicit_implied_predicates_of`
which meant that a trait bound added to a associated type projection
would be missing the implied predicate of the default sizedness
supertrait of that trait.

An unexpected consequence of this change was that the check for multiple
principals was now finding an additional `MetaSized` principal when
eagerly expanding trait aliases. Instead of special-casing trait aliases
as different from traits and not adding a `MetaSized` supertrait to trait
aliases, filter out `MetaSized` when lowering `dyn Trait`.
2025-10-24 15:28:34 +01:00
lcnr
561e3cede2 gamer 2025-10-24 15:34:45 +02:00
Jana Dönszelmann
491554dbc1
add tests for unsizing coercions (both ICE) 2025-10-20 14:35:51 +02:00
bors
402ce0ef07 Auto merge of #147745 - matthiaskrgr:rollup-b4kftk9, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#143191 (Stabilize `rwlock_downgrade` library feature)
 - rust-lang/rust#147444 (Allow printing a fully-qualified path in `def_path_str`)
 - rust-lang/rust#147527 (Update t-compiler beta nomination Zulip msg)
 - rust-lang/rust#147670 (some `ErrorGuaranteed` cleanups)
 - rust-lang/rust#147676 (Return spans out of `is_doc_comment` to reduce reliance on `.span()` on attributes)
 - rust-lang/rust#147708 (const `mem::drop`)
 - rust-lang/rust#147710 (Fix ICE when using contracts on async functions)
 - rust-lang/rust#147716 (Fix some comments)
 - rust-lang/rust#147718 (miri: use allocator_shim_contents codegen helper)
 - rust-lang/rust#147729 (ignore boring locals when explaining why a borrow contains a point due to drop of a live local under polonius)
 - rust-lang/rust#147742 (Revert unintentional whitespace changes to rustfmt-excluded file)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-15 23:20:53 +00:00
David Wood
efaeacfc96
revert: PR144016 - MetaSized does not always hold 2025-10-15 09:35:04 +01:00
ltdk
491bc5008c const mem::drop 2025-10-14 21:49:24 -04:00
Stuart Cook
4321adfbe0
Rollup merge of #147266 - lcnr:fix-search_graph, r=BoxyUwU
fix 2 search graph bugs

wooooooooops, i should really run the fuzzer even when not changing the structure of the search graph as a whole :3 fixes the `ml-kem` ICE in the next-solver crater run

r? ````@BoxyUwU````
2025-10-14 16:30:58 +11:00
Jack Huey
d51f09e5ba Review comments. Move resolve_vars_if_possible into fn and add test minimizations. Update comment and test. 2025-10-13 20:25:01 +00:00
jackh726
a3fbae599c Merge match and if 2025-10-02 21:19:57 +00:00
jackh726
db3c9b640e When computing opaque types in the next solver, take an initial pass pre-fallback where we equate hidden types but do not report errors 2025-10-02 21:06:16 +00:00
lcnr
36283bcb7e fix RebaseReason::Ambiguity
we should not get the certainty from the current result of the
provisional cache entry
2025-10-02 12:10:58 +02:00
lcnr
5139facb36 add tests 2025-09-30 12:02:43 +02:00
lcnr
0f2b79c36d add tests 2025-09-29 15:28:33 +02:00
Matthias Krüger
750e902a75
Rollup merge of #146675 - Jules-Bertholet:sync-nonexclusive, r=Mark-Simulacrum
Allow shared access to `Exclusive<T>` when `T: Sync`

Addresses libs-api request in https://github.com/rust-lang/rust/issues/98407#issuecomment-3299348713.

Adds the following trait impls to `Exclusive<T>`, all bounded on `T: Sync`:

- `AsRef<T>`
- `Clone`
- `Copy`
- `PartialEq`
- `StructuralPartialEq`
- `Eq`
- `Hash`
- `PartialOrd`
- `Ord`
- `Fn`

``@rustbot`` label T-libs-api
2025-09-28 18:13:12 +02:00
lcnr
4a0c7cc730 fix cycle head usages tracking 2025-09-26 15:29:01 +02:00
lcnr
32d24f9efa allow bound regions in writeback 2025-09-24 13:08:25 +02:00
Jules Bertholet
f1d6e000b5
Bless UI tests 2025-09-21 17:26:39 -04:00
Joe Birr-Pixton
325ceef018 Fix other uses of "adaptor" 2025-09-16 11:58:12 +01:00
lcnr
14b0ba6a05 support non-defining uses in HIR typeck 2025-08-25 14:20:18 +02:00
bors
69b76df90c Auto merge of #145706 - lcnr:uniquification, r=BoxyUwU
change HIR typeck region uniquification handling approach

rust-lang/rust#144405 causes structural lookup of opaque types to not work during HIR typeck, so instead avoid uniquifying goals and instead only reprove them if MIR borrowck actually encounters an error.

This doesn't perfectly maintain the property that HIR typeck succeeding implies that MIR typeck succeeds, instead weakening this check to only guarantee that HIR typeck implies that MIR typeck succeeds modulo region uniquification. This means we still get the actually desirable ICEs if we MIR building is broken or we forget to check some property in HIR typeck, without having to deal with the fallout of uniquification in HIR typeck itself.

We report errors using the original obligation sources of HIR typeck so diagnostics aren't that negatively impacted either.

Here's the history of region uniquification while working on the new trait solver:
- rust-lang/rust#107981
- rust-lang/rust#110180
- rust-lang/rust#114117
- rust-lang/rust#130821
- rust-lang/rust#144405
- rust-lang/rust#145706 <- we're here 🎉

r? `@BoxyUwU`
2025-08-23 20:16:58 +00:00
Esteban Küber
049c32797b On E0277, point at type that doesn't implement bound
When encountering an unmet trait bound, point at local type that doesn't implement the trait:

```
error[E0277]: the trait bound `Bar<T>: Foo` is not satisfied
  --> $DIR/issue-64855.rs:9:19
   |
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
   |                   ^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
   |
help: the trait `Foo` is not implemented for `Bar<T>`
  --> $DIR/issue-64855.rs:9:1
   |
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
   | ^^^^^^^^^^^^^^^^^
```
2025-08-22 17:55:15 +00:00
lcnr
17ac2fc96d change HIR typeck unification handling approach 2025-08-22 13:39:38 +02:00
lcnr
aa3691ea08 add regression test 2025-08-14 15:32:50 +02:00
lcnr
a78f92be9b add tests 2025-07-31 15:39:55 +02:00
lcnr
b6cbe33aeb handle region dependent goals due to infer vars 2025-07-30 14:01:37 +02:00
lcnr
0b323eacd4 uniquify root goals during HIR typeck 2025-07-25 12:40:01 +00:00
Michael Goulet
1e96d7a553 Consider param-env for fast path 2025-07-20 17:45:01 +00:00
Michael Goulet
42c9bfd2b9 Remove Symbol for Named LateParam/Bound variants 2025-07-04 18:14:22 +00:00
Michael Goulet
e2e3f5809b Remove PointerLike trait 2025-07-03 20:03:49 +00:00
Oli Scherer
632a921479 Move lazy type alias checks to non-hir-wfck 2025-06-30 08:45:43 +00:00
Guillaume Gomez
80f20c98f3
Rollup merge of #142671 - davidtwco:no-default-bounds-attr, r=lcnr
add #![rustc_no_implicit_bounds]

Follow-up from rust-lang/rust#137944.

Adds a new `rustc_attrs` attribute that stops rustc from adding any default bounds. Useful for tests where default bounds just add noise and make debugging harder.

After reviewing all tests with `?Sized`, these tests seem like they could probably benefit from `#![rustc_no_implicit_bounds]`.

- Skipping most of `tests/ui/unsized` as these seem to want to test `?Sized`
- Skipping tests that used `Box<T>` because it's still bound by `T: MetaSized`
- Skipping parsing or other tests that cared about `?Sized` syntactically
- Skipping tests for `derive(CoercePointee)` because this appears to check that the pointee type is relaxed with `?Sized` explicitly

r? `@lcnr`
2025-06-27 15:04:52 +02:00
David Wood
1fd13fddba
tests: add #![rustc_no_implicit_bounds]
After reviewing all tests with `?Sized` and discussing with lcnr, these
tests seem like they could probably benefit from
`#![rustc_no_implicit_bounds]`.
2025-06-27 05:34:08 +00:00
Michael Goulet
250b5d204f Make missing lifetime suggestion verbose 2025-06-24 18:59:42 +00:00
David Wood
183458263b
tests: bless remaining tests
These tests just need blessing, they don't have any interesting behaviour
changes.

Some of these tests have new errors because `LegacyReceiver` cannot be
proven to be implemented now that it is also testing for `MetaSized` -
but this is just a consequence of the other errors in the test.
2025-06-16 23:04:35 +00:00
Michael Goulet
cd1d84e304 Apply nested goals certainty to InspectGoals for normalizes-to 2025-06-09 17:02:09 +00:00
Michael Goulet
3418d5db3a Fast path for stalled obligations on self ty 2025-06-02 19:23:20 +00:00
Michael Goulet
2a339ce492 Structurally normalize types as needed in projection_ty_core 2025-05-29 11:16:44 +00:00
Matthias Krüger
69b13e4cab
Rollup merge of #141347 - lcnr:lets-make-it-unsound-3, r=compiler-errors
incorrectly prefer builtin `dyn` impls :3

This makes #57893 slightly more exploitable with the new solver. It's still strictly better than the old solver and the underlying unsoundness persists in the new one even without this preference.

Properly fixing #57893 is something we've been looking at more deeply recently and discussed at the [Types Meetup during the All-Hands](https://hackmd.io/rz-4ghMzTb2wXOkdLKHaHw#Dyn-traits). Whatever approach we'll end up deciding on will likely require a fairly long transition period and some significant further design work. This should not block `-Znext-solver`.

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

r? `@compiler-errors` cc `@rust-lang/types`
2025-05-21 22:14:59 +02:00