-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
base: master
Are you sure you want to change the base?
Conversation
@@ -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 { |
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
118c6c1
to
c5165ba
Compare
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
There was a problem hiding this comment.
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?
☔ The latest upstream changes (presumably #113169) made this pull request unmergeable. Please resolve the merge conflicts. |
@fmease |
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 boundsK: 'a
andV: 'a
.With this patch, we imply
K: 'a
,V: 'a
instead ofAlias<K, V>: 'a
in the following code which is consistent with ADTs: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