Skip to content
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

Treat weak alias types more like ADTs when computing implied bounds #122340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fmease
Copy link
Member

@fmease fmease commented Mar 11, 2024

For context, we want to treat lazy type aliases / weak alias types just like ADTs when computing implied bounds (#118479, T-lang design meeting 2023-11-09) but the way I've implemented it in #119350, there are some deviations in behavior which this PR eliminates.

I found this oversight while trying to build alloc with LTAs enabled by default: struct ExtractIfInner<'a, K, V> would no longer build requiring the explicit bounds K: 'a and V: 'a.

With this patch, we imply K: 'a, V: 'a instead of Alias<K, V>: 'a in the following code which is consistent with ADTs:

struct ExtractIfInner<'a, K, V>(&'a mut Root<K, V>);
/*lazy*/ type Root<K, V> = (K, V);

Instead of treating weak alias types as abstract when computing the outlives-components like we do for the other kinds of alias types, we shallowly walk their generic args like we do with ADTs.

This is yet another case in a series (#121344, #120780) where weak alias types deviate in behavior from the other kinds of alias types, well... ^^'.

r? @oli-obk

@fmease fmease added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-types Relevant to the types team, which will review and decide on the PR/issue. A-implied-bounds Area: Implied bounds / inferred outlives-bounds F-lazy_type_alias `#![feature(lazy_type_alias)]` labels Mar 11, 2024
@@ -144,7 +144,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
}
}

fn is_free_region(region: Region<'_>) -> bool {
fn is_early_bound_region(region: Region<'_>) -> bool {
Copy link
Member Author

@fmease fmease Mar 11, 2024

Choose a reason for hiding this comment

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

Just a drive-by renaming, cc #117908. I don't know why this used the term free (ReLateParam). It should've always been named is_early_bound_region or sth. in that vein.

@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the lta-implied-bounds-recurse-shallow branch from 118c6c1 to c5165ba Compare March 11, 2024 18:21
@@ -5,7 +5,6 @@ mod test_lifetime_param {
fn defining(a: &str) -> Ty<'_> { a }
fn assert_static<'a: 'static>() {}
fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
//~^ ERROR: lifetime may not live long enough
Copy link
Member Author

Choose a reason for hiding this comment

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

👀

Copy link
Member Author

@fmease fmease Mar 11, 2024

Choose a reason for hiding this comment

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

WeakTy<'co>: 'static now implies 'co: 'static similar to ADTs. Is that fine / sound?

Copy link
Contributor

@oli-obk oli-obk Mar 19, 2024

Choose a reason for hiding this comment

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

it is, but we need tests that show that we actually enforce it, too. I don't know if we have any weak alias type tests for that, even if we have old-style type alias tests for it

@@ -27,7 +26,6 @@ mod test_type_param {
fn defining<A>(s: A) -> Ty<A> { s }
fn assert_static<A: 'static>() {}
fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
//~^ ERROR: parameter type `A` may not live long enough
Copy link
Member Author

Choose a reason for hiding this comment

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

👀

Copy link
Member Author

@fmease fmease Mar 11, 2024

Choose a reason for hiding this comment

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

Similarly, WeakTy<Co>: 'static now implies Co: 'static similar to ADTs. Is that acceptable?

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 23, 2024
@bors
Copy link
Contributor

bors commented Jun 12, 2024

☔ The latest upstream changes (presumably #113169) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnCSimon
Copy link
Member

@fmease
ping from triage - can you post your status on this PR? This PR has not received an update in a few months and has merge conflicts

@alex-semenyuk alex-semenyuk added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-implied-bounds Area: Implied bounds / inferred outlives-bounds F-lazy_type_alias `#![feature(lazy_type_alias)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants