Commit Graph

263 Commits

Author SHA1 Message Date
Matthias Krüger
1f84e114f1
Rollup merge of #140712 - lcnr:normalization-gat-args, r=compiler-errors
normalization: avoid incompletely constraining GAT args

We need to copy the behavior of #125214 in the new solver. This fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/202 which seems to be the cause of the regression in `deptypes`.

r? ```@compiler-errors```
2025-05-15 22:28:50 +02:00
omahs
1caaa88700 Fix typos 2025-05-12 17:20:49 +00:00
lcnr
01854845bc refactor probe_and_consider_param_env_candidate 2025-05-08 14:51:41 +00:00
lcnr
31ebe11f61 normalization: avoid incompletely constraining GAT args 2025-05-08 14:38:47 +00:00
Matthias Krüger
74b79aee60
Rollup merge of #140711 - compiler-errors:combine-maybes, r=lcnr
Do not discard constraints on overflow if there was candidate ambiguity

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

There's a pretty chunky justification in the test.

r? lcnr
2025-05-08 08:14:18 +02:00
Matthias Krüger
aace48811b
Rollup merge of #140641 - lcnr:opaque-type-storage-entries, r=compiler-errors
detect additional uses of opaques after writeback

Based on #140607. It's a lot harder to encounter in practice than I though 😅 😁 I've still added it with the expectation that somebody will encounter it at some point.

Also modifies the `EvalCtxt` to use the same impl to detect newly added opaque types.

r? ``@compiler-errors``
2025-05-08 08:14:18 +02:00
lcnr
e7979eab89 detect additional uses of opaques after writeback 2025-05-07 17:59:51 +00:00
lcnr
fc0ef54fd9 opaque_type_storage to InferCtxtLike 2025-05-07 17:58:20 +00:00
Michael Goulet
a910329c67 Use MaybeCause::or to allow constraints from overflows if they are combined with ambiguity 2025-05-07 17:12:15 +00:00
Michael Goulet
8a21d1b495 Review 2025-05-07 16:29:49 +00:00
Michael Goulet
1f774d74b3 Only prefer param-env candidates if they remain non-global after norm 2025-05-07 16:00:21 +00:00
lcnr
431f02d531 support duplicates in the opaque_types_storage 2025-05-06 14:59:09 +00:00
Boxy
238d113b07 Set groundwork for proper const normalization 2025-05-01 20:05:02 +01:00
Oli Scherer
a1c70590b2 Treat ManuallyDrop as ~const Destruct 2025-04-29 10:39:54 +00:00
Chris Denton
bf37847434
Rollup merge of #140402 - lcnr:normalizes-to-certainty-yes, r=compiler-errors
only return nested goals for `Certainty::Yes`

Ambiguous `NormalizesTo` goals can otherwise repeatedly add the same nested goals to the parent.

r? ```@compiler-errors```
2025-04-28 23:29:19 +00:00
Chris Denton
0bd531aaf2
Rollup merge of #140276 - compiler-errors:typeof-less-eagerly, r=lcnr
Do not compute type_of for impl item if impl where clauses are unsatisfied

Consider the following code:

```rust
trait Foo {
    fn call(self) -> impl Send;
}

trait Nested {}
impl<T> Foo for T
where
    T: Nested,
{
    fn call(self) -> impl Sized {
        NotSatisfied.call()
    }
}

struct NotSatisfied;
impl Foo for NotSatisfied {
    fn call(self) -> impl Sized {
        todo!()
    }
}
```

In `impl Foo for NotSatisfied`, we need to prove that the RPITIT is well formed. This requires proving the item bound `<NotSatisfied as Foo>::RPITIT: Send`. Normalizing `<NotSatisfied as Foo>::RPITIT: Send` assembles two impl candidates, via the `NotSatisfied` impl and the blanket `T` impl. We end up computing the `type_of` for the blanket impl even if `NotSatisfied: Nested` where clause does not hold.

This type_of query ends up needing to prove that its own `impl Sized` RPIT satisfies `Send`, which ends up needing to compute the hidden type of the RPIT, which is equal to the return type  of `NotSatisfied.call()`. That ends up in a query cycle, since we subsequently try normalizing that return type via the blanket impl again!

In the old solver, we don't end up computing the `type_of` an impl candidate if its where clauses don't hold, since this select call would fail before confirming the projection candidate:

d7ea436a02/compiler/rustc_trait_selection/src/traits/project.rs (L882)

This PR makes the new solver more consistent with the old solver by adding a call to `try_evaluate_added_goals` after regstering the impl predicates, which causes us to bail before computing the `type_of` for impls if the impl definitely doesn't apply.

r? lcnr

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/185
2025-04-28 23:29:16 +00:00
bors
25cdf1f674 Auto merge of #140388 - GuillaumeGomez:rollup-aj9o3ch, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #140056 (Fix a wrong error message in 2024 edition)
 - #140220 (Fix detection of main function if there are expressions around it)
 - #140249 (Remove `weak` alias terminology)
 - #140316 (Introduce `BoxMarker` to improve pretty-printing correctness)
 - #140347 (ci: clean more disk space in codebuild)
 - #140349 (ci: use aws codebuild for the `dist-x86_64-linux` job)
 - #140379 (rustc-dev-guide subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-28 17:22:11 +00:00
Michael Goulet
105d1dcefd Do not compute type_of for impl item if impl where clauses are unsatisfied 2025-04-28 17:15:11 +00:00
lcnr
016105cd77 review 2025-04-28 16:49:30 +00:00
lcnr
fa90feaeef only return nested goals for Certainty::Yes 2025-04-28 16:36:02 +00:00
Guillaume Gomez
7843686ffe
Rollup merge of #140249 - BoxyUwU:remove_weak_alias_terminology, r=oli-obk
Remove `weak` alias terminology

I find the "weak" alias terminology to be quite confusing. It implies the existence of "strong" aliases (which do not exist) and I'm not really sure what about weak aliases is "weak". I much prefer "free alias" as the term. I think it's much more obvious what it means as "free function" is a well defined term that already exists in rust.

It's also a little confusing given "weak alias" is already a term in linker/codegen spaces which are part of the compiler too. Though I'm not particularly worried about that as it's usually very obvious if you're talking about the type system or not lol. I'm also currently trying to write documentation about aliases and it's somewhat awkward/confusing to be talking about *weak* aliases, when I'm not really sure what the basis for that as the term actually *is*.

I would also be happy to just find out there's a nice meaning behind calling them "weak" aliases :-)

r? `@oli-obk`

maybe we want a types MCP to decide on a specific naming here? or maybe we think its just too late to go back on this naming decision ^^'
2025-04-28 13:30:45 +02:00
Andrew Zhogin
c366756a85 AsyncDrop implementation using shim codegen of async_drop_in_place::{closure}, scoped async drop added. 2025-04-28 16:23:13 +07:00
Matthias Krüger
3c322bc1cc
Rollup merge of #140320 - lcnr:wf-use-term, r=compiler-errors
replace `GenericArg` with `Term` where applicable

r? types
2025-04-26 16:12:33 +02:00
lcnr
855035b038 convert some GenericArg to Term 2025-04-26 02:05:31 +00:00
lcnr
009db53e49 handle specialization in the new trait solver
uwu :3
2025-04-25 17:59:33 +00:00
lcnr
e5e3a95c1e norm nested aliases before evaluating the parent goal 2025-04-24 18:41:43 +00:00
Boxy
bdfeb8f36b Remove weak alias terminology 2025-04-24 11:59:20 +01:00
Matthias Krüger
1553cfa4e6
Rollup merge of #140214 - compiler-errors:remove-hack, r=lcnr
Remove comment about handling non-global where bounds with corresponding projection

This comment is no longer relevant since we only assemble rigid projections if no param-env candidates hold.

Also remove a stray comment from the old solver.

r? lcnr
2025-04-24 11:40:46 +02:00
Michael Goulet
1162f42b86 Remove hack 2025-04-23 18:36:37 +00:00
Michael Goulet
f943f73db4 More 2025-04-23 15:09:25 +00:00
Michael Goulet
7c1661f945 Consider Copy/Clone too 2025-04-22 17:05:15 +00:00
Michael Goulet
169955f3be Properly drain pending obligations for coroutines 2025-04-22 16:50:38 +00:00
Michael Goulet
e882ff4e7e Don't assemble non-env/bound candidates if projection is rigid 2025-04-18 01:44:06 +00:00
Matthias Krüger
da43826398
Rollup merge of #139774 - compiler-errors:supertrait-alias, r=lcnr
Fix replacing supertrait aliases in `ReplaceProjectionWith`

The new solver has a procedure called `predicates_for_object_candidate`, which elaborates the super-bounds and item-bounds that are required to hold for a dyn trait to implement something via a built-in object impl.

In that procedure, there is a folder called `ReplaceProjectionWith` which is responsible for replacing projections that reference `Self`, so that we don't encounter cycles when we then go on to normalize those projections in the process of proving these super-bounds.

That folder had a few problems: Firstly, it wasn't actually checking that this was a super bound originating from `Self`. Secondly, it only accounted for a *single* projection type def id, but trait objects can have multiple (i.e. `trait Foo<A, B>: Bar<A, Assoc = A> + Bar<B, Assoc = B>`).

To fix the first, it's simple enough to just add an equality check for the self ty. To fix the second, I implemented a matching step that's very similar to the `projection_may_match` check we have for upcasting, since on top of having multiple choices, we need to deal with both non-structural matches and ambiguity.

This probably lacks a bit of documentation, but I think it works pretty well.

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

r? lcnr
2025-04-17 17:40:27 +02:00
Matthias Krüger
9e0be6c15b
Rollup merge of #139900 - lcnr:normalizes-to-where-bounds-unproductive, r=compiler-errors
stepping into impls for normalization is unproductive

See the inline comment. This builds on the reasoning from #136824 (https://gist.github.com/lcnr/c49d887bbd34f5d05c36d1cf7a1bf5a5). Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/176.

Looking at the end of the gist:
> The only ways to project out of a constructor are the following:
> - accessing an associated item, either its type or its item bounds
> - accessing super predicates

Detecting cases where we accessing the type of an associated item is easy, it's simply when we normalize. I don't yet know how to detect whether we step out of an impl by accessing item bounds. Once we also detect these cases we should be able to soundly support arbitrary coinductive traits. Luckily this does not matter for this PR :>

r? `@compiler-errors` cc `@nikomatsakis`
2025-04-17 00:16:24 +02:00
Michael Goulet
bb3c98165c Don't require rigid alias's trait to hold 2025-04-16 20:06:39 +00:00
Michael Goulet
e1936d22ed Remove FIXME that is no longer relevant 2025-04-16 20:05:55 +00:00
Michael Goulet
3863018d96 Fix replacing supertrait aliases in ReplaceProjectionWith 2025-04-16 20:05:55 +00:00
lcnr
48e119ef5a stepping into impls for norm is unproductive 2025-04-16 10:35:09 +02:00
bors
f433fa46b0 Auto merge of #139845 - Zalathar:rollup-u5u5y1v, r=Zalathar
Rollup of 17 pull requests

Successful merges:

 - #138374 (Enable contracts for const functions)
 - #138380 (ci: add runners for vanilla LLVM 20)
 - #138393 (Allow const patterns of matches to contain pattern types)
 - #139517 (std: sys: process: uefi: Use NULL stdin by default)
 - #139554 (std: add Output::exit_ok)
 - #139660 (compiletest: Add an experimental new executor to replace libtest)
 - #139669 (Overhaul `AssocItem`)
 - #139671 (Proc macro span API redesign: Replace proc_macro::SourceFile by Span::{file, local_file})
 - #139750 (std/thread: Use default stack size from menuconfig for NuttX)
 - #139772 (Remove `hir::Map`)
 - #139785 (Let CStrings be either 1 or 2 byte aligned.)
 - #139789 (do not unnecessarily leak auto traits in item bounds)
 - #139791 (drop global where-bounds before merging candidates)
 - #139798 (normalize: prefer `ParamEnv` over `AliasBound` candidates)
 - #139822 (Fix: Map EOPNOTSUPP to ErrorKind::Unsupported on Unix)
 - #139833 (Fix some HIR pretty-printing problems)
 - #139836 (Basic tests of MPMC receiver cloning)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-15 08:02:23 +00:00
Stuart Cook
b21c5cd025
Rollup merge of #139798 - lcnr:where-bounds-gt-alias-bound, r=compiler-errors
normalize: prefer `ParamEnv` over `AliasBound` candidates

cc https://github.com/rust-lang/trait-system-refactor-initiative/issues/175 not the only issue affecting bevy sadly

r? ``@compiler-errors``
2025-04-15 15:47:30 +10:00
Stuart Cook
e8c9dcc79e
Rollup merge of #139791 - lcnr:ignore-global-where-bounds, r=compiler-errors
drop global where-bounds before merging candidates

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

r? ```@compiler-errors```
2025-04-15 15:47:30 +10:00
Yotam Ofek
4b63362f3d Use newtype_index!-generated types more idiomatically 2025-04-14 16:17:06 +00:00
lcnr
9c88eb6c43 normalize: prefer ParamEnv over AliasBound 2025-04-14 14:46:48 +02:00
lcnr
ce9d8678ca do not leak auto traits in item bounds 2025-04-14 13:26:13 +02:00
lcnr
2c2c9df653 drop global where-bounds before merging candidates 2025-04-14 12:59:22 +02:00
bors
9d28fe3976 Auto merge of #139000 - compiler-errors:rigid-missing-item, r=lcnr
Rigidly project missing item due to guaranteed impossible sized predicate

This is a somewhat involved change, but it amounts to treating missing impl items due to guaranteed impossible where clauses (dyn/str/slice sized, cc #135480) as *rigid projections* rather than projecting to an error term, since that was preventing either reporting a proper error (in an empty param env) *or* successfully type checking the code (in the presence of trivially false where clauses).

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

r? `@lcnr` `@oli-obk`
2025-04-10 04:03:59 +00:00
Michael Goulet
6cd724bb43 Make unnormalizable item ambiguous in coherence 2025-04-09 20:31:58 +00:00
Michael Goulet
830aeb6102 Use a query rather than recomputing the tail repeatedly 2025-04-09 20:26:58 +00:00
Michael Goulet
ccdfd310be Mark GAT WC as GoalSource::AliasWellFormed so that we recurse into them in error reporting 2025-04-09 20:26:57 +00:00