Skip to content

Flip "region lattice" in RegionKind doc comment#152968

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
khyperia:regionkind-comment
Mar 17, 2026
Merged

Flip "region lattice" in RegionKind doc comment#152968
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
khyperia:regionkind-comment

Conversation

@khyperia
Copy link
Contributor

If we assume that references take their region covariantly, and use that to define the subtyping relationship of regions, 'empty is ⊤ (top) and 'static is ⊥ (bottom), and that 'a <: 'b is defined as 'a >= 'b. However, the RegionKind doc comment's "region lattice" had 'static at Top. While this is perhaps technically correct (a so-called "region lattice" is not a "type lattice"), it confused me a lot, and took me half an hour to be like "no, ok, I do understand things correctly, this region lattice is just flipped from the subtype lattice". Seems better to just have them be the same!

I also took the opportunity to rewrite some parts of the comment with notes that would have helped me when starting out.

Bikesheds welcome (as long as they don't go on forever)!

For context: the comment "'static is Top" was written in 2013, before there was a discussion in 2014 that clarified that references take their regions covariantly, and 'a <: 'b is defined as 'a >= 'b.

See also Zulip thread: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/RegionKind.20rustc.20doc.20comment

@rustbot rustbot added 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. labels Feb 22, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 22, 2026

r? @jieyouxu

rustbot has assigned @jieyouxu.
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: compiler, types
  • compiler, types expanded to 68 candidates
  • Random selection from 15 candidates

@jieyouxu
Copy link
Member

@rustbot reroll

@rustbot rustbot assigned wesleywiser and unassigned jieyouxu Feb 22, 2026
@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 23, 2026

r? me

@rustbot rustbot assigned BoxyUwU and unassigned wesleywiser Feb 23, 2026
/// function declaration. They have relationships to one another
/// determined based on the declared relationships from the
/// function.
/// Early-bound/free regions ([`RegionKind::ReEarlyParam`]) are the
Copy link
Member

Choose a reason for hiding this comment

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

I think this comment is out of date in that "free regions" here refers to a previously existing RegionKind::Free which got renamed to ReLateParam. This should probably say something like "Early/LateParam regions are the..."

Copy link
Member

Choose a reason for hiding this comment

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

alternatively we did actually mean free regions in which case this includes 'static but talking explicitly about early bound regions is confusing...

Copy link
Member

Choose a reason for hiding this comment

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

maybe this should actually be "Free regions (ReEarlyParam ReLateParam ReStatic) are the named lifetimes in scope from.." i'm not sure 😅

Copy link
Member

Choose a reason for hiding this comment

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

"Early/LateParam regions are the named lifetimes in scope from the function declaration. They have relationships to one another and 'static based on .." is probably the most useful thing to document 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Early/LateParam regions are the named lifetimes in scope from the function declaration

late params can be anonymous, right? just gonna remove the word "named".

Also hm, ReLateParam can be constructed from HKT ReBound stuff (liberate_late_bound_regions), so they're not always "from the function declaration". Maybe flipping the sentence:

Lifetimes in scope from a function declaration are represented via ReEarlyParam/ReLateParam. They have relationships to one another and 'static based on the declared relationships from the function.

because all lifetimes from a function declaration are ReEarlyParam/ReLateParam, but not all ReLateParam are from a function declaration.

///
/// ## Bound Regions
///
/// These are regions that are stored behind a binder and must be instantiated
Copy link
Member

Choose a reason for hiding this comment

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

I think the pre-existing comment here is wrong/wildly misleading. Early bound parameters are not ReBound. This comment implies that a ReBound can correspond to either an early or a late bound parameter but actually it just always corresponds to a lifetime from a for<'a, ...> binder

I would probably drop everything about early/late here and only talk about them in relation to the Binder type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just pushed an edit, how's this?

@khyperia khyperia force-pushed the regionkind-comment branch 2 times, most recently from d0ac5b1 to 40374b4 Compare March 8, 2026 12:20
Copy link
Member

@BoxyUwU BoxyUwU left a comment

Choose a reason for hiding this comment

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

thanks yeah this looks good now :)

View changes since this review

Comment on lines +65 to +66
/// The distinction between early and late exists because higher-ranked
/// lifetimes aren't supported in all places. See [1] [2].
Copy link
Member

Choose a reason for hiding this comment

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

This is a fairly complex topic. I think we should just link to the dev guide chapter on early/late parameters and go "read here for why there are two kinds of parameters"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I just copied this from the original text to preserve it somewhere.

Do you think it's worth it to preserve the links to the blog posts linked here, or should we just link to the dev guide and delete the links to these posts?

Copy link
Member

Choose a reason for hiding this comment

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

hmm, can you drop them but link to them from the dev guide? you should be able to edit it at src/doc/rustc-dev-guide/src/early-late-parameters.md or something like that

Copy link
Member

Choose a reason for hiding this comment

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

probably like a note at the very start of that chapter that goes "see also these blog posts from when this distinction was introduced"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@khyperia khyperia force-pushed the regionkind-comment branch from 40374b4 to 3eb071e Compare March 13, 2026 16:04
@rustbot
Copy link
Collaborator

rustbot commented Mar 13, 2026

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @tshepang

@rustbot rustbot added the A-rustc-dev-guide Area: rustc-dev-guide label Mar 13, 2026
@BoxyUwU
Copy link
Member

BoxyUwU commented Mar 17, 2026

wonderful!

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 17, 2026

📌 Commit 3eb071e has been approved by BoxyUwU

