From 9918693037dce8aa4bb6f08741b6812923486c18 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 19 Jun 2024 11:26:03 +0200 Subject: Merging upstream version 1.76.0+dfsg1. Signed-off-by: Daniel Baumann --- .../traits/next-solver/alias-bound-preference.rs | 39 +++++++ tests/ui/traits/next-solver/alias-bound-unsound.rs | 32 ++++++ .../traits/next-solver/alias-bound-unsound.stderr | 65 +++++++++++ .../next-solver/alias-eq-in-canonical-response.rs | 40 +++++++ .../alias-relate/deeply-nested-no-hang.rs | 22 ++++ .../opaque-hidden-ty-is-rigid-alias.rs | 8 ++ tests/ui/traits/next-solver/alias-sub.rs | 34 ++++++ .../alias_eq_cant_be_furthur_normalized.rs | 29 +++++ ...alias_eq_dont_use_normalizes_to_if_substs_eq.rs | 47 ++++++++ tests/ui/traits/next-solver/alias_eq_simple.rs | 22 ++++ .../alias_eq_substs_eq_not_intercrate.rs | 17 +++ .../alias_eq_substs_eq_not_intercrate.stderr | 13 +++ tests/ui/traits/next-solver/array-default.rs | 8 ++ .../assemble-normalizing-self-ty-impl-ambiguity.rs | 27 +++++ .../assembly/runaway-impl-candidate-selection.rs | 15 +++ .../runaway-impl-candidate-selection.stderr | 16 +++ tests/ui/traits/next-solver/async.fail.stderr | 17 +++ tests/ui/traits/next-solver/async.rs | 19 ++++ .../auto-with-drop_tracking_mir.fail.stderr | 18 +++ .../next-solver/auto-with-drop_tracking_mir.rs | 27 +++++ tests/ui/traits/next-solver/borrowck-error.rs | 11 ++ tests/ui/traits/next-solver/borrowck-error.stderr | 12 ++ .../next-solver/builtin-fn-must-return-sized.rs | 17 +++ .../builtin-fn-must-return-sized.stderr | 16 +++ .../canonical-int-var-eq-in-response.rs | 22 ++++ .../next-solver/canonical-ty-var-eq-in-response.rs | 39 +++++++ .../traits/next-solver/canonicalize-effect-var.rs | 22 ++++ .../cast-checks-handling-projections.rs | 6 + .../next-solver/closure-inference-guidance.rs | 11 ++ .../next-solver/closure-signature-inference-2.rs | 21 ++++ .../next-solver/closure-signature-inference.rs | 15 +++ .../traits/next-solver/closure-substs-ambiguity.rs | 7 ++ .../coerce-ambig-alias-to-rigid-alias.rs | 15 +++ .../traits/next-solver/coherence/issue-102048.rs | 44 +++++++ .../next-solver/coherence/issue-102048.stderr | 16 +++ .../trait_ref_is_knowable-norm-overflow.rs | 20 ++++ .../trait_ref_is_knowable-norm-overflow.stderr | 12 ++ .../trait_ref_is_knowable-normalization-1.rs | 22 ++++ .../trait_ref_is_knowable-normalization-2.rs | 25 ++++ .../trait_ref_is_knowable-normalization-3.rs | 24 ++++ .../const-param-placeholder.fail.stderr | 16 +++ .../traits/next-solver/const-param-placeholder.rs | 21 ++++ tests/ui/traits/next-solver/coroutine.fail.stderr | 64 +++++++++++ tests/ui/traits/next-solver/coroutine.rs | 32 ++++++ .../coinduction/fixpoint-exponential-growth.rs | 35 ++++++ .../coinduction/fixpoint-exponential-growth.stderr | 16 +++ .../coinduction/incompleteness-unstable-result.rs | 69 +++++++++++ .../incompleteness-unstable-result.stderr | 16 +++ .../cycles/double-cycle-inductive-coinductive.rs | 37 ++++++ .../double-cycle-inductive-coinductive.stderr | 29 +++++ .../cycles/fixpoint-rerun-all-cycle-heads.rs | 53 +++++++++ .../cycles/fixpoint-rerun-all-cycle-heads.stderr | 10 ++ .../next-solver/cycles/inductive-cycle-but-err.rs | 48 ++++++++ .../cycles/inductive-cycle-but-err.stderr | 16 +++ .../next-solver/cycles/inductive-cycle-but-ok.rs | 44 +++++++ ...tive-cycle-discarded-coinductive-constraints.rs | 36 ++++++ .../next-solver/cycles/inductive-fixpoint-hang.rs | 33 ++++++ .../cycles/inductive-fixpoint-hang.stderr | 16 +++ .../next-solver/cycles/inductive-not-on-stack.rs | 46 ++++++++ .../cycles/inductive-not-on-stack.stderr | 29 +++++ .../cycles/leak-check-coinductive-cycle.rs | 33 ++++++ .../next-solver/cycles/provisional-result-done.rs | 33 ++++++ ...deduce-closure-signature-after-normalization.rs | 10 ++ .../ui/traits/next-solver/deduce-ty-from-object.rs | 6 + tests/ui/traits/next-solver/dedup-regions.rs | 31 +++++ tests/ui/traits/next-solver/destruct.rs | 13 +++ .../traits/next-solver/dont-coerce-infer-to-dyn.rs | 17 +++ .../next-solver/dont-elaborate-for-projections.rs | 12 ++ .../next-solver/dont-ice-on-assoc-projection.rs | 19 ++++ .../dont-ice-on-assoc-projection.stderr | 21 ++++ .../dont-loop-fulfill-on-region-constraints.rs | 32 ++++++ .../next-solver/dont-normalize-proj-with-error.rs | 22 ++++ .../dont-normalize-proj-with-error.stderr | 9 ++ .../traits/next-solver/dont-remap-tait-substs.rs | 19 ++++ ...-type_of-tait-in-defining-scope.not_send.stderr | 16 +++ .../dont-type_of-tait-in-defining-scope.rs | 24 ++++ .../traits/next-solver/dyn-any-dont-prefer-impl.rs | 17 +++ .../ui/traits/next-solver/elaborate-item-bounds.rs | 12 ++ .../next-solver/equating-projection-cyclically.rs | 31 +++++ ...caping-bound-vars-in-writeback-normalization.rs | 18 +++ tests/ui/traits/next-solver/float-canonical.rs | 8 ++ tests/ui/traits/next-solver/fn-trait-closure.rs | 8 ++ tests/ui/traits/next-solver/fn-trait.rs | 32 ++++++ tests/ui/traits/next-solver/fn-trait.stderr | 126 +++++++++++++++++++++ .../generalize-proj-new-universe-index-1.rs | 73 ++++++++++++ .../generalize-proj-new-universe-index-2.rs | 75 ++++++++++++ .../generalize-proj-new-universe-index-2.stderr | 19 ++++ .../occurs-check-nested-alias.next.stderr | 11 ++ .../generalize/occurs-check-nested-alias.rs | 38 +++++++ .../traits/next-solver/higher-ranked-dyn-bounds.rs | 17 +++ tests/ui/traits/next-solver/int-var-alias-eq.rs | 18 +++ tests/ui/traits/next-solver/int-var-is-send.rs | 8 ++ .../traits/next-solver/issue-118950-root-region.rs | 22 ++++ .../next-solver/issue-118950-root-region.stderr | 36 ++++++ .../traits/next-solver/iter-filter-projection.rs | 12 ++ .../next-solver/lazy-nested-obligations-1.rs | 13 +++ .../next-solver/lazy-nested-obligations-2.rs | 22 ++++ .../next-solver/lazy-nested-obligations-3.rs | 38 +++++++ .../member-constraints-in-root-universe.rs | 17 +++ tests/ui/traits/next-solver/more-object-bound.rs | 27 +++++ .../ui/traits/next-solver/more-object-bound.stderr | 22 ++++ .../next-solver/negative-coherence-bounds.rs | 40 +++++++ .../next-solver/negative-coherence-bounds.stderr | 12 ++ tests/ui/traits/next-solver/nested-alias-bound.rs | 20 ++++ .../nested-obligations-with-bound-vars-gat.rs | 43 +++++++ .../normalize-async-closure-in-trait.rs | 9 ++ .../ui/traits/next-solver/normalize-param-env-1.rs | 40 +++++++ .../ui/traits/next-solver/normalize-param-env-2.rs | 26 +++++ .../ui/traits/next-solver/normalize-param-env-3.rs | 32 ++++++ .../next-solver/normalize-rcvr-for-inherent.rs | 25 ++++ .../ui/traits/next-solver/normalize-unsize-rhs.rs | 22 ++++ .../next-solver/normalized-const-built-in-op.rs | 11 ++ ...rmalizes_to_ignores_unnormalizable_candidate.rs | 40 +++++++ ...ores_unnormalizable_candidate.self_infer.stderr | 22 ++++ .../object-soundness-requires-generalization.rs | 20 ++++ tests/ui/traits/next-solver/object-unsafety.rs | 27 +++++ tests/ui/traits/next-solver/object-unsafety.stderr | 64 +++++++++++ .../next-solver/opportunistic-region-resolve.rs | 19 ++++ .../overflow/exponential-trait-goals.rs | 19 ++++ .../overflow/exponential-trait-goals.stderr | 16 +++ .../ui/traits/next-solver/overflow/global-cache.rs | 23 ++++ .../next-solver/overflow/global-cache.stderr | 16 +++ .../recursion-limit-normalizes-to-constraints.rs | 25 ++++ .../overflow/recursion-limit-zero-issue-115351.rs | 12 ++ .../recursion-limit-zero-issue-115351.stderr | 27 +++++ .../overflow/recursive-self-normalization-2.rs | 20 ++++ .../overflow/recursive-self-normalization-2.stderr | 24 ++++ .../overflow/recursive-self-normalization.rs | 16 +++ .../overflow/recursive-self-normalization.stderr | 24 ++++ .../param-candidate-doesnt-shadow-project.rs | 25 ++++ tests/ui/traits/next-solver/param-discr-kind.rs | 8 ++ tests/ui/traits/next-solver/pointee.rs | 21 ++++ tests/ui/traits/next-solver/pointer-like.rs | 14 +++ tests/ui/traits/next-solver/pointer-like.stderr | 24 ++++ .../next-solver/prefer-candidate-no-constraints.rs | 22 ++++ .../next-solver/prefer-param-env-on-ambiguity.rs | 10 ++ .../ui/traits/next-solver/projection-discr-kind.rs | 18 +++ .../next-solver/projection-discr-kind.stderr | 22 ++++ .../projection/param-env-trait-candidate-1.rs | 14 +++ .../projection/param-env-trait-candidate-2.rs | 29 +++++ .../ui/traits/next-solver/slice-match-byte-lit.rs | 11 ++ .../traits/next-solver/specialization-transmute.rs | 28 +++++ .../next-solver/specialization-transmute.stderr | 26 +++++ .../next-solver/specialization-unconstrained.rs | 22 ++++ .../specialization-unconstrained.stderr | 32 ++++++ .../stall-num-var-auto-trait.fallback.stderr | 17 +++ .../traits/next-solver/stall-num-var-auto-trait.rs | 25 ++++ .../traits/next-solver/structural-resolve-field.rs | 13 +++ tests/ui/traits/next-solver/tait-eq-proj-2.rs | 23 ++++ tests/ui/traits/next-solver/tait-eq-proj.rs | 35 ++++++ tests/ui/traits/next-solver/tait-eq-tait.rs | 18 +++ tests/ui/traits/next-solver/temporary-ambiguity.rs | 22 ++++ .../trait-upcast-lhs-needs-normalization.rs | 19 ++++ tests/ui/traits/next-solver/try-example.rs | 28 +++++ ...wo-projection-param-candidates-are-ambiguous.rs | 30 +++++ ...rojection-param-candidates-are-ambiguous.stderr | 17 +++ .../unevaluated-const-impl-trait-ref.fails.stderr | 18 +++ .../unevaluated-const-impl-trait-ref.rs | 22 ++++ .../traits/next-solver/unsafe-auto-trait-impl.rs | 8 ++ .../next-solver/unsize-although-ambiguous.rs | 13 +++ tests/ui/traits/next-solver/unsize-good.rs | 25 ++++ tests/ui/traits/next-solver/upcast-right-substs.rs | 13 +++ tests/ui/traits/next-solver/upcast-wrong-substs.rs | 11 ++ .../traits/next-solver/upcast-wrong-substs.stderr | 14 +++ .../next-solver/winnow-specializing-impls.rs | 22 ++++ 165 files changed, 4008 insertions(+) create mode 100644 tests/ui/traits/next-solver/alias-bound-preference.rs create mode 100644 tests/ui/traits/next-solver/alias-bound-unsound.rs create mode 100644 tests/ui/traits/next-solver/alias-bound-unsound.stderr create mode 100644 tests/ui/traits/next-solver/alias-eq-in-canonical-response.rs create mode 100644 tests/ui/traits/next-solver/alias-relate/deeply-nested-no-hang.rs create mode 100644 tests/ui/traits/next-solver/alias-relate/opaque-hidden-ty-is-rigid-alias.rs create mode 100644 tests/ui/traits/next-solver/alias-sub.rs create mode 100644 tests/ui/traits/next-solver/alias_eq_cant_be_furthur_normalized.rs create mode 100644 tests/ui/traits/next-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.rs create mode 100644 tests/ui/traits/next-solver/alias_eq_simple.rs create mode 100644 tests/ui/traits/next-solver/alias_eq_substs_eq_not_intercrate.rs create mode 100644 tests/ui/traits/next-solver/alias_eq_substs_eq_not_intercrate.stderr create mode 100644 tests/ui/traits/next-solver/array-default.rs create mode 100644 tests/ui/traits/next-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs create mode 100644 tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.rs create mode 100644 tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr create mode 100644 tests/ui/traits/next-solver/async.fail.stderr create mode 100644 tests/ui/traits/next-solver/async.rs create mode 100644 tests/ui/traits/next-solver/auto-with-drop_tracking_mir.fail.stderr create mode 100644 tests/ui/traits/next-solver/auto-with-drop_tracking_mir.rs create mode 100644 tests/ui/traits/next-solver/borrowck-error.rs create mode 100644 tests/ui/traits/next-solver/borrowck-error.stderr create mode 100644 tests/ui/traits/next-solver/builtin-fn-must-return-sized.rs create mode 100644 tests/ui/traits/next-solver/builtin-fn-must-return-sized.stderr create mode 100644 tests/ui/traits/next-solver/canonical-int-var-eq-in-response.rs create mode 100644 tests/ui/traits/next-solver/canonical-ty-var-eq-in-response.rs create mode 100644 tests/ui/traits/next-solver/canonicalize-effect-var.rs create mode 100644 tests/ui/traits/next-solver/cast-checks-handling-projections.rs create mode 100644 tests/ui/traits/next-solver/closure-inference-guidance.rs create mode 100644 tests/ui/traits/next-solver/closure-signature-inference-2.rs create mode 100644 tests/ui/traits/next-solver/closure-signature-inference.rs create mode 100644 tests/ui/traits/next-solver/closure-substs-ambiguity.rs create mode 100644 tests/ui/traits/next-solver/coerce-ambig-alias-to-rigid-alias.rs create mode 100644 tests/ui/traits/next-solver/coherence/issue-102048.rs create mode 100644 tests/ui/traits/next-solver/coherence/issue-102048.stderr create mode 100644 tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.rs create mode 100644 tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr create mode 100644 tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-1.rs create mode 100644 tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-2.rs create mode 100644 tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-3.rs create mode 100644 tests/ui/traits/next-solver/const-param-placeholder.fail.stderr create mode 100644 tests/ui/traits/next-solver/const-param-placeholder.rs create mode 100644 tests/ui/traits/next-solver/coroutine.fail.stderr create mode 100644 tests/ui/traits/next-solver/coroutine.rs create mode 100644 tests/ui/traits/next-solver/cycles/coinduction/fixpoint-exponential-growth.rs create mode 100644 tests/ui/traits/next-solver/cycles/coinduction/fixpoint-exponential-growth.stderr create mode 100644 tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.rs create mode 100644 tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.stderr create mode 100644 tests/ui/traits/next-solver/cycles/double-cycle-inductive-coinductive.rs create mode 100644 tests/ui/traits/next-solver/cycles/double-cycle-inductive-coinductive.stderr create mode 100644 tests/ui/traits/next-solver/cycles/fixpoint-rerun-all-cycle-heads.rs create mode 100644 tests/ui/traits/next-solver/cycles/fixpoint-rerun-all-cycle-heads.stderr create mode 100644 tests/ui/traits/next-solver/cycles/inductive-cycle-but-err.rs create mode 100644 tests/ui/traits/next-solver/cycles/inductive-cycle-but-err.stderr create mode 100644 tests/ui/traits/next-solver/cycles/inductive-cycle-but-ok.rs create mode 100644 tests/ui/traits/next-solver/cycles/inductive-cycle-discarded-coinductive-constraints.rs create mode 100644 tests/ui/traits/next-solver/cycles/inductive-fixpoint-hang.rs create mode 100644 tests/ui/traits/next-solver/cycles/inductive-fixpoint-hang.stderr create mode 100644 tests/ui/traits/next-solver/cycles/inductive-not-on-stack.rs create mode 100644 tests/ui/traits/next-solver/cycles/inductive-not-on-stack.stderr create mode 100644 tests/ui/traits/next-solver/cycles/leak-check-coinductive-cycle.rs create mode 100644 tests/ui/traits/next-solver/cycles/provisional-result-done.rs create mode 100644 tests/ui/traits/next-solver/deduce-closure-signature-after-normalization.rs create mode 100644 tests/ui/traits/next-solver/deduce-ty-from-object.rs create mode 100644 tests/ui/traits/next-solver/dedup-regions.rs create mode 100644 tests/ui/traits/next-solver/destruct.rs create mode 100644 tests/ui/traits/next-solver/dont-coerce-infer-to-dyn.rs create mode 100644 tests/ui/traits/next-solver/dont-elaborate-for-projections.rs create mode 100644 tests/ui/traits/next-solver/dont-ice-on-assoc-projection.rs create mode 100644 tests/ui/traits/next-solver/dont-ice-on-assoc-projection.stderr create mode 100644 tests/ui/traits/next-solver/dont-loop-fulfill-on-region-constraints.rs create mode 100644 tests/ui/traits/next-solver/dont-normalize-proj-with-error.rs create mode 100644 tests/ui/traits/next-solver/dont-normalize-proj-with-error.stderr create mode 100644 tests/ui/traits/next-solver/dont-remap-tait-substs.rs create mode 100644 tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.not_send.stderr create mode 100644 tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.rs create mode 100644 tests/ui/traits/next-solver/dyn-any-dont-prefer-impl.rs create mode 100644 tests/ui/traits/next-solver/elaborate-item-bounds.rs create mode 100644 tests/ui/traits/next-solver/equating-projection-cyclically.rs create mode 100644 tests/ui/traits/next-solver/escaping-bound-vars-in-writeback-normalization.rs create mode 100644 tests/ui/traits/next-solver/float-canonical.rs create mode 100644 tests/ui/traits/next-solver/fn-trait-closure.rs create mode 100644 tests/ui/traits/next-solver/fn-trait.rs create mode 100644 tests/ui/traits/next-solver/fn-trait.stderr create mode 100644 tests/ui/traits/next-solver/generalize/generalize-proj-new-universe-index-1.rs create mode 100644 tests/ui/traits/next-solver/generalize/generalize-proj-new-universe-index-2.rs create mode 100644 tests/ui/traits/next-solver/generalize/generalize-proj-new-universe-index-2.stderr create mode 100644 tests/ui/traits/next-solver/generalize/occurs-check-nested-alias.next.stderr create mode 100644 tests/ui/traits/next-solver/generalize/occurs-check-nested-alias.rs create mode 100644 tests/ui/traits/next-solver/higher-ranked-dyn-bounds.rs create mode 100644 tests/ui/traits/next-solver/int-var-alias-eq.rs create mode 100644 tests/ui/traits/next-solver/int-var-is-send.rs create mode 100644 tests/ui/traits/next-solver/issue-118950-root-region.rs create mode 100644 tests/ui/traits/next-solver/issue-118950-root-region.stderr create mode 100644 tests/ui/traits/next-solver/iter-filter-projection.rs create mode 100644 tests/ui/traits/next-solver/lazy-nested-obligations-1.rs create mode 100644 tests/ui/traits/next-solver/lazy-nested-obligations-2.rs create mode 100644 tests/ui/traits/next-solver/lazy-nested-obligations-3.rs create mode 100644 tests/ui/traits/next-solver/member-constraints-in-root-universe.rs create mode 100644 tests/ui/traits/next-solver/more-object-bound.rs create mode 100644 tests/ui/traits/next-solver/more-object-bound.stderr create mode 100644 tests/ui/traits/next-solver/negative-coherence-bounds.rs create mode 100644 tests/ui/traits/next-solver/negative-coherence-bounds.stderr create mode 100644 tests/ui/traits/next-solver/nested-alias-bound.rs create mode 100644 tests/ui/traits/next-solver/nested-obligations-with-bound-vars-gat.rs create mode 100644 tests/ui/traits/next-solver/normalize-async-closure-in-trait.rs create mode 100644 tests/ui/traits/next-solver/normalize-param-env-1.rs create mode 100644 tests/ui/traits/next-solver/normalize-param-env-2.rs create mode 100644 tests/ui/traits/next-solver/normalize-param-env-3.rs create mode 100644 tests/ui/traits/next-solver/normalize-rcvr-for-inherent.rs create mode 100644 tests/ui/traits/next-solver/normalize-unsize-rhs.rs create mode 100644 tests/ui/traits/next-solver/normalized-const-built-in-op.rs create mode 100644 tests/ui/traits/next-solver/normalizes_to_ignores_unnormalizable_candidate.rs create mode 100644 tests/ui/traits/next-solver/normalizes_to_ignores_unnormalizable_candidate.self_infer.stderr create mode 100644 tests/ui/traits/next-solver/object-soundness-requires-generalization.rs create mode 100644 tests/ui/traits/next-solver/object-unsafety.rs create mode 100644 tests/ui/traits/next-solver/object-unsafety.stderr create mode 100644 tests/ui/traits/next-solver/opportunistic-region-resolve.rs create mode 100644 tests/ui/traits/next-solver/overflow/exponential-trait-goals.rs create mode 100644 tests/ui/traits/next-solver/overflow/exponential-trait-goals.stderr create mode 100644 tests/ui/traits/next-solver/overflow/global-cache.rs create mode 100644 tests/ui/traits/next-solver/overflow/global-cache.stderr create mode 100644 tests/ui/traits/next-solver/overflow/recursion-limit-normalizes-to-constraints.rs create mode 100644 tests/ui/traits/next-solver/overflow/recursion-limit-zero-issue-115351.rs create mode 100644 tests/ui/traits/next-solver/overflow/recursion-limit-zero-issue-115351.stderr create mode 100644 tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.rs create mode 100644 tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.stderr create mode 100644 tests/ui/traits/next-solver/overflow/recursive-self-normalization.rs create mode 100644 tests/ui/traits/next-solver/overflow/recursive-self-normalization.stderr create mode 100644 tests/ui/traits/next-solver/param-candidate-doesnt-shadow-project.rs create mode 100644 tests/ui/traits/next-solver/param-discr-kind.rs create mode 100644 tests/ui/traits/next-solver/pointee.rs create mode 100644 tests/ui/traits/next-solver/pointer-like.rs create mode 100644 tests/ui/traits/next-solver/pointer-like.stderr create mode 100644 tests/ui/traits/next-solver/prefer-candidate-no-constraints.rs create mode 100644 tests/ui/traits/next-solver/prefer-param-env-on-ambiguity.rs create mode 100644 tests/ui/traits/next-solver/projection-discr-kind.rs create mode 100644 tests/ui/traits/next-solver/projection-discr-kind.stderr create mode 100644 tests/ui/traits/next-solver/projection/param-env-trait-candidate-1.rs create mode 100644 tests/ui/traits/next-solver/projection/param-env-trait-candidate-2.rs create mode 100644 tests/ui/traits/next-solver/slice-match-byte-lit.rs create mode 100644 tests/ui/traits/next-solver/specialization-transmute.rs create mode 100644 tests/ui/traits/next-solver/specialization-transmute.stderr create mode 100644 tests/ui/traits/next-solver/specialization-unconstrained.rs create mode 100644 tests/ui/traits/next-solver/specialization-unconstrained.stderr create mode 100644 tests/ui/traits/next-solver/stall-num-var-auto-trait.fallback.stderr create mode 100644 tests/ui/traits/next-solver/stall-num-var-auto-trait.rs create mode 100644 tests/ui/traits/next-solver/structural-resolve-field.rs create mode 100644 tests/ui/traits/next-solver/tait-eq-proj-2.rs create mode 100644 tests/ui/traits/next-solver/tait-eq-proj.rs create mode 100644 tests/ui/traits/next-solver/tait-eq-tait.rs create mode 100644 tests/ui/traits/next-solver/temporary-ambiguity.rs create mode 100644 tests/ui/traits/next-solver/trait-upcast-lhs-needs-normalization.rs create mode 100644 tests/ui/traits/next-solver/try-example.rs create mode 100644 tests/ui/traits/next-solver/two-projection-param-candidates-are-ambiguous.rs create mode 100644 tests/ui/traits/next-solver/two-projection-param-candidates-are-ambiguous.stderr create mode 100644 tests/ui/traits/next-solver/unevaluated-const-impl-trait-ref.fails.stderr create mode 100644 tests/ui/traits/next-solver/unevaluated-const-impl-trait-ref.rs create mode 100644 tests/ui/traits/next-solver/unsafe-auto-trait-impl.rs create mode 100644 tests/ui/traits/next-solver/unsize-although-ambiguous.rs create mode 100644 tests/ui/traits/next-solver/unsize-good.rs create mode 100644 tests/ui/traits/next-solver/upcast-right-substs.rs create mode 100644 tests/ui/traits/next-solver/upcast-wrong-substs.rs create mode 100644 tests/ui/traits/next-solver/upcast-wrong-substs.stderr create mode 100644 tests/ui/traits/next-solver/winnow-specializing-impls.rs (limited to 'tests/ui/traits/next-solver') diff --git a/tests/ui/traits/next-solver/alias-bound-preference.rs b/tests/ui/traits/next-solver/alias-bound-preference.rs new file mode 100644 index 000000000..1c6e12096 --- /dev/null +++ b/tests/ui/traits/next-solver/alias-bound-preference.rs @@ -0,0 +1,39 @@ +// revisions: old next +//[next] compile-flags: -Znext-solver +// run-pass + +// A test for https://github.com/rust-lang/trait-system-refactor-initiative/issues/45. + +trait Trait { + type Assoc: Into; +} +impl> Trait for T { + type Assoc = T; +} +fn prefer_alias_bound_projection(x: T::Assoc) { + // There are two possible types for `x`: + // - `u32` by using the "alias bound" of `::Assoc` + // - `::Assoc`, i.e. `u16`, by using `impl From for T` + // + // We infer the type of `x` to be `u32` here as it is highly likely + // that this is expected by the user. + let x = x.into(); + assert_eq!(std::mem::size_of_val(&x), 4); +} + +fn impl_trait() -> impl Into { + 0u16 +} + +fn main() { + // There are two possible types for `x`: + // - `u32` by using the "alias bound" of `impl Into` + // - `impl Into`, i.e. `u16`, by using `impl From for T` + // + // We infer the type of `x` to be `u32` here as it is highly likely + // that this is expected by the user. + let x = impl_trait().into(); + assert_eq!(std::mem::size_of_val(&x), 4); + + prefer_alias_bound_projection::(1); +} diff --git a/tests/ui/traits/next-solver/alias-bound-unsound.rs b/tests/ui/traits/next-solver/alias-bound-unsound.rs new file mode 100644 index 000000000..4e279a84a --- /dev/null +++ b/tests/ui/traits/next-solver/alias-bound-unsound.rs @@ -0,0 +1,32 @@ +// compile-flags: -Znext-solver + +// Makes sure that alias bounds are not unsound! + +#![feature(trivial_bounds)] + +trait Foo { + type Item: Copy + where + ::Item: Copy; + + fn copy_me(x: &Self::Item) -> Self::Item { + *x + } +} + +impl Foo for () { + type Item = String where String: Copy; + //~^ ERROR overflow evaluating the requirement `<() as Foo>::Item: Copy` +} + +fn main() { + let x = String::from("hello, world"); + drop(<() as Foo>::copy_me(&x)); + //~^ ERROR overflow evaluating the requirement `<() as Foo>::Item: Sized` + //~| ERROR overflow evaluating the requirement `<() as Foo>::Item == _` + //~| ERROR overflow evaluating the requirement `<() as Foo>::Item well-formed` + //~| ERROR overflow evaluating the requirement `String <: <() as Foo>::Item` + //~| ERROR overflow evaluating the requirement `&<() as Foo>::Item well-formed` + //~| ERROR overflow evaluating the requirement `<() as Foo>::Item normalizes-to _` + println!("{x}"); +} diff --git a/tests/ui/traits/next-solver/alias-bound-unsound.stderr b/tests/ui/traits/next-solver/alias-bound-unsound.stderr new file mode 100644 index 000000000..ac3f19b3f --- /dev/null +++ b/tests/ui/traits/next-solver/alias-bound-unsound.stderr @@ -0,0 +1,65 @@ +error[E0275]: overflow evaluating the requirement `<() as Foo>::Item: Copy` + --> $DIR/alias-bound-unsound.rs:18:17 + | +LL | type Item = String where String: Copy; + | ^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`) +note: required by a bound in `Foo::Item` + --> $DIR/alias-bound-unsound.rs:8:16 + | +LL | type Item: Copy + | ^^^^ required by this bound in `Foo::Item` + +error[E0275]: overflow evaluating the requirement `String <: <() as Foo>::Item` + --> $DIR/alias-bound-unsound.rs:24:31 + | +LL | drop(<() as Foo>::copy_me(&x)); + | ^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`) + +error[E0275]: overflow evaluating the requirement `<() as Foo>::Item == _` + --> $DIR/alias-bound-unsound.rs:24:10 + | +LL | drop(<() as Foo>::copy_me(&x)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`) + +error[E0275]: overflow evaluating the requirement `<() as Foo>::Item: Sized` + --> $DIR/alias-bound-unsound.rs:24:10 + | +LL | drop(<() as Foo>::copy_me(&x)); + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`) + = note: the return type of a function must have a statically known size + +error[E0275]: overflow evaluating the requirement `&<() as Foo>::Item well-formed` + --> $DIR/alias-bound-unsound.rs:24:31 + | +LL | drop(<() as Foo>::copy_me(&x)); + | ^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`) + +error[E0275]: overflow evaluating the requirement `<() as Foo>::Item well-formed` + --> $DIR/alias-bound-unsound.rs:24:10 + | +LL | drop(<() as Foo>::copy_me(&x)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`) + +error[E0275]: overflow evaluating the requirement `<() as Foo>::Item normalizes-to _` + --> $DIR/alias-bound-unsound.rs:24:10 + | +LL | drop(<() as Foo>::copy_me(&x)); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`) + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/next-solver/alias-eq-in-canonical-response.rs b/tests/ui/traits/next-solver/alias-eq-in-canonical-response.rs new file mode 100644 index 000000000..aa7c94791 --- /dev/null +++ b/tests/ui/traits/next-solver/alias-eq-in-canonical-response.rs @@ -0,0 +1,40 @@ +// check-pass +// compile-flags: -Znext-solver + +trait Foo { + type Gat<'a> + where + Self: 'a; + fn bar(&self) -> Self::Gat<'_>; +} + +enum Option { + Some(T), + None, +} + +impl Option { + fn as_ref(&self) -> Option<&T> { + match self { + Option::Some(t) => Option::Some(t), + Option::None => Option::None, + } + } + + fn map(self, f: impl FnOnce(T) -> U) -> Option { + match self { + Option::Some(t) => Option::Some(f(t)), + Option::None => Option::None, + } + } +} + +impl Foo for Option { + type Gat<'a> = Option<::Gat<'a>> where Self: 'a; + + fn bar(&self) -> Self::Gat<'_> { + self.as_ref().map(Foo::bar) + } +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/alias-relate/deeply-nested-no-hang.rs b/tests/ui/traits/next-solver/alias-relate/deeply-nested-no-hang.rs new file mode 100644 index 000000000..91cfda37a --- /dev/null +++ b/tests/ui/traits/next-solver/alias-relate/deeply-nested-no-hang.rs @@ -0,0 +1,22 @@ +// check-pass +// compile-flags: -Znext-solver +// regression test for trait-system-refactor-initiative#68 +trait Identity { + type Assoc: ?Sized; +} + +impl Identity for T { + type Assoc = T; +} + +type Id = ::Assoc; + +type Five = Id>>>>; +type Ty = Five>>>>; + +trait Trait {} + +impl Trait for Ty {} +impl Trait for Ty {} + +fn main() {} diff --git a/tests/ui/traits/next-solver/alias-relate/opaque-hidden-ty-is-rigid-alias.rs b/tests/ui/traits/next-solver/alias-relate/opaque-hidden-ty-is-rigid-alias.rs new file mode 100644 index 000000000..88bbd13f9 --- /dev/null +++ b/tests/ui/traits/next-solver/alias-relate/opaque-hidden-ty-is-rigid-alias.rs @@ -0,0 +1,8 @@ +// check-pass +// compile-flags: -Znext-solver + +fn test(x: T::Item) -> impl Sized { + x +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/alias-sub.rs b/tests/ui/traits/next-solver/alias-sub.rs new file mode 100644 index 000000000..f7f23a024 --- /dev/null +++ b/tests/ui/traits/next-solver/alias-sub.rs @@ -0,0 +1,34 @@ +// compile-flags: -Znext-solver +// check-pass + +trait Trait { + type Assoc: Sized; +} + +impl Trait for &'static str { + type Assoc = &'static str; +} + +// Wrapper is just here to get around stupid `Sized` obligations in mir typeck +struct Wrapper(std::marker::PhantomData); +fn mk(x: T) -> Wrapper<::Assoc> { todo!() } + + +trait IsStaticStr {} +impl IsStaticStr for (&'static str,) {} +fn define(_: T) {} + +fn foo<'a, T: Trait>() { + let y = Default::default(); + + // `::Assoc <: &'a str` + // In the old solver, this would *equate* the LHS and RHS. + let _: Wrapper<&'a str> = mk(y); + + // ... then later on, we constrain `?0 = &'static str` + // but that should not mean that `'a = 'static`, because + // we should use *sub* above. + define((y,)); +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/alias_eq_cant_be_furthur_normalized.rs b/tests/ui/traits/next-solver/alias_eq_cant_be_furthur_normalized.rs new file mode 100644 index 000000000..04d1b9496 --- /dev/null +++ b/tests/ui/traits/next-solver/alias_eq_cant_be_furthur_normalized.rs @@ -0,0 +1,29 @@ +// check-pass +// compile-flags: -Znext-solver + +// check that a goal such as `alias-eq(::Assoc, ::Assoc)` +// succeeds with a constraint that `?0 = bool` + +// FIXME(deferred_projection_equality): add a test that this is true during coherence + +trait TraitA {} + +trait TraitB { + type Assoc; +} + +impl TraitA for (T, T::Assoc) {} + +impl TraitB for i32 { + type Assoc = u32; +} + +fn needs_a() {} + +fn bar() { + needs_a::<(T, ::Assoc<_>)>(); +} + +fn main() { + bar::(); +} diff --git a/tests/ui/traits/next-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.rs b/tests/ui/traits/next-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.rs new file mode 100644 index 000000000..48157192a --- /dev/null +++ b/tests/ui/traits/next-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.rs @@ -0,0 +1,47 @@ +// compile-flags: -Znext-solver + +// check-pass +// (should not pass, should be turned into a coherence-only test) + +// check that when computing `alias-eq(<() as Foo>::Assoc, <() as Foo>::Assoc)` +// we do not infer `?0 = u8` via the `for (): Foo` impl or `?0 = u16` by +// relating substs as either could be a valid solution. + +trait Foo { + type Assoc; +} + +impl Foo for () +where + (): Foo, +{ + type Assoc = <() as Foo>::Assoc; +} + +impl Foo for () { + type Assoc = u8; +} + +impl Foo for () { + type Assoc = u16; +} + +fn output() -> <() as Foo>::Assoc +where + (): Foo, +{ + todo!() +} + +fn incomplete() +where + (): Foo, +{ + // `<() as Foo>::Assoc == <() as Foo<_, STOP>>::Assoc` + let _: <() as Foo>::Assoc = output::<_, T>(); + + // let _: <() as Foo>::Assoc = output::(); // OK + // let _: <() as Foo>::Assoc = output::(); // OK +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/alias_eq_simple.rs b/tests/ui/traits/next-solver/alias_eq_simple.rs new file mode 100644 index 000000000..21ad1a4fa --- /dev/null +++ b/tests/ui/traits/next-solver/alias_eq_simple.rs @@ -0,0 +1,22 @@ +// check-pass +// compile-flags: -Znext-solver + +// test that the new solver can handle `alias-eq(::Assoc, u32)` + +trait TraitA {} + +trait TraitB { + type Assoc; +} + +impl TraitA for (T, T::Assoc) {} + +impl TraitB for i32 { + type Assoc = u32; +} + +fn needs_a() {} + +fn main() { + needs_a::<(i32, u32)>(); +} diff --git a/tests/ui/traits/next-solver/alias_eq_substs_eq_not_intercrate.rs b/tests/ui/traits/next-solver/alias_eq_substs_eq_not_intercrate.rs new file mode 100644 index 000000000..4717aa804 --- /dev/null +++ b/tests/ui/traits/next-solver/alias_eq_substs_eq_not_intercrate.rs @@ -0,0 +1,17 @@ +// compile-flags: -Znext-solver + +// check that a `alias-eq(::Assoc, ::Assoc)` goal fails +// during coherence. We must not incorrectly constrain `?a` and `?b` to be +// equal. + +trait TraitB { + type Assoc; +} + +trait Overlaps {} + +impl Overlaps> for ::Assoc {} +impl Overlaps for ::Assoc {} +//~^ ERROR conflicting implementations of trait + +fn main() {} diff --git a/tests/ui/traits/next-solver/alias_eq_substs_eq_not_intercrate.stderr b/tests/ui/traits/next-solver/alias_eq_substs_eq_not_intercrate.stderr new file mode 100644 index 000000000..8c6840f72 --- /dev/null +++ b/tests/ui/traits/next-solver/alias_eq_substs_eq_not_intercrate.stderr @@ -0,0 +1,13 @@ +error[E0119]: conflicting implementations of trait `Overlaps>` for type `<_ as TraitB>::Assoc` + --> $DIR/alias_eq_substs_eq_not_intercrate.rs:14:1 + | +LL | impl Overlaps> for ::Assoc {} + | --------------------------------------------------------- first implementation here +LL | impl Overlaps for ::Assoc {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `<_ as TraitB>::Assoc` + | + = note: downstream crates may implement trait `TraitB` for type `std::boxed::Box<_>` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/traits/next-solver/array-default.rs b/tests/ui/traits/next-solver/array-default.rs new file mode 100644 index 000000000..6bfbce7d4 --- /dev/null +++ b/tests/ui/traits/next-solver/array-default.rs @@ -0,0 +1,8 @@ +// compile-flags: -Znext-solver +// check-pass + +fn has_default() where [(); N]: Default {} + +fn main() { + has_default::<1>(); +} diff --git a/tests/ui/traits/next-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs b/tests/ui/traits/next-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs new file mode 100644 index 000000000..4401abd07 --- /dev/null +++ b/tests/ui/traits/next-solver/assembly/assemble-normalizing-self-ty-impl-ambiguity.rs @@ -0,0 +1,27 @@ +// compile-flags: -Znext-solver +// check-pass + +// Checks that we do not get ambiguity by considering an impl +// multiple times if we're able to normalize the self type. + +trait Trait<'a> {} + +impl<'a, T: 'a> Trait<'a> for T {} + +fn impls_trait<'a, T: Trait<'a>>() {} + +trait Id { + type Assoc; +} +impl Id for T { + type Assoc = T; +} + +fn call() { + impls_trait::<::Assoc>(); +} + +fn main() { + call::<()>(); + impls_trait::<<<() as Id>::Assoc as Id>::Assoc>(); +} diff --git a/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.rs b/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.rs new file mode 100644 index 000000000..1edc1a8c5 --- /dev/null +++ b/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.rs @@ -0,0 +1,15 @@ +// compile-flags: -Znext-solver + +// In the new solver, we are trying to select `::Item: Debug`, +// which, naively can be unified with every impl of `Debug` if we're not careful. +// This test makes sure that we treat projections with inference var substs as +// placeholders during fast reject. + +fn iter() -> ::Item { + todo!() +} + +fn main() { + println!("{:?}", iter::<_>()); + //~^ ERROR type annotations needed +} diff --git a/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr b/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr new file mode 100644 index 000000000..4bd55ee80 --- /dev/null +++ b/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr @@ -0,0 +1,16 @@ +error[E0283]: type annotations needed + --> $DIR/runaway-impl-candidate-selection.rs:13:22 + | +LL | println!("{:?}", iter::<_>()); + | ^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `iter` + | + = note: cannot satisfy `_: Iterator` +note: required by a bound in `iter` + --> $DIR/runaway-impl-candidate-selection.rs:8:12 + | +LL | fn iter() -> ::Item { + | ^^^^^^^^ required by this bound in `iter` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/traits/next-solver/async.fail.stderr b/tests/ui/traits/next-solver/async.fail.stderr new file mode 100644 index 000000000..ebd0ada26 --- /dev/null +++ b/tests/ui/traits/next-solver/async.fail.stderr @@ -0,0 +1,17 @@ +error[E0271]: type mismatch resolving `<{async block@$DIR/async.rs:12:17: 12:25} as Future>::Output == i32` + --> $DIR/async.rs:12:17 + | +LL | needs_async(async {}); + | ----------- ^^^^^^^^ types differ + | | + | required by a bound introduced by this call + | +note: required by a bound in `needs_async` + --> $DIR/async.rs:8:31 + | +LL | fn needs_async(_: impl Future) {} + | ^^^^^^^^^^^^ required by this bound in `needs_async` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/traits/next-solver/async.rs b/tests/ui/traits/next-solver/async.rs new file mode 100644 index 000000000..5833c0522 --- /dev/null +++ b/tests/ui/traits/next-solver/async.rs @@ -0,0 +1,19 @@ +// compile-flags: -Znext-solver +// edition: 2021 +// revisions: pass fail +//[pass] check-pass + +use std::future::Future; + +fn needs_async(_: impl Future) {} + +#[cfg(fail)] +fn main() { + needs_async(async {}); + //[fail]~^ ERROR type mismatch +} + +#[cfg(pass)] +fn main() { + needs_async(async { 1i32 }); +} diff --git a/tests/ui/traits/next-solver/auto-with-drop_tracking_mir.fail.stderr b/tests/ui/traits/next-solver/auto-with-drop_tracking_mir.fail.stderr new file mode 100644 index 000000000..ac05dfb2d --- /dev/null +++ b/tests/ui/traits/next-solver/auto-with-drop_tracking_mir.fail.stderr @@ -0,0 +1,18 @@ +error[E0277]: `impl Future` cannot be sent between threads safely + --> $DIR/auto-with-drop_tracking_mir.rs:25:13 + | +LL | is_send(foo()); + | ------- ^^^^^ `impl Future` cannot be sent between threads safely + | | + | required by a bound introduced by this call + | + = help: the trait `Send` is not implemented for `impl Future` +note: required by a bound in `is_send` + --> $DIR/auto-with-drop_tracking_mir.rs:24:24 + | +LL | fn is_send(_: impl Send) {} + | ^^^^ required by this bound in `is_send` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/next-solver/auto-with-drop_tracking_mir.rs b/tests/ui/traits/next-solver/auto-with-drop_tracking_mir.rs new file mode 100644 index 000000000..d4010a552 --- /dev/null +++ b/tests/ui/traits/next-solver/auto-with-drop_tracking_mir.rs @@ -0,0 +1,27 @@ +// compile-flags: -Znext-solver +// edition: 2021 +// revisions: pass fail +//[pass] check-pass + +#![feature(negative_impls)] + +struct NotSync; +impl !Sync for NotSync {} + +async fn foo() { + #[cfg(pass)] + let x = &(); + #[cfg(fail)] + let x = &NotSync; + bar().await; + #[allow(dropping_references)] + drop(x); +} + +async fn bar() {} + +fn main() { + fn is_send(_: impl Send) {} + is_send(foo()); + //[fail]~^ ERROR `impl Future` cannot be sent between threads safely +} diff --git a/tests/ui/traits/next-solver/borrowck-error.rs b/tests/ui/traits/next-solver/borrowck-error.rs new file mode 100644 index 000000000..25f144594 --- /dev/null +++ b/tests/ui/traits/next-solver/borrowck-error.rs @@ -0,0 +1,11 @@ +// compile-flags: -Znext-solver + +use std::collections::HashMap; + +fn foo() -> &'static HashMap +{ + &HashMap::new() + //~^ ERROR cannot return reference to temporary value +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/borrowck-error.stderr b/tests/ui/traits/next-solver/borrowck-error.stderr new file mode 100644 index 000000000..4cb41e7d5 --- /dev/null +++ b/tests/ui/traits/next-solver/borrowck-error.stderr @@ -0,0 +1,12 @@ +error[E0515]: cannot return reference to temporary value + --> $DIR/borrowck-error.rs:7:5 + | +LL | &HashMap::new() + | ^-------------- + | || + | |temporary value created here + | returns a reference to data owned by the current function + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0515`. diff --git a/tests/ui/traits/next-solver/builtin-fn-must-return-sized.rs b/tests/ui/traits/next-solver/builtin-fn-must-return-sized.rs new file mode 100644 index 000000000..eab25214d --- /dev/null +++ b/tests/ui/traits/next-solver/builtin-fn-must-return-sized.rs @@ -0,0 +1,17 @@ +// compile-flags: -Znext-solver + +#![feature(fn_traits)] +#![feature(unboxed_closures)] +#![feature(tuple_trait)] + +use std::ops::Fn; +use std::marker::Tuple; + +fn foo, T: Tuple>(f: Option, t: T) { + let y = (f.unwrap()).call(t); +} + +fn main() { + foo:: str, _>(None, ()); + //~^ expected a `Fn<_>` closure, found `fn() -> str` +} diff --git a/tests/ui/traits/next-solver/builtin-fn-must-return-sized.stderr b/tests/ui/traits/next-solver/builtin-fn-must-return-sized.stderr new file mode 100644 index 000000000..08047852f --- /dev/null +++ b/tests/ui/traits/next-solver/builtin-fn-must-return-sized.stderr @@ -0,0 +1,16 @@ +error[E0277]: expected a `Fn<_>` closure, found `fn() -> str` + --> $DIR/builtin-fn-must-return-sized.rs:15:11 + | +LL | foo:: str, _>(None, ()); + | ^^^^^^^^^^^ expected an `Fn<_>` closure, found `fn() -> str` + | + = help: the trait `Fn<_>` is not implemented for `fn() -> str` +note: required by a bound in `foo` + --> $DIR/builtin-fn-must-return-sized.rs:10:11 + | +LL | fn foo, T: Tuple>(f: Option, t: T) { + | ^^^^^ required by this bound in `foo` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/next-solver/canonical-int-var-eq-in-response.rs b/tests/ui/traits/next-solver/canonical-int-var-eq-in-response.rs new file mode 100644 index 000000000..ea2740523 --- /dev/null +++ b/tests/ui/traits/next-solver/canonical-int-var-eq-in-response.rs @@ -0,0 +1,22 @@ +// compile-flags: -Znext-solver +// check-pass + +trait Mirror { + type Assoc; +} + +impl Mirror for T { + type Assoc = T; +} + +trait Test {} +impl Test for i64 {} +impl Test for u64 {} + +fn mirror_me(t: T, s: ::Assoc) where ::Assoc: Test {} + +fn main() { + let mut x = 0; + mirror_me(x, 1); + x = 1i64; +} diff --git a/tests/ui/traits/next-solver/canonical-ty-var-eq-in-response.rs b/tests/ui/traits/next-solver/canonical-ty-var-eq-in-response.rs new file mode 100644 index 000000000..b1e4a9e58 --- /dev/null +++ b/tests/ui/traits/next-solver/canonical-ty-var-eq-in-response.rs @@ -0,0 +1,39 @@ +// check-pass +// compile-flags: -Znext-solver + +trait Mirror { + type Item; +} + +struct Wrapper(T); +impl Mirror for Wrapper { + type Item = T; +} + +fn mirror() +where + Wrapper: Mirror, +{ +} + +fn main() { + mirror::<_ /* ?0 */>(); + + // Solving ` as Mirror>::Item = i32` + + // First, we replace the term with a fresh infer var: + // ` as Mirror>::Item = ?1` + + // We select the impl candidate on line #6, which leads us to learn that + // `?0 == ?1`. + + // That should be reflected in our canonical response, which should have + // `^0 = ^0, ^1 = ^0` + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + // !! We used to return a totally unconstrained response here :< !! + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + // Then, during the "equate term" part of the projection solving, we + // instantiate the response from the unconstrained projection predicate, + // and equate `?0 == i32`. +} diff --git a/tests/ui/traits/next-solver/canonicalize-effect-var.rs b/tests/ui/traits/next-solver/canonicalize-effect-var.rs new file mode 100644 index 000000000..4a13ba373 --- /dev/null +++ b/tests/ui/traits/next-solver/canonicalize-effect-var.rs @@ -0,0 +1,22 @@ +// compile-flags: -Znext-solver +// check-pass + +#![feature(effects)] +#![feature(const_trait_impl)] + +#[const_trait] +trait Foo { + fn foo(); +} + +trait Bar {} + +impl const Foo for i32 { + fn foo() {} +} + +impl const Foo for T where T: Bar { + fn foo() {} +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/cast-checks-handling-projections.rs b/tests/ui/traits/next-solver/cast-checks-handling-projections.rs new file mode 100644 index 000000000..406b4dc12 --- /dev/null +++ b/tests/ui/traits/next-solver/cast-checks-handling-projections.rs @@ -0,0 +1,6 @@ +// compile-flags: -Znext-solver +// check-pass + +fn main() { + (0u8 + 0u8) as char; +} diff --git a/tests/ui/traits/next-solver/closure-inference-guidance.rs b/tests/ui/traits/next-solver/closure-inference-guidance.rs new file mode 100644 index 000000000..8175b92f8 --- /dev/null +++ b/tests/ui/traits/next-solver/closure-inference-guidance.rs @@ -0,0 +1,11 @@ +// compile-flags: -Znext-solver +// check-pass + +fn foo(i: isize) -> isize { i + 1 } + +fn apply(f: F, v: A) -> A where F: FnOnce(A) -> A { f(v) } + +pub fn main() { + let f = |i| foo(i); + assert_eq!(apply(f, 2), 3); +} diff --git a/tests/ui/traits/next-solver/closure-signature-inference-2.rs b/tests/ui/traits/next-solver/closure-signature-inference-2.rs new file mode 100644 index 000000000..8fece7ba9 --- /dev/null +++ b/tests/ui/traits/next-solver/closure-signature-inference-2.rs @@ -0,0 +1,21 @@ +// compile-flags: -Znext-solver +// check-pass + +fn map U>(f: F) { + f(T::default()); +} + +fn main() { + map::(|x| x.to_string()); + // PREVIOUSLY when confirming the `map` call, we register: + // + // (1.) ?F: FnOnce<(i32,)> + // (2.) >::Output projects-to ?U + // + // While (1.) is ambiguous, (2.) immediately gets processed + // and we infer `?U := >::Output`. + // + // Thus, the only pending obligation that remains is (1.). + // Since it is a trait obligation, we don't use it to deduce + // the closure signature, and we fail! +} diff --git a/tests/ui/traits/next-solver/closure-signature-inference.rs b/tests/ui/traits/next-solver/closure-signature-inference.rs new file mode 100644 index 000000000..355fc7902 --- /dev/null +++ b/tests/ui/traits/next-solver/closure-signature-inference.rs @@ -0,0 +1,15 @@ +// compile-flags: -Znext-solver +// check-pass + +struct A; +impl A { + fn hi(self) {} +} + +fn hello() -> Result<(A,), ()> { + Err(()) +} + +fn main() { + let x = hello().map(|(x,)| x.hi()); +} diff --git a/tests/ui/traits/next-solver/closure-substs-ambiguity.rs b/tests/ui/traits/next-solver/closure-substs-ambiguity.rs new file mode 100644 index 000000000..cc9ee58f2 --- /dev/null +++ b/tests/ui/traits/next-solver/closure-substs-ambiguity.rs @@ -0,0 +1,7 @@ +// compile-flags: -Znext-solver +// check-pass + +fn main() { + let mut x: Vec<_> = vec![]; + x.extend(Some(1i32).into_iter().map(|x| x)); +} diff --git a/tests/ui/traits/next-solver/coerce-ambig-alias-to-rigid-alias.rs b/tests/ui/traits/next-solver/coerce-ambig-alias-to-rigid-alias.rs new file mode 100644 index 000000000..bcb48b5ac --- /dev/null +++ b/tests/ui/traits/next-solver/coerce-ambig-alias-to-rigid-alias.rs @@ -0,0 +1,15 @@ +// compile-flags: -Znext-solver +// check-pass + +trait Trait { + type Assoc; +} + +fn call(_: ::Assoc, _: T) {} + +fn foo(rigid: ::Assoc, t: T) { + // Check that we can coerce `::Assoc` to `::Assoc`. + call::<_ /* ?0 */>(rigid, t); +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/coherence/issue-102048.rs b/tests/ui/traits/next-solver/coherence/issue-102048.rs new file mode 100644 index 000000000..600e63d4d --- /dev/null +++ b/tests/ui/traits/next-solver/coherence/issue-102048.rs @@ -0,0 +1,44 @@ +// This must fail coherence. +// +// Getting this to pass was fairly difficult, so here's an explanation +// of what's happening: +// +// Normalizing projections currently tries to replace them with inference variables +// while emitting a nested `Projection` obligation. This cannot be done if the projection +// has bound variables which is the case here. +// +// So the projections stay until after normalization. When unifying two projections we +// currently treat them as if they are injective, so we **incorrectly** unify their +// substs. This means that coherence for the two impls ends up unifying `?T` and `?U` +// as it tries to unify `>::Assoc` with `>::Assoc`. +// +// `impl1` therefore has the projection `>::Assoc` and we have the +// assumption `?T: for<'a> WithAssoc2<'a, Assoc = i32>` in the `param_env`, so we normalize +// that to `i32`. We then try to unify `i32` from `impl1` with `u32` from `impl2` which fails, +// causing coherence to consider these two impls distinct. + +// compile-flags: -Znext-solver +pub trait Trait {} + +pub trait WithAssoc1<'a> { + type Assoc; +} +pub trait WithAssoc2<'a> { + type Assoc; +} + +// impl 1 +impl Trait fn(>::Assoc, >::Assoc)> for (T, U) +where + T: for<'a> WithAssoc1<'a> + for<'a> WithAssoc2<'a, Assoc = i32>, + U: for<'a> WithAssoc2<'a>, +{ +} + +// impl 2 +impl Trait fn(>::Assoc, u32)> for (T, U) where + U: for<'a> WithAssoc1<'a> //~^ ERROR conflicting implementations of trait +{ +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/coherence/issue-102048.stderr b/tests/ui/traits/next-solver/coherence/issue-102048.stderr new file mode 100644 index 000000000..4e93ae284 --- /dev/null +++ b/tests/ui/traits/next-solver/coherence/issue-102048.stderr @@ -0,0 +1,16 @@ +error[E0119]: conflicting implementations of trait `Trait fn(<_ as WithAssoc1<'a>>::Assoc, <_ as WithAssoc2<'a>>::Assoc)>` for type `(_, _)` + --> $DIR/issue-102048.rs:39:1 + | +LL | / impl Trait fn(>::Assoc, >::Assoc)> for (T, U) +LL | | where +LL | | T: for<'a> WithAssoc1<'a> + for<'a> WithAssoc2<'a, Assoc = i32>, +LL | | U: for<'a> WithAssoc2<'a>, + | |______________________________- first implementation here +... +LL | / impl Trait fn(>::Assoc, u32)> for (T, U) where +LL | | U: for<'a> WithAssoc1<'a> + | |_____________________________^ conflicting implementation for `(_, _)` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.rs b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.rs new file mode 100644 index 000000000..af471b5e1 --- /dev/null +++ b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.rs @@ -0,0 +1,20 @@ +// compile-flags: -Znext-solver + +// Coherence should handle overflow while normalizing for +// `trait_ref_is_knowable` correctly. + +trait Overflow { + type Assoc; +} +impl Overflow for T { + type Assoc = ::Assoc; +} + + +trait Trait {} +impl Trait for T {} +struct LocalTy; +impl Trait for ::Assoc {} +//~^ ERROR conflicting implementations of trait `Trait` for type `::Assoc` + +fn main() {} diff --git a/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr new file mode 100644 index 000000000..e3c0dabf5 --- /dev/null +++ b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-norm-overflow.stderr @@ -0,0 +1,12 @@ +error[E0119]: conflicting implementations of trait `Trait` for type `::Assoc` + --> $DIR/trait_ref_is_knowable-norm-overflow.rs:17:1 + | +LL | impl Trait for T {} + | ------------------------- first implementation here +LL | struct LocalTy; +LL | impl Trait for ::Assoc {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `::Assoc` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-1.rs b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-1.rs new file mode 100644 index 000000000..e6ffb55b4 --- /dev/null +++ b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-1.rs @@ -0,0 +1,22 @@ +// compile-flags: -Znext-solver +// check-pass + +trait Id { + type Assoc; +} +impl Id for T { + type Assoc = T; +} + + +// Coherence should be able to reason that `::Assoc: Copy` +// does not hold. +// +// See https://github.com/rust-lang/trait-system-refactor-initiative/issues/51 +// for more details. +trait Trait {} +impl Trait for T {} +struct LocalTy; +impl Trait for ::Assoc {} + +fn main() {} diff --git a/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-2.rs b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-2.rs new file mode 100644 index 000000000..d16f9d22c --- /dev/null +++ b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-2.rs @@ -0,0 +1,25 @@ +// compile-flags: -Znext-solver +// check-pass + +use std::future::{Future, IntoFuture}; +use std::pin::Pin; + +// We check that this does not overlap with the following impl from std: +// impl

Future for Pin

where P: DerefMut,

::Target: Future { .. } +// This should fail because we know ` <&mut Value as Deref>::Target: Future` not to hold. +// For this to work we have to normalize in the `trait_ref_is_knowable` check as we +// otherwise add an ambiguous candidate here. +// +// See https://github.com/rust-lang/trait-system-refactor-initiative/issues/51 +// for more details. +struct Value; +impl<'a> IntoFuture for Pin<&'a mut Value> { + type Output = (); + type IntoFuture = Pin + Send>>; + + fn into_future(self) -> Self::IntoFuture { + todo!() + } +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-3.rs b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-3.rs new file mode 100644 index 000000000..90de6b847 --- /dev/null +++ b/tests/ui/traits/next-solver/coherence/trait_ref_is_knowable-normalization-3.rs @@ -0,0 +1,24 @@ +// compile-flags: -Znext-solver +// check-pass + +trait Id { + type Assoc; +} +impl Id for T { + type Assoc = T; +} + + +// Coherence should be able to reason that `(): PartialEq<::Assoc>>` +// does not hold. +// +// See https://github.com/rust-lang/trait-system-refactor-initiative/issues/51 +// for more details. +trait Trait {} +impl Trait for T +where + (): PartialEq {} +struct LocalTy; +impl Trait for ::Assoc {} + +fn main() {} diff --git a/tests/ui/traits/next-solver/const-param-placeholder.fail.stderr b/tests/ui/traits/next-solver/const-param-placeholder.fail.stderr new file mode 100644 index 000000000..163710706 --- /dev/null +++ b/tests/ui/traits/next-solver/const-param-placeholder.fail.stderr @@ -0,0 +1,16 @@ +error[E0277]: the trait bound `[T; N]: Foo` is not satisfied + --> $DIR/const-param-placeholder.rs:17:17 + | +LL | needs_foo::<[T; N]>(); + | ^^^^^^ the trait `Foo` is not implemented for `[T; N]` + | + = help: the trait `Foo` is implemented for `[T; 1]` +note: required by a bound in `needs_foo` + --> $DIR/const-param-placeholder.rs:8:17 + | +LL | fn needs_foo() {} + | ^^^ required by this bound in `needs_foo` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/next-solver/const-param-placeholder.rs b/tests/ui/traits/next-solver/const-param-placeholder.rs new file mode 100644 index 000000000..c22bc54cf --- /dev/null +++ b/tests/ui/traits/next-solver/const-param-placeholder.rs @@ -0,0 +1,21 @@ +// compile-flags: -Znext-solver +// revisions: pass fail +//[pass] check-pass + +struct Wrapper([T; N]); + +trait Foo {} +fn needs_foo() {} + +#[cfg(fail)] +impl Foo for [T; 1] {} + +#[cfg(pass)] +impl Foo for [T; N] {} + +fn test() { + needs_foo::<[T; N]>(); + //[fail]~^ ERROR the trait bound `[T; N]: Foo` is not satisfied +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/coroutine.fail.stderr b/tests/ui/traits/next-solver/coroutine.fail.stderr new file mode 100644 index 000000000..14e67727d --- /dev/null +++ b/tests/ui/traits/next-solver/coroutine.fail.stderr @@ -0,0 +1,64 @@ +error[E0277]: the trait bound `{coroutine@$DIR/coroutine.rs:18:21: 18:23}: Coroutine` is not satisfied + --> $DIR/coroutine.rs:18:21 + | +LL | needs_coroutine(|| { + | _____---------------_^ + | | | + | | required by a bound introduced by this call +LL | | +LL | | +LL | | +LL | | yield (); +LL | | }); + | |_____^ the trait `Coroutine` is not implemented for `{coroutine@$DIR/coroutine.rs:18:21: 18:23}` + | +note: required by a bound in `needs_coroutine` + --> $DIR/coroutine.rs:14:28 + | +LL | fn needs_coroutine(_: impl Coroutine) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `needs_coroutine` + +error[E0271]: type mismatch resolving `<{coroutine@$DIR/coroutine.rs:18:21: 18:23} as Coroutine>::Yield == B` + --> $DIR/coroutine.rs:18:21 + | +LL | needs_coroutine(|| { + | _____---------------_^ + | | | + | | required by a bound introduced by this call +LL | | +LL | | +LL | | +LL | | yield (); +LL | | }); + | |_____^ types differ + | +note: required by a bound in `needs_coroutine` + --> $DIR/coroutine.rs:14:41 + | +LL | fn needs_coroutine(_: impl Coroutine) {} + | ^^^^^^^^^ required by this bound in `needs_coroutine` + +error[E0271]: type mismatch resolving `<{coroutine@$DIR/coroutine.rs:18:21: 18:23} as Coroutine>::Return == C` + --> $DIR/coroutine.rs:18:21 + | +LL | needs_coroutine(|| { + | _____---------------_^ + | | | + | | required by a bound introduced by this call +LL | | +LL | | +LL | | +LL | | yield (); +LL | | }); + | |_____^ types differ + | +note: required by a bound in `needs_coroutine` + --> $DIR/coroutine.rs:14:52 + | +LL | fn needs_coroutine(_: impl Coroutine) {} + | ^^^^^^^^^^ required by this bound in `needs_coroutine` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0271, E0277. +For more information about an error, try `rustc --explain E0271`. diff --git a/tests/ui/traits/next-solver/coroutine.rs b/tests/ui/traits/next-solver/coroutine.rs new file mode 100644 index 000000000..727e23568 --- /dev/null +++ b/tests/ui/traits/next-solver/coroutine.rs @@ -0,0 +1,32 @@ +// compile-flags: -Znext-solver +// edition: 2021 +// revisions: pass fail +//[pass] check-pass + +#![feature(coroutine_trait, coroutines)] + +use std::ops::Coroutine; + +struct A; +struct B; +struct C; + +fn needs_coroutine(_: impl Coroutine) {} + +#[cfg(fail)] +fn main() { + needs_coroutine(|| { + //[fail]~^ ERROR Coroutine` is not satisfied + //[fail]~| ERROR as Coroutine>::Yield == B` + //[fail]~| ERROR as Coroutine>::Return == C` + yield (); + }); +} + +#[cfg(pass)] +fn main() { + needs_coroutine(|_: A| { + let _: A = yield B; + C + }) +} diff --git a/tests/ui/traits/next-solver/cycles/coinduction/fixpoint-exponential-growth.rs b/tests/ui/traits/next-solver/cycles/coinduction/fixpoint-exponential-growth.rs new file mode 100644 index 000000000..947b52da7 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/coinduction/fixpoint-exponential-growth.rs @@ -0,0 +1,35 @@ +// compile-flags: -Znext-solver + +// Proving `W: Trait` instantiates `?0` with `(W, W)` and then +// proves `W: Trait` and `W: Trait`, resulting in a coinductive cycle. +// +// Proving coinductive cycles runs until we reach a fixpoint. However, after +// computing `try_evaluate_added_goals` in the second fixpoint iteration, the +// self type already has a depth equal to the number of steps. This results +// in enormous constraints, causing the canonicalizer to hang without ever +// reaching the recursion limit. We currently avoid that by erasing the constraints +// from overflow. +// +// This previously caused a hang in the trait solver, see +// https://github.com/rust-lang/trait-system-refactor-initiative/issues/13. + +#![feature(rustc_attrs)] + +#[rustc_coinductive] +trait Trait {} + +struct W(T); + +impl Trait for W<(W, W)> +where + W: Trait, + W: Trait, +{ +} + +fn impls() {} + +fn main() { + impls::>(); + //~^ ERROR overflow evaluating the requirement +} diff --git a/tests/ui/traits/next-solver/cycles/coinduction/fixpoint-exponential-growth.stderr b/tests/ui/traits/next-solver/cycles/coinduction/fixpoint-exponential-growth.stderr new file mode 100644 index 000000000..150100f2c --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/coinduction/fixpoint-exponential-growth.stderr @@ -0,0 +1,16 @@ +error[E0275]: overflow evaluating the requirement `W<_>: Trait` + --> $DIR/fixpoint-exponential-growth.rs:33:13 + | +LL | impls::>(); + | ^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`fixpoint_exponential_growth`) +note: required by a bound in `impls` + --> $DIR/fixpoint-exponential-growth.rs:30:13 + | +LL | fn impls() {} + | ^^^^^ required by this bound in `impls` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.rs b/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.rs new file mode 100644 index 000000000..a3c07b987 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.rs @@ -0,0 +1,69 @@ +// compile-flags: -Znext-solver +#![feature(rustc_attrs)] + +// This test is incredibly subtle. At its core the goal is to get a coinductive cycle, +// which, depending on its root goal, either holds or errors. We achieve this by getting +// incomplete inference via a `ParamEnv` candidate in the `A` impl and required +// inference from an `Impl` candidate in the `B` impl. +// +// To make global cache accesses stronger than the guidance from the where-bounds, we add +// another coinductive cycle from `A: Trait` to `A: Trait` and only +// constrain `D` directly. This means that any candidates which rely on `V` only make +// progress in the second iteration, allowing a cache access in the first iteration to take +// precedence. +// +// tl;dr: our caching of coinductive cycles was broken and this is a regression +// test for that. + +#[rustc_coinductive] +trait Trait {} +struct A(*const T); +struct B(*const T); + +trait IncompleteGuidance {} +impl IncompleteGuidance for T {} +impl IncompleteGuidance for T {} +impl IncompleteGuidance for T {} + +trait ImplGuidance {} +impl ImplGuidance for T {} +impl ImplGuidance for T {} + +impl Trait for A +where + T: IncompleteGuidance, + A: Trait, + B: Trait, + (): ToU8, +{ +} + +trait ToU8 {} +impl ToU8 for () {} + +impl Trait for B +where + T: ImplGuidance, + A: Trait, +{ +} + +fn impls_trait, U: ?Sized, V: ?Sized, D: ?Sized>() {} + +fn with_bound() +where + X: IncompleteGuidance, + X: IncompleteGuidance, + X: IncompleteGuidance, +{ + impls_trait::, _, _, _>(); // entering the cycle from `B` works + + // entering the cycle from `A` fails, but would work if we were to use the cache + // result of `B`. + impls_trait::, _, _, _>(); + //~^ ERROR the trait bound `A: Trait<_, _, _>` is not satisfied +} + +fn main() { + with_bound::(); +} diff --git a/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.stderr b/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.stderr new file mode 100644 index 000000000..d49321917 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/coinduction/incompleteness-unstable-result.stderr @@ -0,0 +1,16 @@ +error[E0277]: the trait bound `A: Trait<_, _, _>` is not satisfied + --> $DIR/incompleteness-unstable-result.rs:63:19 + | +LL | impls_trait::, _, _, _>(); + | ^^^^ the trait `Trait<_, _, _>` is not implemented for `A` + | + = help: the trait `Trait` is implemented for `A` +note: required by a bound in `impls_trait` + --> $DIR/incompleteness-unstable-result.rs:51:28 + | +LL | fn impls_trait, U: ?Sized, V: ?Sized, D: ?Sized>() {} + | ^^^^^^^^^^^^^^ required by this bound in `impls_trait` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/next-solver/cycles/double-cycle-inductive-coinductive.rs b/tests/ui/traits/next-solver/cycles/double-cycle-inductive-coinductive.rs new file mode 100644 index 000000000..0f19bc2c5 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/double-cycle-inductive-coinductive.rs @@ -0,0 +1,37 @@ +// compile-flags: -Znext-solver +#![feature(rustc_attrs)] + +// Test that having both an inductive and a coinductive cycle +// is handled correctly. + +#[rustc_coinductive] +trait Trait {} +impl Trait for T {} + +trait Inductive {} +impl Inductive for T {} +#[rustc_coinductive] +trait Coinductive {} +impl Coinductive for T {} + +fn impls_trait() {} + +#[rustc_coinductive] +trait TraitRev {} +impl TraitRev for T {} + +trait InductiveRev {} +impl InductiveRev for T {} +#[rustc_coinductive] +trait CoinductiveRev {} +impl CoinductiveRev for T {} + +fn impls_trait_rev() {} + +fn main() { + impls_trait::<()>(); + //~^ ERROR overflow evaluating the requirement + + impls_trait_rev::<()>(); + //~^ ERROR overflow evaluating the requirement +} diff --git a/tests/ui/traits/next-solver/cycles/double-cycle-inductive-coinductive.stderr b/tests/ui/traits/next-solver/cycles/double-cycle-inductive-coinductive.stderr new file mode 100644 index 000000000..a3404da51 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/double-cycle-inductive-coinductive.stderr @@ -0,0 +1,29 @@ +error[E0275]: overflow evaluating the requirement `(): Trait` + --> $DIR/double-cycle-inductive-coinductive.rs:32:19 + | +LL | impls_trait::<()>(); + | ^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`double_cycle_inductive_coinductive`) +note: required by a bound in `impls_trait` + --> $DIR/double-cycle-inductive-coinductive.rs:17:19 + | +LL | fn impls_trait() {} + | ^^^^^ required by this bound in `impls_trait` + +error[E0275]: overflow evaluating the requirement `(): TraitRev` + --> $DIR/double-cycle-inductive-coinductive.rs:35:23 + | +LL | impls_trait_rev::<()>(); + | ^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`double_cycle_inductive_coinductive`) +note: required by a bound in `impls_trait_rev` + --> $DIR/double-cycle-inductive-coinductive.rs:29:23 + | +LL | fn impls_trait_rev() {} + | ^^^^^^^^ required by this bound in `impls_trait_rev` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/next-solver/cycles/fixpoint-rerun-all-cycle-heads.rs b/tests/ui/traits/next-solver/cycles/fixpoint-rerun-all-cycle-heads.rs new file mode 100644 index 000000000..c7e2e2d5e --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/fixpoint-rerun-all-cycle-heads.rs @@ -0,0 +1,53 @@ +// compile-flags: -Znext-solver +#![feature(rustc_attrs)] + +// Check that we correctly rerun the trait solver for heads of cycles, +// even if they are not the root. + +struct A(*const T); +struct B(*const T); +struct C(*const T); + +#[rustc_coinductive] +trait Trait<'a, 'b> {} +trait NotImplemented {} + +impl<'a, 'b, T: ?Sized> Trait<'a, 'b> for A where B: Trait<'a, 'b> {} + +// With this the root of `B` is `A`, even if the other impl does +// not have a cycle with `A`. This candidate never applies because of +// the `A: NotImplemented` bound. +impl<'a, 'b, T: ?Sized> Trait<'a, 'b> for B +where + A: Trait<'a, 'b>, + A: NotImplemented, +{ +} + +// This impl directly requires 'b to be equal to 'static. +// +// Because of the coinductive cycle through `C` it also requires +// 'a to be 'static. +impl<'a, T: ?Sized> Trait<'a, 'static> for B +where + C: Trait<'a, 'a>, +{} + +// In the first iteration of `B: Trait<'a, 'b>` we don't add any +// constraints here, only after setting the provisional result to require +// `'b == 'static` do we also add that constraint for `'a`. +impl<'a, 'b, T: ?Sized> Trait<'a, 'b> for C +where + B: Trait<'a, 'b>, +{} + +fn impls_trait<'a, 'b, T: Trait<'a, 'b> + ?Sized>() {} + +fn check<'a, T: ?Sized>() { + impls_trait::<'a, 'static, A>(); + //~^ ERROR lifetime may not live long enough +} + +fn main() { + check::<()>(); +} diff --git a/tests/ui/traits/next-solver/cycles/fixpoint-rerun-all-cycle-heads.stderr b/tests/ui/traits/next-solver/cycles/fixpoint-rerun-all-cycle-heads.stderr new file mode 100644 index 000000000..7b3075f4f --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/fixpoint-rerun-all-cycle-heads.stderr @@ -0,0 +1,10 @@ +error: lifetime may not live long enough + --> $DIR/fixpoint-rerun-all-cycle-heads.rs:47:5 + | +LL | fn check<'a, T: ?Sized>() { + | -- lifetime `'a` defined here +LL | impls_trait::<'a, 'static, A>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` + +error: aborting due to 1 previous error + diff --git a/tests/ui/traits/next-solver/cycles/inductive-cycle-but-err.rs b/tests/ui/traits/next-solver/cycles/inductive-cycle-but-err.rs new file mode 100644 index 000000000..fdc7afea3 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/inductive-cycle-but-err.rs @@ -0,0 +1,48 @@ +// compile-flags: -Znext-solver +#![feature(trivial_bounds, marker_trait_attr)] +#![allow(trivial_bounds)] +// This previously triggered a bug in the provisional cache. +// +// This has the proof tree +// - `MultipleCandidates: Trait` proven via impl-one +// - `MultipleNested: Trait` via impl +// - `MultipleCandidates: Trait` (inductive cycle ~> OVERFLOW) +// - `DoesNotImpl: Trait` (ERR) +// - `MultipleCandidates: Trait` proven via impl-two +// - `MultipleNested: Trait` (in provisional cache ~> OVERFLOW) +// +// We previously incorrectly treated the `MultipleCandidates: Trait` as +// overflow because it was in the cache and reached via an inductive cycle. +// It should be `NoSolution`. + +struct MultipleCandidates; +struct MultipleNested; +struct DoesNotImpl; + +#[marker] +trait Trait {} + +// impl-one +impl Trait for MultipleCandidates +where + MultipleNested: Trait +{} + +// impl-two +impl Trait for MultipleCandidates +where + MultipleNested: Trait, +{} + +impl Trait for MultipleNested +where + MultipleCandidates: Trait, + DoesNotImpl: Trait, +{} + +fn impls_trait() {} + +fn main() { + impls_trait::(); + //~^ ERROR the trait bound `MultipleCandidates: Trait` is not satisfied +} diff --git a/tests/ui/traits/next-solver/cycles/inductive-cycle-but-err.stderr b/tests/ui/traits/next-solver/cycles/inductive-cycle-but-err.stderr new file mode 100644 index 000000000..acacaf6a3 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/inductive-cycle-but-err.stderr @@ -0,0 +1,16 @@ +error[E0277]: the trait bound `MultipleCandidates: Trait` is not satisfied + --> $DIR/inductive-cycle-but-err.rs:46:19 + | +LL | impls_trait::(); + | ^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `MultipleCandidates` + | + = help: the trait `Trait` is implemented for `MultipleCandidates` +note: required by a bound in `impls_trait` + --> $DIR/inductive-cycle-but-err.rs:43:19 + | +LL | fn impls_trait() {} + | ^^^^^ required by this bound in `impls_trait` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/next-solver/cycles/inductive-cycle-but-ok.rs b/tests/ui/traits/next-solver/cycles/inductive-cycle-but-ok.rs new file mode 100644 index 000000000..d6d9762bb --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/inductive-cycle-but-ok.rs @@ -0,0 +1,44 @@ +// compile-flags: -Znext-solver +// check-pass +#![feature(trivial_bounds, marker_trait_attr)] +#![allow(trivial_bounds)] + +// This previously triggered a bug in the provisional cache. +// +// This has the proof tree +// - `Root: Trait` proven via impl +// - `MultipleCandidates: Trait` +// - candidate: overflow-impl +// - `Root: Trait` (inductive cycle ~> OVERFLOW) +// - candidate: trivial-impl ~> YES +// - merge respones ~> YES +// - `MultipleCandidates: Trait` (in provisional cache ~> OVERFLOW) +// +// We previously incorrectly treated the `MultipleCandidates: Trait` as +// overflow because it was in the cache and reached via an inductive cycle. +// It should be `YES`. + +struct Root; +struct MultipleCandidates; + +#[marker] +trait Trait {} +impl Trait for Root +where + MultipleCandidates: Trait, + MultipleCandidates: Trait, +{} + +// overflow-impl +impl Trait for MultipleCandidates +where + Root: Trait, +{} +// trivial-impl +impl Trait for MultipleCandidates {} + +fn impls_trait() {} + +fn main() { + impls_trait::(); +} diff --git a/tests/ui/traits/next-solver/cycles/inductive-cycle-discarded-coinductive-constraints.rs b/tests/ui/traits/next-solver/cycles/inductive-cycle-discarded-coinductive-constraints.rs new file mode 100644 index 000000000..a32f7a13a --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/inductive-cycle-discarded-coinductive-constraints.rs @@ -0,0 +1,36 @@ +// check-pass +// compile-flags: -Znext-solver +#![feature(rustc_attrs, marker_trait_attr)] +#[rustc_coinductive] +trait Trait {} + +impl Trait for (T, U) +where + (U, T): Trait, + (T, U): Inductive, + (): ConstrainToU32, +{} + +trait ConstrainToU32 {} +impl ConstrainToU32 for () {} + +// We only prefer the candidate without an inductive cycle +// once the inductive cycle has the same constraints as the +// other goal. +#[marker] +trait Inductive {} +impl Inductive for (T, U) +where + (T, U): Trait, +{} + +impl Inductive for (u32, u32) {} + +fn impls_trait() +where + (T, U): Trait, +{} + +fn main() { + impls_trait::<_, _>(); +} diff --git a/tests/ui/traits/next-solver/cycles/inductive-fixpoint-hang.rs b/tests/ui/traits/next-solver/cycles/inductive-fixpoint-hang.rs new file mode 100644 index 000000000..efeb8d023 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/inductive-fixpoint-hang.rs @@ -0,0 +1,33 @@ +// compile-flags: -Znext-solver + +// This currently hangs if we do not erase constraints from +// overflow. +// +// We set the provisional result of `W` to `?0 := W<_>`. +// The next iteration does not simply result in a `?0 := W` constraint as +// one might expect, but instead each time we evaluate the nested `W` goal we +// apply the previously returned constraints: the first fixpoint iteration goes +// as follows: `W: Trait` constrains `?1` to `W`, we then evaluate +// `W>: Trait` the next time we try to prove the nested goal. This results +// inn `W>>` and so on. This goes on until we reach overflow in +// `try_evaluate_added_goals`. This means the provisional result after the +// second fixpoint iteration is already `W>>` with a size proportional +// to the number of steps in `try_evaluate_added_goals`. The size then continues +// to grow. The exponential blowup from having 2 nested goals per impl causes +// the solver to hang without hitting the recursion limit. +trait Trait {} + +struct W(*const T); + +impl Trait for W> +where + W: Trait, + W: Trait, +{} + +fn impls_trait() {} + +fn main() { + impls_trait::>(); + //~^ ERROR overflow evaluating the requirement +} diff --git a/tests/ui/traits/next-solver/cycles/inductive-fixpoint-hang.stderr b/tests/ui/traits/next-solver/cycles/inductive-fixpoint-hang.stderr new file mode 100644 index 000000000..424519207 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/inductive-fixpoint-hang.stderr @@ -0,0 +1,16 @@ +error[E0275]: overflow evaluating the requirement `W<_>: Trait` + --> $DIR/inductive-fixpoint-hang.rs:31:19 + | +LL | impls_trait::>(); + | ^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`inductive_fixpoint_hang`) +note: required by a bound in `impls_trait` + --> $DIR/inductive-fixpoint-hang.rs:28:19 + | +LL | fn impls_trait() {} + | ^^^^^ required by this bound in `impls_trait` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/next-solver/cycles/inductive-not-on-stack.rs b/tests/ui/traits/next-solver/cycles/inductive-not-on-stack.rs new file mode 100644 index 000000000..f2f6e009d --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/inductive-not-on-stack.rs @@ -0,0 +1,46 @@ +// compile-flags: -Znext-solver +#![feature(rustc_attrs, trivial_bounds)] + +// We have to be careful here: +// +// We either have the provisional result of `A -> B -> A` on the +// stack, which is a fully coinductive cycle. Accessing the +// provisional result for `B` as part of the `A -> C -> B -> A` cycle +// has to make sure we don't just use the result of `A -> B -> A` as the +// new cycle is inductive. +// +// Alternatively, if we have `A -> C -> A` first, then `A -> B -> A` has +// a purely inductive stack, so something could also go wrong here. + +#[rustc_coinductive] +trait A {} +#[rustc_coinductive] +trait B {} +trait C {} + +impl A for T {} +impl B for T {} +impl C for T {} + +fn impls_a() {} + +// The same test with reordered where clauses to make sure we're actually testing anything. +#[rustc_coinductive] +trait AR {} +#[rustc_coinductive] +trait BR {} +trait CR {} + +impl AR for T {} +impl BR for T {} +impl CR for T {} + +fn impls_ar() {} + +fn main() { + impls_a::<()>(); + //~^ ERROR overflow evaluating the requirement `(): A` + + impls_ar::<()>(); + //~^ ERROR overflow evaluating the requirement `(): AR` +} diff --git a/tests/ui/traits/next-solver/cycles/inductive-not-on-stack.stderr b/tests/ui/traits/next-solver/cycles/inductive-not-on-stack.stderr new file mode 100644 index 000000000..859b3f3f1 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/inductive-not-on-stack.stderr @@ -0,0 +1,29 @@ +error[E0275]: overflow evaluating the requirement `(): A` + --> $DIR/inductive-not-on-stack.rs:41:15 + | +LL | impls_a::<()>(); + | ^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`inductive_not_on_stack`) +note: required by a bound in `impls_a` + --> $DIR/inductive-not-on-stack.rs:25:15 + | +LL | fn impls_a() {} + | ^ required by this bound in `impls_a` + +error[E0275]: overflow evaluating the requirement `(): AR` + --> $DIR/inductive-not-on-stack.rs:44:16 + | +LL | impls_ar::<()>(); + | ^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`inductive_not_on_stack`) +note: required by a bound in `impls_ar` + --> $DIR/inductive-not-on-stack.rs:38:16 + | +LL | fn impls_ar() {} + | ^^ required by this bound in `impls_ar` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/next-solver/cycles/leak-check-coinductive-cycle.rs b/tests/ui/traits/next-solver/cycles/leak-check-coinductive-cycle.rs new file mode 100644 index 000000000..9ff362ec8 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/leak-check-coinductive-cycle.rs @@ -0,0 +1,33 @@ +// compile-flags: -Znext-solver +// check-pass +#![feature(rustc_attrs)] + +#[rustc_coinductive] +trait Trait {} +impl<'a, 'b, T> Trait for (&'a (), &'b ()) +where + 'b: 'a, + &'a (): Trait, +{} + +impl Trait for &'static () {} +impl<'a> Trait for &'a () +where + for<'b> (&'a (), &'b ()): Trait, +{} + + +fn impls_trait, U>() {} + +fn main() { + // This infers to `impls_trait::<(&'static (), &'static ()), i32>();` + // + // In the first attempt we have 2 candidates for `&'a (): Trait<_>` + // and we get ambiguity. The result is therefore ambiguity with a `'b: 'a` + // constraint. The next attempt then uses that provisional result when + // trying to apply `impl<'a> Trait for &'a ()`. This means we get a + // `for<'b> 'b: 'a` bound which fails the leak check. Because of this we + // end up with a single impl for `&'a (): Trait<_>` which infers `_` to `i32` + // and succeeds. + impls_trait::<(&(), &()), _>(); +} diff --git a/tests/ui/traits/next-solver/cycles/provisional-result-done.rs b/tests/ui/traits/next-solver/cycles/provisional-result-done.rs new file mode 100644 index 000000000..0f3b84ce5 --- /dev/null +++ b/tests/ui/traits/next-solver/cycles/provisional-result-done.rs @@ -0,0 +1,33 @@ +// compile-flags: -Znext-solver +// check-pass + +// This tests checks that we update results in the provisional cache when +// we pop a goal from the stack. +#![feature(auto_traits)] +auto trait Coinductive {} +struct Foo(T); +struct Bar(T); + +impl Coinductive for Foo +where + Bar: Coinductive +{} + +impl Coinductive for Bar +where + Foo: Coinductive, + Bar: ConstrainInfer, +{} + +trait ConstrainInfer {} +impl ConstrainInfer for Bar {} +impl ConstrainInfer for Foo {} + +fn impls() -> T { todo!() } + +fn constrain(_: T) {} + +fn main() { + // This should constrain `_` to `u8`. + impls::>(); +} diff --git a/tests/ui/traits/next-solver/deduce-closure-signature-after-normalization.rs b/tests/ui/traits/next-solver/deduce-closure-signature-after-normalization.rs new file mode 100644 index 000000000..08f26686b --- /dev/null +++ b/tests/ui/traits/next-solver/deduce-closure-signature-after-normalization.rs @@ -0,0 +1,10 @@ +// compile-flags: -Znext-solver +// check-pass + +trait Foo { + fn test() -> impl Fn(u32) -> u32 { + |x| x.count_ones() + } +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/deduce-ty-from-object.rs b/tests/ui/traits/next-solver/deduce-ty-from-object.rs new file mode 100644 index 000000000..b627fd720 --- /dev/null +++ b/tests/ui/traits/next-solver/deduce-ty-from-object.rs @@ -0,0 +1,6 @@ +// check-pass +// compile-flags: -Znext-solver + +fn main() { + let x: Box> = Box::new(std::iter::empty()); +} diff --git a/tests/ui/traits/next-solver/dedup-regions.rs b/tests/ui/traits/next-solver/dedup-regions.rs new file mode 100644 index 000000000..dd406333f --- /dev/null +++ b/tests/ui/traits/next-solver/dedup-regions.rs @@ -0,0 +1,31 @@ +// compile-flags: -Znext-solver +// check-pass + +struct A(*mut ()); + +unsafe impl Send for A where A: 'static {} + +macro_rules! mk { + ($name:ident $ty:ty) => { + struct $name($ty, $ty, $ty, $ty, $ty, $ty, $ty, $ty, $ty, $ty); + }; +} + +mk!(B A); +mk!(C B); +mk!(D C); +mk!(E D); +mk!(F E); +mk!(G F); +mk!(H G); +mk!(I H); +mk!(J I); +mk!(K J); +mk!(L K); +mk!(M L); + +fn needs_send() {} + +fn main() { + needs_send::(); +} diff --git a/tests/ui/traits/next-solver/destruct.rs b/tests/ui/traits/next-solver/destruct.rs new file mode 100644 index 000000000..5093344e4 --- /dev/null +++ b/tests/ui/traits/next-solver/destruct.rs @@ -0,0 +1,13 @@ +// compile-flags: -Znext-solver +// check-pass + +#![feature(const_trait_impl)] + +fn foo(_: impl std::marker::Destruct) {} + +struct MyAdt; + +fn main() { + foo(1); + foo(MyAdt); +} diff --git a/tests/ui/traits/next-solver/dont-coerce-infer-to-dyn.rs b/tests/ui/traits/next-solver/dont-coerce-infer-to-dyn.rs new file mode 100644 index 000000000..da07869f3 --- /dev/null +++ b/tests/ui/traits/next-solver/dont-coerce-infer-to-dyn.rs @@ -0,0 +1,17 @@ +// compile-flags: -Znext-solver +// check-pass + +use std::fmt::Display; +use std::rc::Rc; + +fn mk(t: Option<&T>) -> Rc { + todo!() +} + +fn main() { + let mut x = None; + let y = mk(x); + // Don't treat the line below as a unsize coercion `Rc ~> Rc` + let z: Rc = y; + x = Some(&1 as &dyn Display); +} diff --git a/tests/ui/traits/next-solver/dont-elaborate-for-projections.rs b/tests/ui/traits/next-solver/dont-elaborate-for-projections.rs new file mode 100644 index 000000000..9123871db --- /dev/null +++ b/tests/ui/traits/next-solver/dont-elaborate-for-projections.rs @@ -0,0 +1,12 @@ +// compile-flags: -Znext-solver +// check-pass + +trait Iter<'a, I: 'a>: Iterator {} + +fn needs_iter<'a, T: Iter<'a, I> + ?Sized, I: 'a>(_: &T) {} + +fn test(x: &dyn Iter<'_, ()>) { + needs_iter(x); +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/dont-ice-on-assoc-projection.rs b/tests/ui/traits/next-solver/dont-ice-on-assoc-projection.rs new file mode 100644 index 000000000..1e1ef8c23 --- /dev/null +++ b/tests/ui/traits/next-solver/dont-ice-on-assoc-projection.rs @@ -0,0 +1,19 @@ +// compile-flags: -Znext-solver=coherence + +// Makes sure we don't ICE on associated const projection when the feature gate +// is not enabled, since we should avoid encountering ICEs on stable if possible. + +trait Bar { + const ASSOC: usize; +} +impl Bar for () { + const ASSOC: usize = 1; +} + +trait Foo {} +impl Foo for () {} +impl Foo for T where T: Bar {} +//~^ ERROR associated const equality is incomplete +//~| ERROR conflicting implementations of trait `Foo` for type `()` + +fn main() {} diff --git a/tests/ui/traits/next-solver/dont-ice-on-assoc-projection.stderr b/tests/ui/traits/next-solver/dont-ice-on-assoc-projection.stderr new file mode 100644 index 000000000..368f5cd0c --- /dev/null +++ b/tests/ui/traits/next-solver/dont-ice-on-assoc-projection.stderr @@ -0,0 +1,21 @@ +error[E0658]: associated const equality is incomplete + --> $DIR/dont-ice-on-assoc-projection.rs:15:32 + | +LL | impl Foo for T where T: Bar {} + | ^^^^^^^^^ + | + = note: see issue #92827 for more information + = help: add `#![feature(associated_const_equality)]` to the crate attributes to enable + +error[E0119]: conflicting implementations of trait `Foo` for type `()` + --> $DIR/dont-ice-on-assoc-projection.rs:15:1 + | +LL | impl Foo for () {} + | --------------- first implementation here +LL | impl Foo for T where T: Bar {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0119, E0658. +For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/traits/next-solver/dont-loop-fulfill-on-region-constraints.rs b/tests/ui/traits/next-solver/dont-loop-fulfill-on-region-constraints.rs new file mode 100644 index 000000000..a85098a95 --- /dev/null +++ b/tests/ui/traits/next-solver/dont-loop-fulfill-on-region-constraints.rs @@ -0,0 +1,32 @@ +// compile-flags: -Znext-solver +// check-pass + +trait Eq<'a, 'b, T> {} + +trait Ambig {} +impl Ambig for () {} + +impl<'a, T> Eq<'a, 'a, T> for () where T: Ambig {} + +fn eq<'a, 'b, T>(t: T) +where + (): Eq<'a, 'b, T>, +{ +} + +fn test<'r>() { + let mut x = Default::default(); + + // When we evaluate `(): Eq<'r, 'r, ?0>` we uniquify the regions. + // That leads us to evaluate `(): Eq<'?0, '?1, ?0>`. The response of this + // will be ambiguous (because `?0: Ambig` is ambig) and also not an "identity" + // response, since the region constraints will contain `'?0 == '?1` (so + // `is_changed` will return true). Since it's both ambig and changed, + // fulfillment will both re-register the goal AND loop again. This hits the + // overflow limit. This should neither be considered overflow, nor ICE. + eq::<'r, 'r, _>(x); + + x = (); +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/dont-normalize-proj-with-error.rs b/tests/ui/traits/next-solver/dont-normalize-proj-with-error.rs new file mode 100644 index 000000000..fd1682cd6 --- /dev/null +++ b/tests/ui/traits/next-solver/dont-normalize-proj-with-error.rs @@ -0,0 +1,22 @@ +// compile-flags: -Znext-solver + +// Test that we don't incorrectly leak unconstrained inference variables +// if the projection contained an error. This caused an ICE in writeback. + +trait Mirror { + type Assoc: ?Sized; +} + +struct Wrapper(T); +impl Mirror for Wrapper { + type Assoc = T; +} + +fn mirror(_: W) -> Box { todo!() } + +fn type_error() -> TypeError { todo!() } +//~^ ERROR cannot find type `TypeError` in this scope + +fn main() { + let x = mirror(type_error()); +} diff --git a/tests/ui/traits/next-solver/dont-normalize-proj-with-error.stderr b/tests/ui/traits/next-solver/dont-normalize-proj-with-error.stderr new file mode 100644 index 000000000..576ede52a --- /dev/null +++ b/tests/ui/traits/next-solver/dont-normalize-proj-with-error.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `TypeError` in this scope + --> $DIR/dont-normalize-proj-with-error.rs:17:20 + | +LL | fn type_error() -> TypeError { todo!() } + | ^^^^^^^^^ not found in this scope + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/traits/next-solver/dont-remap-tait-substs.rs b/tests/ui/traits/next-solver/dont-remap-tait-substs.rs new file mode 100644 index 000000000..b089f0df3 --- /dev/null +++ b/tests/ui/traits/next-solver/dont-remap-tait-substs.rs @@ -0,0 +1,19 @@ +// compile-flags: -Znext-solver +// check-pass + +// Makes sure we don't prepopulate the MIR typeck of `define` +// with `Foo = T`, but instead, `Foo = B`, so that +// the param-env predicates actually apply. + +#![feature(type_alias_impl_trait)] + +type Foo = impl NeedsSend; + +trait NeedsSend {} +impl NeedsSend for T {} + +fn define(a: A, b: B, _: Foo) { + let y: Option> = Some(b); +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.not_send.stderr b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.not_send.stderr new file mode 100644 index 000000000..076dab29d --- /dev/null +++ b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.not_send.stderr @@ -0,0 +1,16 @@ +error[E0283]: type annotations needed: cannot satisfy `Foo: Send` + --> $DIR/dont-type_of-tait-in-defining-scope.rs:16:18 + | +LL | needs_send::(); + | ^^^ + | + = note: cannot satisfy `Foo: Send` +note: required by a bound in `needs_send` + --> $DIR/dont-type_of-tait-in-defining-scope.rs:13:18 + | +LL | fn needs_send() {} + | ^^^^ required by this bound in `needs_send` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.rs b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.rs new file mode 100644 index 000000000..a1f38e69e --- /dev/null +++ b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.rs @@ -0,0 +1,24 @@ +// revisions: is_send not_send +// compile-flags: -Znext-solver +//[is_send] check-pass + +#![feature(type_alias_impl_trait)] + +#[cfg(is_send)] +type Foo = impl Send; + +#[cfg(not_send)] +type Foo = impl Sized; + +fn needs_send() {} + +fn test(_: Foo) { + needs_send::(); + //[not_send]~^ ERROR type annotations needed: cannot satisfy `Foo: Send` +} + +fn defines(_: Foo) { + let _: Foo = (); +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/dyn-any-dont-prefer-impl.rs b/tests/ui/traits/next-solver/dyn-any-dont-prefer-impl.rs new file mode 100644 index 000000000..bb1c24a00 --- /dev/null +++ b/tests/ui/traits/next-solver/dyn-any-dont-prefer-impl.rs @@ -0,0 +1,17 @@ +// compile-flags: -Znext-solver +// check-pass + +// Test that selection prefers the builtin trait object impl for `Any` +// instead of the user defined impl. Both impls apply to the trait +// object. + +use std::any::Any; + +fn needs_usize(_: &usize) {} + +fn main() { + let x: &dyn Any = &1usize; + if let Some(x) = x.downcast_ref::() { + needs_usize(x); + } +} diff --git a/tests/ui/traits/next-solver/elaborate-item-bounds.rs b/tests/ui/traits/next-solver/elaborate-item-bounds.rs new file mode 100644 index 000000000..0f1f6c044 --- /dev/null +++ b/tests/ui/traits/next-solver/elaborate-item-bounds.rs @@ -0,0 +1,12 @@ +// compile-flags: -Znext-solver +// check-pass + +trait Foo { + type Bar: Bar; +} + +trait Bar: Baz {} + +trait Baz {} + +fn main() {} diff --git a/tests/ui/traits/next-solver/equating-projection-cyclically.rs b/tests/ui/traits/next-solver/equating-projection-cyclically.rs new file mode 100644 index 000000000..e7c80cfd7 --- /dev/null +++ b/tests/ui/traits/next-solver/equating-projection-cyclically.rs @@ -0,0 +1,31 @@ +// check-pass +// compile-flags: -Znext-solver + +trait Test { + type Assoc; +} + +fn transform(x: Inv) -> Inv { + todo!() +} + +impl Test for i32 { + type Assoc = i32; +} + +impl Test for String { + type Assoc = String; +} + +struct Inv(Option<*mut T>); + +fn main() { + let mut x: Inv<_> = Inv(None); + // This ends up equating `Inv` with `Inv<::Assoc>` + // which fails the occurs check when generalizing `?x`. + // + // We end up emitting a delayed obligation, causing this to still + // succeed. + x = transform(x); + x = Inv::(None); +} diff --git a/tests/ui/traits/next-solver/escaping-bound-vars-in-writeback-normalization.rs b/tests/ui/traits/next-solver/escaping-bound-vars-in-writeback-normalization.rs new file mode 100644 index 000000000..77bedc351 --- /dev/null +++ b/tests/ui/traits/next-solver/escaping-bound-vars-in-writeback-normalization.rs @@ -0,0 +1,18 @@ +// compile-flags: -Znext-solver +// check-pass + +trait Trivial { + type Assoc; +} + +impl Trivial for T { + type Assoc = (); +} + +fn main() { + // During writeback, we call `normalize_erasing_regions`, which will walk past + // the `for<'a>` binder and try to normalize `<&'a () as Trivial>::Assoc` directly. + // We need to handle this case in the new deep normalizer similarly to how it + // is handled in the old solver. + let x: Option fn(<&'a () as Trivial>::Assoc)> = None; +} diff --git a/tests/ui/traits/next-solver/float-canonical.rs b/tests/ui/traits/next-solver/float-canonical.rs new file mode 100644 index 000000000..90d75bacb --- /dev/null +++ b/tests/ui/traits/next-solver/float-canonical.rs @@ -0,0 +1,8 @@ +// compile-flags: -Znext-solver +// check-pass + +fn foo(x: f64) { + let y = x + 1.0; +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/fn-trait-closure.rs b/tests/ui/traits/next-solver/fn-trait-closure.rs new file mode 100644 index 000000000..cd2ae1f6f --- /dev/null +++ b/tests/ui/traits/next-solver/fn-trait-closure.rs @@ -0,0 +1,8 @@ +// compile-flags: -Znext-solver +// check-pass + +fn require_fn(_: impl Fn() -> i32) {} + +fn main() { + require_fn(|| -> i32 { 1i32 }); +} diff --git a/tests/ui/traits/next-solver/fn-trait.rs b/tests/ui/traits/next-solver/fn-trait.rs new file mode 100644 index 000000000..1e3d8a21c --- /dev/null +++ b/tests/ui/traits/next-solver/fn-trait.rs @@ -0,0 +1,32 @@ +// compile-flags: -Znext-solver + +fn require_fn(_: impl Fn() -> i32) {} + +fn f() -> i32 { + 1i32 +} + +extern "C" fn g() -> i32 { + 2i32 +} + +unsafe fn h() -> i32 { + 2i32 +} + +fn main() { + require_fn(f); + require_fn(f as fn() -> i32); + require_fn(f as unsafe fn() -> i32); + //~^ ERROR: expected a `Fn()` closure, found `unsafe fn() -> i32` + //~| ERROR: type mismatch resolving ` i32 as FnOnce<()>>::Output == i32` + require_fn(g); + //~^ ERROR: expected a `Fn()` closure, found `extern "C" fn() -> i32 {g}` + //~| ERROR: type mismatch resolving ` i32 {g} as FnOnce<()>>::Output == i32` + require_fn(g as extern "C" fn() -> i32); + //~^ ERROR: expected a `Fn()` closure, found `extern "C" fn() -> i32` + //~| ERROR: type mismatch resolving ` i32 as FnOnce<()>>::Output == i32` + require_fn(h); + //~^ ERROR: expected a `Fn()` closure, found `unsafe fn() -> i32 {h}` + //~| ERROR: type mismatch resolving ` i32 {h} as FnOnce<()>>::Output == i32` +} diff --git a/tests/ui/traits/next-solver/fn-trait.stderr b/tests/ui/traits/next-solver/fn-trait.stderr new file mode 100644 index 000000000..e33487235 --- /dev/null +++ b/tests/ui/traits/next-solver/fn-trait.stderr @@ -0,0 +1,126 @@ +error[E0277]: expected a `Fn()` closure, found `unsafe fn() -> i32` + --> $DIR/fn-trait.rs:20:16 + | +LL | require_fn(f as unsafe fn() -> i32); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` + | | + | required by a bound introduced by this call + | + = help: the trait `Fn<()>` is not implemented for `unsafe fn() -> i32` + = note: unsafe function cannot be called generically without an unsafe block + = note: wrap the `unsafe fn() -> i32` in a closure with no arguments: `|| { /* code */ }` +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:23 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^^^^^^^^^ required by this bound in `require_fn` + +error[E0271]: type mismatch resolving ` i32 as FnOnce<()>>::Output == i32` + --> $DIR/fn-trait.rs:20:16 + | +LL | require_fn(f as unsafe fn() -> i32); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^ types differ + | | + | required by a bound introduced by this call + | +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:31 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^ required by this bound in `require_fn` + +error[E0277]: expected a `Fn()` closure, found `extern "C" fn() -> i32 {g}` + --> $DIR/fn-trait.rs:23:16 + | +LL | require_fn(g); + | ---------- ^ expected an `Fn()` closure, found `extern "C" fn() -> i32 {g}` + | | + | required by a bound introduced by this call + | + = help: the trait `Fn<()>` is not implemented for fn item `extern "C" fn() -> i32 {g}` + = note: wrap the `extern "C" fn() -> i32 {g}` in a closure with no arguments: `|| { /* code */ }` +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:23 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^^^^^^^^^ required by this bound in `require_fn` + +error[E0271]: type mismatch resolving ` i32 {g} as FnOnce<()>>::Output == i32` + --> $DIR/fn-trait.rs:23:16 + | +LL | require_fn(g); + | ---------- ^ types differ + | | + | required by a bound introduced by this call + | +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:31 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^ required by this bound in `require_fn` + +error[E0277]: expected a `Fn()` closure, found `extern "C" fn() -> i32` + --> $DIR/fn-trait.rs:26:16 + | +LL | require_fn(g as extern "C" fn() -> i32); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `Fn()` closure, found `extern "C" fn() -> i32` + | | + | required by a bound introduced by this call + | + = help: the trait `Fn<()>` is not implemented for `extern "C" fn() -> i32` + = note: wrap the `extern "C" fn() -> i32` in a closure with no arguments: `|| { /* code */ }` +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:23 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^^^^^^^^^ required by this bound in `require_fn` + +error[E0271]: type mismatch resolving ` i32 as FnOnce<()>>::Output == i32` + --> $DIR/fn-trait.rs:26:16 + | +LL | require_fn(g as extern "C" fn() -> i32); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ + | | + | required by a bound introduced by this call + | +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:31 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^ required by this bound in `require_fn` + +error[E0277]: expected a `Fn()` closure, found `unsafe fn() -> i32 {h}` + --> $DIR/fn-trait.rs:29:16 + | +LL | require_fn(h); + | ---------- ^ call the function in a closure: `|| unsafe { /* code */ }` + | | + | required by a bound introduced by this call + | + = help: the trait `Fn<()>` is not implemented for fn item `unsafe fn() -> i32 {h}` + = note: unsafe function cannot be called generically without an unsafe block + = note: wrap the `unsafe fn() -> i32 {h}` in a closure with no arguments: `|| { /* code */ }` +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:23 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^^^^^^^^^ required by this bound in `require_fn` + +error[E0271]: type mismatch resolving ` i32 {h} as FnOnce<()>>::Output == i32` + --> $DIR/fn-trait.rs:29:16 + | +LL | require_fn(h); + | ---------- ^ types differ + | | + | required by a bound introduced by this call + | +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:31 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^ required by this bound in `require_fn` + +error: aborting due to 8 previous errors + +Some errors have detailed explanations: E0271, E0277. +For more information about an error, try `rustc --explain E0271`. diff --git a/tests/ui/traits/next-solver/generalize/generalize-proj-new-universe-index-1.rs b/tests/ui/traits/next-solver/generalize/generalize-proj-new-universe-index-1.rs new file mode 100644 index 000000000..4a70bd5f8 --- /dev/null +++ b/tests/ui/traits/next-solver/generalize/generalize-proj-new-universe-index-1.rs @@ -0,0 +1,73 @@ +// compile-flags: -Znext-solver +// check-pass + +// A minimization of an ambiguity when using typenum. See +// https://github.com/rust-lang/trait-system-refactor-initiative/issues/55 +// for more details. +trait Id { + type Assoc: ?Sized; +} +impl Id for T { + type Assoc = T; +} + +trait WithAssoc { + type Assoc: ?Sized; +} + + +struct Leaf; +struct Wrapper(U); + +impl WithAssoc for Leaf { + type Assoc = U; +} + +impl WithAssoc> for Wrapper