Skip to content

Infer implied outlives from fn signature - #412

Open
kirloo wants to merge 12 commits into
rust-lang:mainfrom
kirloo:fn_implied_bounds-clean
Open

Infer implied outlives from fn signature#412
kirloo wants to merge 12 commits into
rust-lang:mainfrom
kirloo:fn_implied_bounds-clean

Conversation

@kirloo

@kirloo kirloo commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #405
Closes #202

How does it work, what questions do you have?

I created a new function implied_outlives_for_fn which goes through input argument and output types for a function and produces a Wcs corresponding to the function's implied outlives bounds. When encountering a ref it creates a WhereClause::Outlives for the inner type and the outer lifetime. The function recurses to handle nested borrows. The final Wcs is included in the assumptions of check_fn.

I think the logic seems sound and all tests pass, but:

  • I'm not sure if I'm handling the case of multiple type parameters correctly (e.g. &'a HashMap<&'b K,&'c V>)
  • I'm not sure if I'm handling the Arc in Parameter::Lt correctly.
  • I'm not sure about function names and file structure.

Some old tests had to be updated due to the new assumptions.

This is a second attempt at #407 after I messed up the history trying to merge test updates.

AI disclosure

  • I used an AI tool for research, autocomplete, or in other minimal ways

@rustbot

rustbot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Thanks for contributing to formality! :)
A reviewer will take a look at your PR within a week or two. If not, come talk to us on https://rust-lang.zulipchat.com/#narrow/channel/402470-t-types.2Fformality

@kirloo

kirloo commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@nikomatsakis Now everything is in judgment functions

Comment thread tests/implied_bounds.rs
@rustbot

This comment has been minimized.

@kirloo
kirloo force-pushed the fn_implied_bounds-clean branch from f969552 to 1d6cbcb Compare July 22, 2026 07:22
@rustbot

This comment has been minimized.

Comment thread crates/formality-rust/src/check/implied_bounds.rs Outdated
Comment thread crates/formality-rust/src/check/implied_bounds.rs Outdated
Comment thread crates/formality-rust/src/check/implied_bounds.rs Outdated
Comment thread crates/formality-rust/src/check/fns.rs
@nikomatsakis

Copy link
Copy Markdown
Contributor

I guess I got a suggestion wrong @kirloo

 Error:   --> /home/runner/work/a-mir-formality/a-mir-formality/crates/formality-rust/src/check/implied_bounds.rs:40:1
   |
24 |     ) => Wcs {
   |              - the nearest open delimiter
...
32 |         )
   |         - missing open `(` for this delimiter
...
40 | }
   | ^ unexpected closing delimiter

@kirloo
kirloo force-pushed the fn_implied_bounds-clean branch from 3781404 to 003b218 Compare August 5, 2026 15:43
@rustbot

This comment has been minimized.

@kirloo
kirloo requested a review from nikomatsakis August 6, 2026 07:16
@rustbot

This comment has been minimized.

@rustbot

rustbot commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@kirloo
kirloo force-pushed the fn_implied_bounds-clean branch from ba53f20 to 124e52f Compare August 7, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested borrow failure Model implied bounds

4 participants