rust/tests/ui/associated-types
bors 6afee111c2 Auto merge of #133858 - dianne:better-blame-constraints-for-static, r=lcnr
`best_blame_constraint`: Blame better constraints when the region graph has cycles from invariance or `'static`

This fixes #132749 by changing which constraint is blamed for region errors in several cases. `best_blame_constraint` had a heuristic that tried to pinpoint the constraint causing an error by filtering out any constraints where the outliving region is unified with the ultimate target region being outlived. However, it used the SCCs of the region graph to do this, which is unreliable; in particular, if the target region is `'static`, or if there are cycles from the presence of invariant types, it was skipping over the constraints it should be blaming. As is the case in that issue, this could lead to confusing diagnostics. The simplest fix seems to work decently, judging by test stderr: this makes `best_blame_constraint` no longer filter constraints by their outliving region's SCC.

There are admittedly some quirks in the test output. In many cases, subdiagnostics that depend on the particular constraint being blamed have either started or stopped being emitted. After starting at this for quite a while, I think anything too fickle about whether it outputs based on the particular constraint being blamed should instead be looking at the constraint path as a whole, similar to what's done for [the placeholder-from-predicate note](https://github.com/rust-lang/rust/compare/master...dianne:rust:better-blame-constraints-for-static#diff-3c0de6462469af483c9ecdf2c4b00cb26192218ef2d5c62a0fde75107a74caaeR506).

Very many tests involving invariant types gained a note pointing out the types' invariance, but in a few cases it was lost. A particularly illustrative example is [tests/ui/lifetimes/copy_modulo_regions.stderr](https://github.com/rust-lang/rust/compare/master...dianne:rust:better-blame-constraints-for-static?expand=1#diff-96e1f8b29789b3c4ce2f77a5e0fba248829b97ef9d1ce39e7d2b4aa57b2cf4f0); I'd argue the new constraint is a better one to blame, but it lacks the variance diagnostic information that's elsewhere in the constraint path. If desired, I can try making that note check the whole path rather than just the blamed constraint.