It is now in the queue for this repository.

@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 Mar 17, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Mar 17, 2026
…yUwU

Flip "region lattice" in RegionKind doc comment

If we assume that references take their region covariantly, and use that to define the subtyping relationship of regions, `'empty` is ⊤ (top) and `'static` is ⊥ (bottom), and that `'a <: 'b` is defined as `'a >= 'b`. However, the RegionKind doc comment's "region lattice" had `'static` at Top. While this is perhaps technically correct (a so-called "region lattice" is not a "type lattice"), it confused me a lot, and took me half an hour to be like "no, ok, I *do* understand things correctly, this region lattice is just flipped from the subtype lattice". Seems better to just have them be the same!

I also took the opportunity to rewrite some parts of the comment with notes that would have helped me when starting out.

Bikesheds welcome (as long as they don't go on forever)!

For context: the comment "`'static` is Top" was [written in 2013](rust-lang@a896440#diff-8780054cdf09361c4ac2540c7f544ecfdc52a9e610822aabb8bcd2964affcb1cR430), before there was a [discussion in 2014](rust-lang#15699) that clarified that references take their regions covariantly, and `'a <: 'b` is defined as `'a >= 'b`.

See also Zulip thread: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/RegionKind.20rustc.20doc.20comment
rust-bors bot pushed a commit that referenced this pull request Mar 17, 2026
Rollup of 7 pull requests

Successful merges:

 - #153801 (Add the option to run UI tests with the parallel frontend)
 - #153967 (Tweak wording of failed predicate in inference error)
 - #152968 (Flip "region lattice" in RegionKind doc comment)
 - #153531 (Fix LegacyKeyValueFormat report from docker build: various)
 - #153709 (Fix hypothetical ICE in `variances_of`)
 - #153884 (test `classify-runtime-const` for `f16`)
 - #153946 (dissolve `tests/ui/cross`)
rust-bors bot pushed a commit that referenced this pull request Mar 17, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #153972 (stdarch subtree update)
 - #153801 (Add the option to run UI tests with the parallel frontend)
 - #153959 (Fix non-module `parent_module` in stripped cfg diagnostics)
 - #153967 (Tweak wording of failed predicate in inference error)
 - #152968 (Flip "region lattice" in RegionKind doc comment)
 - #153531 (Fix LegacyKeyValueFormat report from docker build: various)
 - #153622 (remove concept of soft-unstable features)
 - #153709 (Fix hypothetical ICE in `variances_of`)
 - #153884 (test `classify-runtime-const` for `f16`)
 - #153894 (Point at unit structs on foreign crates in type errors when they are the pattern of a binding)
 - #153920 (improve `#[track_caller]` invalid ABI error)
 - #153946 (dissolve `tests/ui/cross`)
 - #153965 (Fix minor kasan bugs)
 - #153991 (Small report_cycle refactor)
@rust-bors rust-bors bot merged commit f7c9081 into rust-lang:main Mar 17, 2026
11 checks passed
@khyperia khyperia deleted the regionkind-comment branch March 17, 2026 21:39
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Mar 18, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#153972 (stdarch subtree update)
 - rust-lang/rust#153801 (Add the option to run UI tests with the parallel frontend)
 - rust-lang/rust#153959 (Fix non-module `parent_module` in stripped cfg diagnostics)
 - rust-lang/rust#153967 (Tweak wording of failed predicate in inference error)
 - rust-lang/rust#152968 (Flip "region lattice" in RegionKind doc comment)
 - rust-lang/rust#153531 (Fix LegacyKeyValueFormat report from docker build: various)
 - rust-lang/rust#153622 (remove concept of soft-unstable features)
 - rust-lang/rust#153709 (Fix hypothetical ICE in `variances_of`)
 - rust-lang/rust#153884 (test `classify-runtime-const` for `f16`)
 - rust-lang/rust#153894 (Point at unit structs on foreign crates in type errors when they are the pattern of a binding)
 - rust-lang/rust#153920 (improve `#[track_caller]` invalid ABI error)
 - rust-lang/rust#153946 (dissolve `tests/ui/cross`)
 - rust-lang/rust#153965 (Fix minor kasan bugs)
 - rust-lang/rust#153991 (Small report_cycle refactor)
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Mar 18, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#153972 (stdarch subtree update)
 - rust-lang/rust#153801 (Add the option to run UI tests with the parallel frontend)
 - rust-lang/rust#153959 (Fix non-module `parent_module` in stripped cfg diagnostics)
 - rust-lang/rust#153967 (Tweak wording of failed predicate in inference error)
 - rust-lang/rust#152968 (Flip "region lattice" in RegionKind doc comment)
 - rust-lang/rust#153531 (Fix LegacyKeyValueFormat report from docker build: various)
 - rust-lang/rust#153622 (remove concept of soft-unstable features)
 - rust-lang/rust#153709 (Fix hypothetical ICE in `variances_of`)
 - rust-lang/rust#153884 (test `classify-runtime-const` for `f16`)
 - rust-lang/rust#153894 (Point at unit structs on foreign crates in type errors when they are the pattern of a binding)
 - rust-lang/rust#153920 (improve `#[track_caller]` invalid ABI error)
 - rust-lang/rust#153946 (dissolve `tests/ui/cross`)
 - rust-lang/rust#153965 (Fix minor kasan bugs)
 - rust-lang/rust#153991 (Small report_cycle refactor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rustc-dev-guide Area: rustc-dev-guide 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.

5 participants