Skip to content

borrowck: Introduce BlameConstraint::to_obligation_cause_from_path()#158624

Open
Enselic wants to merge 1 commit into
rust-lang:mainfrom
Enselic:to_obligation_cause_from_path
Open

borrowck: Introduce BlameConstraint::to_obligation_cause_from_path()#158624
Enselic wants to merge 1 commit into
rust-lang:mainfrom
Enselic:to_obligation_cause_from_path

Conversation

@Enselic

@Enselic Enselic commented Jun 30, 2026

Copy link
Copy Markdown
Member

Before this commit, BlameConstraint is a bit hard to understand at first, because of its ObligationCause field. In practice, BlameConstraint is just a slimmed down version of an OutlivesConstraint from Vec<OutlivesConstraint>.

The artificial ObligationCause is only needed in one place. Rather than having that exception polute the lower level analysis, bubble it up as much as we can. That way, it becomes clearer what BlameConstraint actually is.

For reference, ObligationCause was introdued by #89249, but the codebase looked quite different back then.

This takes us one step closer (this is commit 1 of 4) towards the end result illustrated in #158623.

Notes

I have removed the comment

        // We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
        // Instead, we use it to produce an improved `ObligationCauseCode`.

because I think this existing comment is sufficient:

                // We handle predicates and opaque types specially; don't prioritize them here.
                ConstraintCategory::Predicate(_) | ConstraintCategory::OpaqueType => 4,

Before this commit, `BlameConstraint` is a bit hard to understand at
first, because of its `ObligationCause` field. In practice,
`BlameConstraint` is just a slimmed down version of an
`OutlivesConstraint` from `Vec<OutlivesConstraint>`.

The artificial `ObligationCause` is only needed in one place. Rather
than having that exception polute the lower level analysis, bubble it up
as much as we can. That way, it becomes clearer what `BlameConstraint`
actually is.

For reference, `ObligationCause` was introdued by 93ab12e, but the
codebase looked quite different back then.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 30, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 30, 2026
@rustbot

rustbot commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: borrowck, compiler
  • borrowck, compiler expanded to 73 candidates
  • Random selection from 16 candidates

@Enselic Enselic added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-cleanup Category: PRs that clean code up or issues documenting cleanup. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants