Skip to content

Well-formedness dev guide page#2889

Open
fallible-algebra wants to merge 6 commits into
rust-lang:mainfrom
fallible-algebra:types-overhaul/wellformedness
Open

Well-formedness dev guide page#2889
fallible-algebra wants to merge 6 commits into
rust-lang:mainfrom
fallible-algebra:types-overhaul/wellformedness

Conversation

@fallible-algebra
Copy link
Copy Markdown

@fallible-algebra fallible-algebra commented Jun 3, 2026

Initial work off of discussions with boxy + chasing hyperlinks.

Few unsolved items here:

  • Conceptual: Items "contain" Terms? Is this the right way to say this? I imagine so, syntactically, but I need a vibe check.
  • More links in more places
  • Remove the "boxy said so" citations
  • "Term"1 needs to be better specified as a concept. Maybe added to the glossary.
  • Should Wfck (well-formedness check) be in the glossary? Should Wfck be the term used here?
  • ??? I'm sure I'm missing something here. Draft PR.
  • Need to run the formatter that deals with maximum line length.
  • Remove the unused links

I've also ended up doing some syntax here "from scratch", which I could use some input on. Specifically for showing off obligations I've done:

<Items or Terms>
---
<Obligations and (relevant) Substitutions>

If this works fine, cool. Otherwise, open to being told to do it a different way :)

Finally, I'm putting this in an analysis subfolder as I've been told we need to do some structural reordering of the mdbook directory, and this should eventually live in an analysis subfolder so might as well have it there now.

Footnotes

  1. This was "Type-Level Term" in these files before I find-replaced it all to Term, which is maybe too vague to our target audience.

@BoxyUwU BoxyUwU self-assigned this Jun 3, 2026
@fallible-algebra fallible-algebra marked this pull request as ready for review June 3, 2026 15:34
@rustbot rustbot added the S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content label Jun 3, 2026

During wfck we encounter the obligation for `Vec<T>` that `T: Sized`. For `Vec<str>` we encounter the obligation `str: Sized`, and as `str` is not `Sized` the term is not well-formed.

### We Don't Need Normalization (Yet)
Copy link
Copy Markdown
Member

@BoxyUwU BoxyUwU Jun 4, 2026

Choose a reason for hiding this comment

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

when i talk about normalization im referring to the process of replacing aliases with the aliased type (see https://rustc-dev-guide.rust-lang.org/normalization.html), which is orthogonal from whether a term has generic parameters in it or not.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Right, got wires crossed with monomorphization. This makes why this is problematic make a lot more sense ^^

Comment thread src/analysis/well-formed.md Outdated

Wfck doesn't check or validate lifetimes, this is handled in [MIR](../borrow-check.md).

## Generating Obligations
Copy link
Copy Markdown
Member

@BoxyUwU BoxyUwU Jun 4, 2026

Choose a reason for hiding this comment

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

I think this makes more sense as being part of the wfness of terms section, item wfck doesn't really start by doing this

View changes since the review

Comment thread src/analysis/well-formed.md Outdated

This produces an obligation that still has a generic in it. While more normalized versions of `Struct<T>` may not be `Ord`, we can say that `Set<Struct<T>>` is well-formed when `T: Ord`.

### Const Generic Arguments
Copy link
Copy Markdown
Member

@BoxyUwU BoxyUwU Jun 4, 2026

Choose a reason for hiding this comment

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

Comment thread src/analysis/well-formed.md Outdated

Here we have a trivial bound that does not hold, because `String` is not `Copy`.

## When We Don't Fully Do Wfck
Copy link
Copy Markdown
Member

@BoxyUwU BoxyUwU Jun 4, 2026

Choose a reason for hiding this comment

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

i think as a general rule we should never just say "wfck" on its own in this, we should always explicitly say if we're talking about wfness of terms or checking wf of items.

View changes since the review

Comment thread src/analysis/well-formed.md Outdated
@@ -0,0 +1,166 @@
# Well-Formedness of Terms and Items

The area of the analysis pipeline that deals with questions like "does `T: Debug` hold true for some data structure that uses T?" or "is this const generic parameter `const B: bool` being handed a value of the right type?"
Copy link
Copy Markdown
Member

@BoxyUwU BoxyUwU Jun 4, 2026

Choose a reason for hiding this comment

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

this feels slightly off to me, i would say the trait solver deals with those questions. though i guess that kind of makes sense since the trait solver is also responsible for proving wf obligations (i.e. checking terms are wf when we require them to be)

View changes since the review

fallible-algebra and others added 2 commits June 5, 2026 09:33
Co-authored-by: Boxy <rust@boxyuwu.dev>
@fallible-algebra fallible-algebra requested a review from BoxyUwU June 5, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants