-
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
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.
WeakAlias<'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, WeakAlias<Co>: 'static
now implies Co: 'static
similar to ADTs. Is that acceptable?
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
c5165ba
to
0e7952c
Compare
I'm having second thoughts about this. Treating weak aliases like ADTs during infer_outlives, i.e., super-visiting them is meh (visiting its generic arguments), esp. for TAIT. Weak aliases aren't really nominal after all. Let's take a look at ADTs: I can see why it's convenient to imply the bound For example, for So for weak aliases, this ADT-behavior would be even "worse". I don't think we want to imply the bound #![feature(lazy_type_alias)]
type Ty<'a, T: Trait> = &'a Aux<T>;
type Aux<T: Trait> = T::P;
trait Trait { type P; } On master, we imply the bound Yet again, I'm wondering if we should instead employ " Ignoring the details for now, the " type Opaque<T> = impl Sized;
fn define<T>() -> Opaque<T> {}
struct Ty<'a, T>(&'a Opaque<T>); On this branch, we currently imply the bound @oli-obk, thoughts? ^^' |
In summary, the options might be:
|
can we somehow automatically encode this by wrapping weak alias types in a binder that has lifetimes for anything we could possibly want to bind? I guess this would be "precomputing" your option 3 and force every weak alias use site to think about what it wants. |
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 ofRoot<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