The subdiagnostic [`BorrowExplanation::add_object_lifetime_default_note`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_borrowck/diagnostics/explain_borrow/enum.BorrowExplanation.html#method.add_object_lifetime_default_note) depends on a `Cast` being blamed, so [a special case](https://github.com/rust-lang/rust/pull/133858/commits/364ca7f99c12fb5220e6b568ac391979317ce878) was necessary to keep it from disappearing from tests specifically testing for it. However, see the FIXME comment in that commit; I think the special case should be removed once that subdiagnostic works properly, but it's nontrivial enough to warrant a separate PR. Incidentally, this removes the note from a test where it was being added erroneously: in [tests/ui/borrowck/two-phase-surprise-no-conflict.stderr](https://github.com/rust-lang/rust/compare/master...dianne:rust:better-blame-constraints-for-static?expand=1#diff-8cf085af8203677de6575a45458c9e6b03412a927df879412adec7e4f7ff5e14), the object lifetime is explicitly provided and it's not `'static`.
2025-01-08 12:37:54 +00:00
..
auxiliary
cache best_blame_constraint: don't filter constraints by sup SCC 2025-01-06 16:08:29 -08:00
associate-type-bound-normalization.rs
associated-item-long-paths.rs
associated-type-destructuring-assignment.rs
associated-type-macro.rs
associated-type-macro.stderr
associated-type-projection-ambig-between-bound-and-where-clause.rs
associated-type-projection-ambig-between-bound-and-where-clause.stderr
associated-type-projection-from-multiple-supertraits.rs
associated-type-projection-from-multiple-supertraits.stderr
associated-type-projection-from-supertrait.rs
associated-type-projection-from-supertrait.stderr
associated-type-shadowed-from-non-local-supertrait.rs
associated-type-shadowed-from-non-local-supertrait.stderr
associated-type-shadowed-from-supertrait.rs
associated-type-shadowed-from-supertrait.stderr
associated-type-struct-construction.rs
associated-type-tuple-struct-construction.rs
associated-type-tuple-struct-construction.stderr
associated-types-basic.rs
associated-types-binding-in-trait.rs
associated-types-binding-in-where-clause.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-binding-to-type-defined-in-supertrait.rs
associated-types-binding-to-type-defined-in-supertrait.stderr
associated-types-bound-ambiguity.rs
associated-types-bound-failure.fixed
associated-types-bound-failure.rs
associated-types-bound-failure.stderr
associated-types-bound.rs
associated-types-cc.rs
associated-types-coherence-failure.rs
associated-types-coherence-failure.stderr
associated-types-conditional-dispatch.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-constant-type.rs
associated-types-doubleendediterator-object.rs
associated-types-duplicate-binding-in-env-hrtb.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-duplicate-binding-in-env.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-enum-field-named.rs
associated-types-enum-field-numbered.rs
associated-types-eq-1.rs
associated-types-eq-1.stderr
associated-types-eq-2.rs chore: fix typos 2024-12-30 14:56:21 +07:00
associated-types-eq-2.stderr Tweak multispan rendering 2024-12-12 23:36:27 +00:00
associated-types-eq-3.rs
associated-types-eq-3.stderr
associated-types-eq-expr-path.rs
associated-types-eq-expr-path.stderr
associated-types-eq-hr.rs
associated-types-eq-hr.stderr
associated-types-eq-obj.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-for-unimpl-trait.fixed
associated-types-for-unimpl-trait.rs
associated-types-for-unimpl-trait.stderr Normalize each signature input/output in typeck_with_fallback with its own span 2025-01-06 17:58:30 +00:00
associated-types-from-supertrait.rs
associated-types-ICE-when-projecting-out-of-err.rs
associated-types-ICE-when-projecting-out-of-err.stderr
associated-types-impl-redirect.rs
associated-types-in-ambiguous-context.rs Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
associated-types-in-ambiguous-context.stderr
associated-types-in-bound-type-arg.rs
associated-types-in-default-method.rs
associated-types-in-fn.rs
associated-types-in-impl-generics.rs
associated-types-in-inherent-method.rs
associated-types-incomplete-object.rs
associated-types-incomplete-object.stderr
associated-types-invalid-trait-ref-issue-18865.rs
associated-types-invalid-trait-ref-issue-18865.stderr
associated-types-issue-17359.rs
associated-types-issue-17359.stderr
associated-types-issue-20220.rs
associated-types-issue-20220.stderr
associated-types-issue-20346.rs
associated-types-issue-20346.stderr
associated-types-issue-20371.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-issue-21212.rs
associated-types-iterator-binding.rs
associated-types-method.rs
associated-types-multiple-types-one-trait.rs
associated-types-multiple-types-one-trait.stderr
associated-types-nested-projections.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-nested-projections.stderr tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-no-suitable-bound.rs
associated-types-no-suitable-bound.stderr Normalize each signature input/output in typeck_with_fallback with its own span 2025-01-06 17:58:30 +00:00
associated-types-no-suitable-supertrait-2.rs
associated-types-no-suitable-supertrait-2.stderr Normalize each signature input/output in typeck_with_fallback with its own span 2025-01-06 17:58:30 +00:00
associated-types-no-suitable-supertrait.rs
associated-types-no-suitable-supertrait.stderr Normalize each signature input/output in typeck_with_fallback with its own span 2025-01-06 17:58:30 +00:00
associated-types-normalize-in-bounds-binding.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-normalize-in-bounds-ufcs.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-normalize-in-bounds.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-normalize-unifield-struct.rs
associated-types-outlives.rs
associated-types-outlives.stderr
associated-types-overridden-binding-2.rs
associated-types-overridden-binding-2.stderr
associated-types-overridden-binding.rs
associated-types-overridden-binding.stderr
associated-types-overridden-default.rs
associated-types-path-1.rs
associated-types-path-1.stderr
associated-types-path-2.rs
associated-types-path-2.stderr
associated-types-project-from-hrtb-in-fn-body.rs
associated-types-project-from-hrtb-in-fn-body.stderr best_blame_constraint: don't filter constraints by sup SCC 2025-01-06 16:08:29 -08:00
associated-types-project-from-hrtb-in-fn.fixed
associated-types-project-from-hrtb-in-fn.rs
associated-types-project-from-hrtb-in-fn.stderr
associated-types-project-from-hrtb-in-struct.rs
associated-types-project-from-hrtb-in-struct.stderr
associated-types-project-from-hrtb-in-trait-method.fixed
associated-types-project-from-hrtb-in-trait-method.rs
associated-types-project-from-hrtb-in-trait-method.stderr
associated-types-project-from-type-param-via-bound-in-where.rs
associated-types-projection-bound-ambiguity.rs
associated-types-projection-bound-in-supertraits.rs
associated-types-projection-from-known-type-in-impl.rs
associated-types-projection-from-known-type-in-impl.stderr
associated-types-projection-in-object-type.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-projection-in-supertrait.rs
associated-types-projection-in-where-clause.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-projection-to-unrelated-trait-in-method-without-default.fixed
associated-types-projection-to-unrelated-trait-in-method-without-default.rs
associated-types-projection-to-unrelated-trait-in-method-without-default.stderr
associated-types-projection-to-unrelated-trait.rs
associated-types-qualified-path-with-trait-with-type-parameters.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-ref-from-struct.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-ref-in-struct-literal.rs
associated-types-region-erasure-issue-20582.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-resolve-lifetime.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
associated-types-return.rs
associated-types-simple.rs
associated-types-stream.rs
associated-types-struct-field-named.rs
associated-types-struct-field-numbered.rs
associated-types-subtyping-1.rs
associated-types-subtyping-1.stderr
associated-types-sugar-path.rs
associated-types-unconstrained.rs
associated-types-unconstrained.stderr
associated-types-unsized.fixed
associated-types-unsized.rs
associated-types-unsized.stderr
associated-types-where-clause-impl-ambiguity.rs
bound-lifetime-constrained.clause.stderr
bound-lifetime-constrained.func.stderr
bound-lifetime-constrained.object.stderr
bound-lifetime-constrained.ok.stderr
bound-lifetime-constrained.rs
bound-lifetime-in-binding-only.angle.stderr
bound-lifetime-in-binding-only.elision.stderr
bound-lifetime-in-binding-only.ok.stderr
bound-lifetime-in-binding-only.paren.stderr
bound-lifetime-in-binding-only.rs
bound-lifetime-in-return-only.elision.stderr
bound-lifetime-in-return-only.local.stderr
bound-lifetime-in-return-only.ok.stderr
bound-lifetime-in-return-only.rs
bound-lifetime-in-return-only.sig.stderr
bound-lifetime-in-return-only.structure.stderr
default-associated-types.rs
defaults-cyclic-fail-1.rs
defaults-cyclic-fail-1.stderr
defaults-cyclic-fail-2.rs
defaults-cyclic-fail-2.stderr
defaults-cyclic-pass-1.rs
defaults-cyclic-pass-2.rs
defaults-in-other-trait-items-pass.rs
defaults-in-other-trait-items.rs
defaults-in-other-trait-items.stderr
defaults-mixed.rs
defaults-mixed.stderr
defaults-specialization.rs
defaults-specialization.stderr
defaults-suitability.current.stderr Use trait name instead of full constraint in suggestion message 2024-12-07 21:29:58 +00:00
defaults-suitability.next.stderr Use trait name instead of full constraint in suggestion message 2024-12-07 21:29:58 +00:00
defaults-suitability.rs
defaults-unsound-62211-1.current.stderr
defaults-unsound-62211-1.next.stderr
defaults-unsound-62211-1.rs
defaults-unsound-62211-2.current.stderr
defaults-unsound-62211-2.next.stderr
defaults-unsound-62211-2.rs
defaults-wf.rs
defaults-wf.stderr
dont-suggest-cyclic-constraint.rs
dont-suggest-cyclic-constraint.stderr
higher-ranked-projection.bad.stderr
higher-ranked-projection.rs
hr-associated-type-bound-1.rs
hr-associated-type-bound-1.stderr
hr-associated-type-bound-2.rs
hr-associated-type-bound-2.stderr
hr-associated-type-bound-object.rs
hr-associated-type-bound-object.stderr
hr-associated-type-bound-param-1.rs
hr-associated-type-bound-param-1.stderr
hr-associated-type-bound-param-2.rs
hr-associated-type-bound-param-2.stderr
hr-associated-type-bound-param-3.rs
hr-associated-type-bound-param-3.stderr
hr-associated-type-bound-param-4.rs
hr-associated-type-bound-param-4.stderr
hr-associated-type-bound-param-5.rs
hr-associated-type-bound-param-5.stderr
hr-associated-type-bound-param-6.rs
hr-associated-type-bound-param-6.stderr Use trait name instead of full constraint in suggestion message 2024-12-07 21:29:58 +00:00
hr-associated-type-projection-1.rs
hr-associated-type-projection-1.stderr Tweak wording 2024-12-07 22:18:51 +00:00
impl-trait-return-missing-constraint.rs
impl-trait-return-missing-constraint.stderr
impl-wf-cycle-1.rs
impl-wf-cycle-1.stderr
impl-wf-cycle-2.rs
impl-wf-cycle-2.stderr
impl-wf-cycle-3.rs
impl-wf-cycle-3.stderr
impl-wf-cycle-4.rs
impl-wf-cycle-4.stderr
impl-wf-cycle-5.fixed
impl-wf-cycle-5.rs
impl-wf-cycle-5.stderr
impl-wf-cycle-6.fixed
impl-wf-cycle-6.rs
impl-wf-cycle-6.stderr
imply-relevant-nested-item-bounds-2.rs
imply-relevant-nested-item-bounds-for-gat.rs
imply-relevant-nested-item-bounds.rs
invalid-ctor.fixed Suggest to replace tuple constructor through projection 2025-01-06 18:04:33 +00:00
invalid-ctor.rs Suggest to replace tuple constructor through projection 2025-01-06 18:04:33 +00:00
invalid-ctor.stderr Suggest to replace tuple constructor through projection 2025-01-06 18:04:33 +00:00
issue-18655.rs
issue-19081.rs
issue-19129-1.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
issue-19129-2.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
issue-19883.rs
issue-19883.stderr
issue-20005.rs
issue-20005.stderr
issue-20763-1.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
issue-20763-2.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
issue-20825-2.rs
issue-20825.rs
issue-20825.stderr
issue-21363.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
issue-21726.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
issue-22037.rs
issue-22037.stderr
issue-22066.rs
issue-22560.rs
issue-22560.stderr
issue-22828.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
issue-23208.rs
issue-23595-1.rs
issue-23595-1.stderr
issue-23595-2.rs
issue-23595-2.stderr
issue-24159.rs
issue-24204.rs
issue-24338.rs
issue-25339.rs
issue-25700-1.rs
issue-25700-2.rs
issue-25700.rs
issue-25700.stderr
issue-26262.rs
issue-26262.stderr
issue-26681.rs
issue-26681.stderr
issue-27675-unchecked-bounds.rs
issue-27675-unchecked-bounds.stderr Use trait name instead of full constraint in suggestion message 2024-12-07 21:29:58 +00:00
issue-27901.rs
issue-28871.rs
issue-31597.rs
issue-32323.rs
issue-32323.stderr
issue-32350.rs
issue-36499.rs
issue-36499.stderr
issue-37808.rs
issue-37883.rs
issue-38821.rs
issue-38821.stderr
issue-38917.rs
issue-39532.rs
issue-40093.rs
issue-41868.rs
issue-43475.rs
issue-43784-associated-type.rs
issue-43784-associated-type.stderr Use trait name instead of full constraint in suggestion message 2024-12-07 21:29:58 +00:00
issue-43924.rs
issue-43924.stderr
issue-44153.rs
issue-44153.stderr
issue-47139-1.rs
issue-47139-2.rs
issue-47385.rs
issue-47814.rs
issue-47814.stderr
issue-48010.rs
issue-48551.rs
issue-50301.rs
issue-54108.current.stderr
issue-54108.next.stderr
issue-54108.rs
issue-54182-1.rs
issue-54182-2.rs
issue-54467.rs
issue-55846.rs
issue-59324.rs
issue-59324.stderr Normalize each signature input/output in typeck_with_fallback with its own span 2025-01-06 17:58:30 +00:00
issue-62200.rs
issue-62200.stderr
issue-63591.rs
issue-63593.current.stderr
issue-63593.next.stderr
issue-63593.rs
issue-64848.rs
issue-64855-2.rs
issue-64855.rs
issue-64855.stderr
issue-65774-1.rs
issue-65774-1.stderr
issue-65774-2.rs
issue-65774-2.stderr
issue-65934.rs
issue-67684.rs
issue-69398.rs
issue-71113.rs
issue-72806.rs
issue-72806.stderr
issue-76179.rs
issue-82079.rs
issue-85103-layout-debug.rs
issue-85103-layout-debug.stderr
issue-87261.rs
issue-87261.stderr
issue-88856.rs
issue-91069.rs
issue-91231.rs
issue-91234.rs
missing-associated-types.rs
missing-associated-types.stderr Fix ICE when multiple supertrait substitutions need assoc but only one is provided 2024-12-11 19:53:40 +00:00
normalization-debruijn-1.rs
normalization-debruijn-2.rs
normalization-debruijn-3.rs
normalization-generality-2.rs
normalization-generality.rs
normalization-probe-cycle.rs
normalize-cycle-in-eval-no-region.rs
normalize-cycle-in-eval.rs
object-method-numbering.rs
object-normalization.rs
param-env-normalize-cycle.rs
point-at-type-on-obligation-failure-2.rs
point-at-type-on-obligation-failure-2.stderr
point-at-type-on-obligation-failure.rs
point-at-type-on-obligation-failure.stderr
project-defer-unification.rs chore: fix typos 2024-12-30 14:56:21 +07:00
project-recursion-limit-non-fatal.rs
remove-invalid-type-bound-suggest-issue-127555.rs Report impl has stricter requirements even when RPITIT inference gets in the way 2025-01-03 02:45:29 +00:00
remove-invalid-type-bound-suggest-issue-127555.stderr Report impl has stricter requirements even when RPITIT inference gets in the way 2025-01-03 02:45:29 +00:00
substs-ppaux.normal.stderr
substs-ppaux.rs
substs-ppaux.verbose.stderr
trait-with-supertraits-needing-sized-self.rs
trait-with-supertraits-needing-sized-self.stderr
wf-cycle-2.rs
wf-cycle.rs