Skip to content

borrowck: Introduce BlameConstraint::to_obligation_cause_from_path()#158624

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Enselic:to_obligation_cause_from_path
Jul 5, 2026
Merged

borrowck: Introduce BlameConstraint::to_obligation_cause_from_path()#158624
rust-bors[bot] merged 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 logic, 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

@JohnTitor JohnTitor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors

rust-bors Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

📌 Commit e2af9c0 has been approved by JohnTitor

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 10. This pull request will be tested once the tree is reopened.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 3, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 3, 2026
…ath, r=JohnTitor

borrowck: Introduce BlameConstraint::to_obligation_cause_from_path()

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 logic, bubble it up as much as we can. That way, it becomes clearer what `BlameConstraint` actually is.

For reference, `ObligationCause` was introdued by rust-lang#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 rust-lang#158623.

# Notes

I have removed the comment

```rs
        // 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](https://github.com/rust-lang/rust/blob/e2af9c03ef4cfb769e391968a5cfbb1afe6f01e2/compiler/rustc_borrowck/src/region_infer/mod.rs#L1763-L1762) existing comment is sufficient:

```rs
                // We handle predicates and opaque types specially; don't prioritize them here.
                ConstraintCategory::Predicate(_) | ConstraintCategory::OpaqueType => 4,
```
rust-bors Bot pushed a commit that referenced this pull request Jul 5, 2026
Rollup of 18 pull requests

Successful merges:

 - #158692 (Add release notes for 1.96.1)
 - #134021 (Implement `IntoIterator` for `[&[mut]] Box<[T; N], A>`)
 - #152860 (Port the `without_debuginfo` test from `backtrace-rs` to the testsuite)
 - #155932 (MIR Call terminator: evaluate destination place before arguments)
 - #156777 (Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust)
 - #157151 (JSON target specs: remove 'x86-softfloat' compatibility alias)
 - #157835 (expand free alias types in the auto-trait orphan check)
 - #158377 (add `-Zforce-intrinsic-fallback` flag)
 - #158434 (delegation: refactor AST -> HIR lowering)
 - #158552 (make some tidy errors around python easier to understand)
 - #158624 (borrowck: Introduce BlameConstraint::to_obligation_cause_from_path())
 - #158704 (Optimize `ArrayChunks::try_rfold` with `DoubleEndedIterator::next_chunk_back`)
 - #158711 (library: Comment on libtest's dicey internal soundness)
 - #158539 (Move `SizeHint` and `IoHandle` to `core::io`)
 - #158659 (refactor the normalization in `coerce_shared_info`)
 - #158689 (resolver: don't use `Finalize` when resolving visibilities during AST expansion)
 - #158698 (Update TypeVisitable implementation)
 - #158706 (Tweaks to MIR building scope API)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 5, 2026
…ath, r=JohnTitor

borrowck: Introduce BlameConstraint::to_obligation_cause_from_path()

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 logic, bubble it up as much as we can. That way, it becomes clearer what `BlameConstraint` actually is.

For reference, `ObligationCause` was introdued by rust-lang#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 rust-lang#158623.

# Notes

I have removed the comment

```rs
        // 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](https://github.com/rust-lang/rust/blob/e2af9c03ef4cfb769e391968a5cfbb1afe6f01e2/compiler/rustc_borrowck/src/region_infer/mod.rs#L1763-L1762) existing comment is sufficient:

```rs
                // We handle predicates and opaque types specially; don't prioritize them here.
                ConstraintCategory::Predicate(_) | ConstraintCategory::OpaqueType => 4,
```
rust-bors Bot pushed a commit that referenced this pull request Jul 5, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #158692 (Add release notes for 1.96.1)
 - #134021 (Implement `IntoIterator` for `[&[mut]] Box<[T; N], A>`)
 - #155932 (MIR Call terminator: evaluate destination place before arguments)
 - #155989 (Update `transmute_copy` to ub_checks and `?Sized`)
 - #156777 (Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust)
 - #157151 (JSON target specs: remove 'x86-softfloat' compatibility alias)
 - #157835 (expand free alias types in the auto-trait orphan check)
 - #157857 (Stabilize `#[my_macro] mod foo;` (part of `proc_macro_hygiene`))
 - #158377 (add `-Zforce-intrinsic-fallback` flag)
 - #158434 (delegation: refactor AST -> HIR lowering)
 - #158552 (make some tidy errors around python easier to understand)
 - #158624 (borrowck: Introduce BlameConstraint::to_obligation_cause_from_path())
 - #158704 (Optimize `ArrayChunks::try_rfold` with `DoubleEndedIterator::next_chunk_back`)
 - #158711 (library: Comment on libtest's dicey internal soundness)
 - #158751 (rustdoc: Fix crash when trying to inline foreign item which cannot have attributes)
 - #158539 (Move `SizeHint` and `IoHandle` to `core::io`)
 - #158659 (refactor the normalization in `coerce_shared_info`)
 - #158689 (resolver: don't use `Finalize` when resolving visibilities during AST expansion)
 - #158698 (Update TypeVisitable implementation)
 - #158706 (Tweaks to MIR building scope API)
rust-bors Bot pushed a commit that referenced this pull request Jul 5, 2026
…uwer

Rollup of 19 pull requests

Successful merges:

 - #158692 (Add release notes for 1.96.1)
 - #134021 (Implement `IntoIterator` for `[&[mut]] Box<[T; N], A>`)
 - #155932 (MIR Call terminator: evaluate destination place before arguments)
 - #155989 (Update `transmute_copy` to ub_checks and `?Sized`)
 - #156777 (Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust)
 - #157151 (JSON target specs: remove 'x86-softfloat' compatibility alias)
 - #157835 (expand free alias types in the auto-trait orphan check)
 - #157857 (Stabilize `#[my_macro] mod foo;` (part of `proc_macro_hygiene`))
 - #158434 (delegation: refactor AST -> HIR lowering)
 - #158552 (make some tidy errors around python easier to understand)
 - #158624 (borrowck: Introduce BlameConstraint::to_obligation_cause_from_path())
 - #158704 (Optimize `ArrayChunks::try_rfold` with `DoubleEndedIterator::next_chunk_back`)
 - #158711 (library: Comment on libtest's dicey internal soundness)
 - #158751 (rustdoc: Fix crash when trying to inline foreign item which cannot have attributes)
 - #158539 (Move `SizeHint` and `IoHandle` to `core::io`)
 - #158659 (refactor the normalization in `coerce_shared_info`)
 - #158689 (resolver: don't use `Finalize` when resolving visibilities during AST expansion)
 - #158698 (Update TypeVisitable implementation)
 - #158706 (Tweaks to MIR building scope API)
@rust-bors rust-bors Bot merged commit 4a436da into rust-lang:main Jul 5, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jul 5, 2026
rust-timer added a commit that referenced this pull request Jul 5, 2026
Rollup merge of #158624 - Enselic:to_obligation_cause_from_path, r=JohnTitor

borrowck: Introduce BlameConstraint::to_obligation_cause_from_path()

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 logic, 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

```rs
        // 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](https://github.com/rust-lang/rust/blob/e2af9c03ef4cfb769e391968a5cfbb1afe6f01e2/compiler/rustc_borrowck/src/region_infer/mod.rs#L1763-L1762) existing comment is sufficient:

```rs
                // We handle predicates and opaque types specially; don't prioritize them here.
                ConstraintCategory::Predicate(_) | ConstraintCategory::OpaqueType => 4,
```
@theemathas theemathas modified the milestones: 1.98.0, 1.99.0 Jul 6, 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

4 participants