-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lifetime order breaks member constraints #104639
Comments
@rustbot claim |
Here is the code of concern rust/compiler/rustc_borrowck/src/region_infer/mod.rs Lines 746 to 769 in e07425d
The code should calculate the The goal here is to find a unique minimum choice that is known to be outlived by all other regions. If none can be found, the function returns Regions that have cycles between them are considered equivalent so we can pick either one of them as a unique choice. e.g. |
…e-check, r=oli-obk Find the right lower bound region in the scenario of partial order relations Fixes rust-lang#104639
…e-check, r=oli-obk Find the right lower bound region in the scenario of partial order relations Fixes rust-lang#104639
rework min_choice algorithm of member constraints See [this comment](rust-lang#105300 (comment)) for the description of the new algorithm. Fixes rust-lang#63033 Fixes rust-lang#104639 This uses a more general algorithm than rust-lang#89056 that doesn't treat `'static` as a special case. It thus accepts more code. For example: ```rust async fn test2<'s>(_: &'s u8, _: &'_ &'s u8, _: &'_ &'s u8) {} ``` I claim it's more correct as well because it fixes rust-lang#104639. cc `@nikomatsakis` `@lqd` `@tmandry` `@eholk` `@chenyukang` `@oli-obk` r? types
rework min_choice algorithm of member constraints See [this comment](rust-lang#105300 (comment)) for the description of the new algorithm. Fixes rust-lang#63033 Fixes rust-lang#104639 This uses a more general algorithm than rust-lang#89056 that doesn't treat `'static` as a special case. It thus accepts more code. For example: ```rust async fn test2<'s>(_: &'s u8, _: &'_ &'s u8, _: &'_ &'s u8) {} ``` I claim it's more correct as well because it fixes rust-lang#104639. cc ``@nikomatsakis`` ``@lqd`` ``@tmandry`` ``@eholk`` ``@chenyukang`` ``@oli-obk`` r? types
The following code should pass regardless of the declaration order of lifetimes: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=88e227f9f7a5b516bffe21e09b18cd5e
This is related to #63033 but it's different in that we do have a lower bound region,
'c
, but we fail to recognize that because the algorithm here, which is responsible for calculatingmin_choice
fromchoice_regions = ['static, 'a, 'b, 'c]
, assumes that the outlive relation is a total order, which is not true.Here is the graph of
self.universal_region_relations
:So we need an efficient algorithm that works for partial order relations, but the one that comes to mind is
O(n^2)
. The perf may not be really important here but I'm curious to see the alternatives.@rustbot label C-bug T-compiler A-borrow-checker E-mentor E-help-wanted
The text was updated successfully, but these errors were encountered: