rust/tests/ui/coherence
bors 9ab0749ce3 Auto merge of #112875 - compiler-errors:negative-coherence-rework, r=lcnr
Rework negative coherence to properly consider impls that only partly overlap

This PR implements a modified negative coherence that handles impls that only have partial overlap.

It does this by:
1. taking both impl trait refs, instantiating them with infer vars
2. equating both trait refs
3. taking the equated trait ref (which represents the two impls' intersection), and resolving any vars
4. plugging all remaining infer vars with placeholder types

these placeholder-plugged trait refs can then be used normally with the new trait solver, since we no longer have to worry about the issue with infer vars in param-envs.

We use the **new trait solver** to reason correctly about unnormalized trait refs (due to deferred projection equality), since this avoid having to normalize anything under param-envs with infer vars in them.

This PR then additionally:
* removes the `FnPtr` knowable hack by implementing proper negative `FnPtr` trait bounds for rigid types.

---

An example:

Consider these two partially overlapping impls:

```
impl<T, U> PartialEq<&U> for &T where T: PartialEq<U> {}
impl<F> PartialEq<F> for F where F: FnPtr {}
```

Under the old algorithm, we would take one of these impls and replace it with infer vars, then try unifying it with the other impl under identity substitutions. This is not possible in either direction, since it either sets `T = U`, or tries to equate `F = &?0`.

Under the new algorithm, we try to unify `?0: PartialEq<?0>` with `&?1: PartialEq<&?2>`. This gives us `?0 = &?1 = &?2` and thus `?1 = ?2`. The intersection of these two trait refs therefore looks like: `&?1: PartialEq<&?1>`. After plugging this with placeholders, we get a trait ref that looks like `&!0: PartialEq<&!0>`, with the first impl having substs `?T = ?U = !0` and the second having substs `?F = &!0`[^1].

Then we can take the param-env from the first impl, and try to prove the negated where clause of the second.

We know that `&!0: !FnPtr` never holds, since it's a rigid type that is also not a fn ptr, we successfully detect that these impls may never overlap.

[^1]: For the purposes of this example, I just ignored lifetimes, since it doesn't really matter.
2023-10-26 10:57:21 +00:00
..
auxiliary
coherence_copy_like_err_fundamental_struct_ref.rs
coherence_copy_like_err_fundamental_struct_tuple.rs
coherence_copy_like_err_fundamental_struct_tuple.stderr
coherence_copy_like_err_fundamental_struct.rs
coherence_copy_like_err_struct.rs
coherence_copy_like_err_struct.stderr
coherence_copy_like_err_tuple.rs
coherence_copy_like_err_tuple.stderr
coherence_copy_like.rs
coherence_inherent_cc.rs
coherence_inherent_cc.stderr
coherence_inherent.rs
coherence_inherent.stderr
coherence_local_err_struct.rs
coherence_local_err_struct.stderr
coherence_local_err_tuple.rs
coherence_local_err_tuple.stderr
coherence_local_ref.rs
coherence_local.rs
coherence-all-remote.rs
coherence-all-remote.stderr
coherence-bigint-int.rs
coherence-bigint-param.rs
coherence-bigint-param.stderr
coherence-bigint-vecint.rs
coherence-blanket-conflicts-with-blanket-implemented.rs
coherence-blanket-conflicts-with-blanket-implemented.stderr
coherence-blanket-conflicts-with-blanket-unimplemented.rs
coherence-blanket-conflicts-with-blanket-unimplemented.stderr
coherence-blanket-conflicts-with-specific-cross-crate.rs
coherence-blanket-conflicts-with-specific-cross-crate.stderr
coherence-blanket-conflicts-with-specific-multidispatch.rs
coherence-blanket-conflicts-with-specific-multidispatch.stderr
coherence-blanket-conflicts-with-specific-trait.rs
coherence-blanket-conflicts-with-specific-trait.stderr
coherence-blanket-conflicts-with-specific.rs
coherence-blanket-conflicts-with-specific.stderr
coherence-blanket.rs
coherence-conflicting-negative-trait-impl.rs
coherence-conflicting-negative-trait-impl.stderr
coherence-covered-type-parameter.rs
coherence-cow.re_a.stderr
coherence-cow.re_b.stderr
coherence-cow.re_c.stderr
coherence-cow.rs
coherence-cross-crate-conflict.rs
coherence-cross-crate-conflict.stderr
coherence-default-trait-impl.rs
coherence-default-trait-impl.stderr
coherence-doesnt-use-infcx-evaluate.rs
coherence-doesnt-use-infcx-evaluate.stderr
coherence-error-suppression.rs
coherence-error-suppression.stderr
coherence-fn-covariant-bound-vs-static.rs
coherence-fn-covariant-bound-vs-static.stderr
coherence-fn-implied-bounds.rs
coherence-fn-implied-bounds.stderr
coherence-fn-inputs.rs
coherence-fn-inputs.stderr
coherence-free-vs-bound-region.rs
coherence-free-vs-bound-region.stderr
coherence-fundamental-trait-objects.rs
coherence-fundamental-trait-objects.stderr
coherence-impl-in-fn.rs
coherence-impl-trait-for-marker-trait-negative.rs
coherence-impl-trait-for-marker-trait-negative.stderr
coherence-impl-trait-for-marker-trait-positive.rs
coherence-impl-trait-for-marker-trait-positive.stderr
coherence-impl-trait-for-trait-object-safe.rs Work around the fact that check_mod_type_wf may spuriously return ErrorGuaranteed, even if that error is only emitted by check_modwitem_types 2023-10-25 12:04:54 +00:00
coherence-impl-trait-for-trait-object-safe.stderr Work around the fact that check_mod_type_wf may spuriously return ErrorGuaranteed, even if that error is only emitted by check_modwitem_types 2023-10-25 12:04:54 +00:00
coherence-impl-trait-for-trait.rs
coherence-impl-trait-for-trait.stderr
coherence-impls-copy.rs
coherence-impls-copy.stderr
coherence-impls-send.rs
coherence-impls-send.stderr
coherence-impls-sized.rs
coherence-impls-sized.stderr
coherence-inherited-assoc-ty-cycle-err.rs
coherence-inherited-assoc-ty-cycle-err.stderr moved note as unspanned note, moved note to the bottom of the msg 2023-07-18 21:53:34 -04:00
coherence-inherited-subtyping.rs
coherence-inherited-subtyping.stderr
coherence-iterator-vec-any-elem.rs
coherence-iterator-vec.rs
coherence-lone-type-parameter.rs
coherence-lone-type-parameter.stderr
coherence-multidispatch-tuple.rs
coherence-negative-impls-copy-bad.rs
coherence-negative-impls-copy-bad.stderr
coherence-negative-impls-copy.rs
coherence-negative-impls-safe-rpass.rs
coherence-negative-impls-safe.rs
coherence-negative-impls-safe.stderr
coherence-negative-inherent-where-bounds.rs
coherence-negative-inherent.rs
coherence-negative-outlives-lifetimes.rs coherence doesn't like region constraints 2023-10-23 23:35:27 +00:00
coherence-negative-outlives-lifetimes.stock.stderr
coherence-negative-outlives-lifetimes.with_negative_coherence.stderr coherence doesn't like region constraints 2023-10-23 23:35:27 +00:00
coherence-no-direct-lifetime-dispatch.rs
coherence-no-direct-lifetime-dispatch.stderr
coherence-orphan.rs
coherence-orphan.stderr
coherence-overlap-all-t-and-tuple.rs
coherence-overlap-all-t-and-tuple.stderr
coherence-overlap-double-negative.rs
coherence-overlap-downstream-inherent.next.stderr update tests 2023-09-21 08:17:58 +02:00
coherence-overlap-downstream-inherent.old.stderr update tests 2023-09-21 08:17:58 +02:00
coherence-overlap-downstream-inherent.rs update tests 2023-09-21 08:17:58 +02:00
coherence-overlap-downstream.next.stderr Extend impl's def_span to include where clauses 2023-10-09 11:47:02 +00:00
coherence-overlap-downstream.old.stderr Extend impl's def_span to include where clauses 2023-10-09 11:47:02 +00:00
coherence-overlap-downstream.rs update tests 2023-09-21 08:17:58 +02:00
coherence-overlap-issue-23516-inherent.next.stderr update tests 2023-09-21 08:17:58 +02:00
coherence-overlap-issue-23516-inherent.old.stderr update tests 2023-09-21 08:17:58 +02:00
coherence-overlap-issue-23516-inherent.rs update tests 2023-09-21 08:17:58 +02:00
coherence-overlap-issue-23516.next.stderr update tests 2023-09-21 08:17:58 +02:00
coherence-overlap-issue-23516.old.stderr update tests 2023-09-21 08:17:58 +02:00
coherence-overlap-issue-23516.rs update tests 2023-09-21 08:17:58 +02:00
coherence-overlap-messages.rs
coherence-overlap-messages.stderr
coherence-overlap-negate-alias-strict.rs
coherence-overlap-negate-not-use-feature-gate.rs
coherence-overlap-negate-not-use-feature-gate.stderr
coherence-overlap-negate-strict.rs
coherence-overlap-negate-use-feature-gate.rs
coherence-overlap-negative-impls.rs
coherence-overlap-negative-trait2.rs
coherence-overlap-negative-trait.rs
coherence-overlap-super-negative.rs
coherence-overlap-trait-alias.rs Make things work by using the new solver 2023-10-23 23:35:27 +00:00
coherence-overlap-trait-alias.stderr Make things work by using the new solver 2023-10-23 23:35:27 +00:00
coherence-overlap-upstream-inherent.rs
coherence-overlap-upstream-inherent.stderr
coherence-overlap-upstream.rs
coherence-overlap-upstream.stderr Extend impl's def_span to include where clauses 2023-10-09 11:47:02 +00:00
coherence-overlap-with-regions.rs nits 2023-10-23 23:35:27 +00:00
coherence-overlap-with-regions.stderr coherence doesn't like region constraints 2023-10-23 23:35:27 +00:00
coherence-overlapping-pairs.rs
coherence-overlapping-pairs.stderr
coherence-pair-covered-uncovered-1.rs
coherence-pair-covered-uncovered-1.stderr
coherence-pair-covered-uncovered.rs
coherence-pair-covered-uncovered.stderr
coherence-projection-conflict-orphan.rs
coherence-projection-conflict-orphan.stderr
coherence-projection-conflict-ty-param.rs
coherence-projection-conflict-ty-param.stderr
coherence-projection-conflict.rs
coherence-projection-conflict.stderr
coherence-projection-ok-orphan.rs
coherence-projection-ok.rs
coherence-rfc447-constrained.rs
coherence-subtyping.rs
coherence-subtyping.stderr
coherence-tuple-conflict.rs
coherence-tuple-conflict.stderr
coherence-unsafe-trait-object-impl.rs
coherence-unsafe-trait-object-impl.stderr Point out if a local trait has no implementations 2023-09-10 21:20:36 +00:00
coherence-vec-local-2.rs
coherence-vec-local-2.stderr
coherence-vec-local.rs
coherence-vec-local.stderr
coherence-wasm-bindgen.rs
coherence-wasm-bindgen.stderr Extend impl's def_span to include where clauses 2023-10-09 11:47:02 +00:00
coherence-where-clause.rs
coherence-with-closure.rs
coherence-with-closure.stderr
coherence-with-coroutine.rs Rename lots of files that had generator in their name 2023-10-20 21:14:02 +00:00
coherence-with-coroutine.stock.stderr Rename lots of files that had generator in their name 2023-10-20 21:14:02 +00:00
conflicting-impl-with-err.rs
conflicting-impl-with-err.stderr
const-generics-orphan-check-ok.rs
deep-bad-copy-reason.rs
deep-bad-copy-reason.stderr
illegal-copy-bad-projection.rs
illegal-copy-bad-projection.stderr
impl-foreign-for-foreign.rs
impl-foreign-for-foreign.stderr
impl-foreign-for-foreign[foreign].rs
impl-foreign-for-foreign[foreign].stderr
impl-foreign-for-foreign[local].rs
impl-foreign-for-fundamental[foreign].rs
impl-foreign-for-fundamental[foreign].stderr
impl-foreign-for-fundamental[local].rs
impl-foreign-for-local.rs
impl-foreign-for-locally-defined-fundamental.rs
impl-foreign-for-locally-defined-fundamental[foreign].rs
impl-foreign[foreign]-for-foreign.rs
impl-foreign[foreign]-for-foreign.stderr
impl-foreign[foreign]-for-local.rs
impl-foreign[fundemental[foreign]]-for-foreign.rs
impl-foreign[fundemental[foreign]]-for-foreign.stderr
impl-foreign[fundemental[local]]-for-foreign.rs
impl[t]-foreign-for-foreign[t].rs
impl[t]-foreign-for-foreign[t].stderr
impl[t]-foreign-for-fundamental[t].rs
impl[t]-foreign-for-fundamental[t].stderr
impl[t]-foreign[foreign[t]_local]-for-foreign.rs
impl[t]-foreign[foreign]-for-fundamental[t].rs
impl[t]-foreign[foreign]-for-fundamental[t].stderr
impl[t]-foreign[foreign]-for-t.rs
impl[t]-foreign[foreign]-for-t.stderr
impl[t]-foreign[fundamental[t]_local]-for-foreign.rs
impl[t]-foreign[fundamental[t]_local]-for-foreign.stderr
impl[t]-foreign[fundamental[t]]-for-foreign.rs
impl[t]-foreign[fundamental[t]]-for-foreign.stderr
impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs
impl[t]-foreign[fundamental[t]]-for-fundamental[t].stderr
impl[t]-foreign[fundamental[t]]-for-local.rs
impl[t]-foreign[fundamental[t]]-for-t.rs
impl[t]-foreign[fundamental[t]]-for-t.stderr
impl[t]-foreign[fundemental[local]]-for-foreign[t].rs
impl[t]-foreign[local_fundamental[t]]-for-foreign.rs
impl[t]-foreign[local]-for-foreign.rs
impl[t]-foreign[local]-for-foreign[t].rs
impl[t]-foreign[local]-for-fundamental[foreign[t]].rs
impl[t]-foreign[local]-for-fundamental[t].rs
impl[t]-foreign[local]-for-fundamental[t].stderr
impl[t]-foreign[local]-for-local.rs
impl[t]-foreign[local]-for-t.rs
impl[t]-foreign[local]-for-t.stderr
impl[t]-foreign[t]-for-foreign.rs
impl[t]-foreign[t]-for-foreign.stderr
impl[t]-foreign[t]-for-fundamental.rs
impl[t]-foreign[t]-for-fundamental.stderr
impl[t]-foreign[t]-for-local.rs
impl[t]-foreign[t]-for-t.rs
impl[t]-foreign[t]-for-t.stderr
indirect-impl-for-trait-obj-coherence.rs
inter-crate-ambiguity-causes-notes.next.stderr Extend impl's def_span to include where clauses 2023-10-09 11:47:02 +00:00
inter-crate-ambiguity-causes-notes.old.stderr Extend impl's def_span to include where clauses 2023-10-09 11:47:02 +00:00
inter-crate-ambiguity-causes-notes.rs update tests 2023-09-21 08:17:58 +02:00
issue-85026.rs
issue-85026.stderr
issue-99663-2.rs
issue-99663.rs
negative-coherence-considering-regions.any_lt.stderr Consider regions 2023-10-23 23:35:27 +00:00
negative-coherence-considering-regions.rs nits 2023-10-23 23:35:27 +00:00
negative-coherence-considering-regions.static_lt.stderr coherence doesn't like region constraints 2023-10-23 23:35:27 +00:00
re-rebalance-coherence-default-generic-associated-type.rs
re-rebalance-coherence.rs
strict-coherence-needs-negative-coherence.rs
strict-coherence-needs-negative-coherence.stderr
warn-when-cycle-is-error-in-coherence.rs more nits 2023-08-15 03:44:21 +00:00
warn-when-cycle-is-error-in-coherence.stderr Bump COINDUCTIVE_OVERLAP_IN_COHERENCE 2023-10-18 18:54:11 +00:00