-
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
Propagate lifetime resolution errors into tcx.type_of #69178
Propagate lifetime resolution errors into tcx.type_of #69178
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #67681) made this pull request unmergeable. Please resolve the merge conflicts. |
0ab312d
to
bdb0794
Compare
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.
So, I'm not convinced that this should be needed, lifetime resolution isn't handling OpaqueTy
correctly because AST to HIR lowering is treating top level and nested impl Trait
differeny. For example this will still incorrectly error:
#![feature(type_alias_impl_trait)]
trait SomeTrait {}
trait WithAssoc {
type AssocType;
}
impl<T: ?Sized> WithAssoc for T {
type AssocType = ();
}
impl<T: ?Sized> SomeTrait for T {}
type Return<'a> = impl WithAssoc<AssocType = impl Sized + 'a>;
fn my_fun<'a>() -> Return<'a> {}
fn main() {}
@matthewjasper: You're right - there are still issues with lifetimes in nested opaque types (see #69137). This PR doesn't fix those errors - it just ensures that we properly bail out when errors do occur, since opaque type inference may implicitly assume that the opaque type has sane generics. |
☔ The latest upstream changes (presumably #67953) made this pull request unmergeable. Please resolve the merge conflicts. |
Fixes rust-lang#69136 Previously, lifetime resolution errors would cause an error to be emitted, but would not mark the parent type as 'tainted' in any way. We usually abort compilation before this becomes an issue - however, opaque types can cause us to type-check function bodies before such an abort occurs. Ths can result in trying to instantiate opaque types that have invalid computed generics. Currently, this only causes issues for nested opaque types, but there's no reason to expect the computed generics to be sane when we had unresolved lifetimes (which can result in extra lifetime parameters getting added to the generics). This commit tracks 'unresolved lifetime' errors that occur during lifetime resolution. When we type-check an item, we bail out and return `tcx.types.err` if a lifetime error was reported for that type. This causes us to skip type-checking of types affected by the lifetime error, while still checking unrelated types. Additionally, we now check for errors in 'parent' opaque types (if such a 'parent' exists) when collecting constraints for opaque types. This reflects the fact that opaque types inherit generics from 'parent' opaque types - if an error ocurred while type-checking the parent, we don't attempt to type-check the child.
e940496
to
50a3c38
Compare
☔ The latest upstream changes (presumably #69507) made this pull request unmergeable. Please resolve the merge conflicts. |
It should be OK to assume that lifetime resolution is producing sane results, if a lifetime cannot be resolved then not recording it will result in AST conv lowering it as The problem here is that lifetime resolution is recording |
@Aaron1011 waiting for you to resolve the conflicts |
Closing this due to inactivity |
Fixes #69136
Previously, lifetime resolution errors would cause an error to be
emitted, but would not mark the parent type as 'tainted' in any way.
We usually abort compilation before this becomes an issue - however,
opaque types can cause us to type-check function bodies before such an
abort occurs. Ths can result in trying to instantiate opaque types that
have invalid computed generics. Currently, this only causes issues for
nested opaque types, but there's no reason to expect the computed
generics to be sane when we had unresolved lifetimes (which can result
in extra lifetime parameters getting added to the generics).
This commit tracks 'unresolved lifetime' errors that occur during
lifetime resolution. When we type-check an item, we bail out and return
tcx.types.err
if a lifetime error was reported for that type. Thiscauses us to skip type-checking of types affected by the lifetime error,
while still checking unrelated types.
Additionally, we now check for errors in 'parent' opaque types (if such
a 'parent' exists) when collecting constraints for opaque types. This
reflects the fact that opaque types inherit generics from 'parent'
opaque types - if an error ocurred while type-checking the parent,
we don't attempt to type-check the child.