-
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
lazy_type_alias causes lifetime error #114221
Comments
#![feature(lazy_type_alias)]
enum ScopeChain<'a> {
Link(Scope<'a>),
End,
}
type Scope<'a> = &'a ScopeChain<'a>;
struct Context<'a> {
foo: &'a (),
}
impl<'a> Context<'a> {
fn foo(&mut self, scope: Scope) {
let link = if 1 < 2 {
let l = ScopeChain::Link(scope);
self.take_scope(&l);
l
} else {
ScopeChain::Link(scope)
};
}
fn take_scope(&mut self, x: Scope) {}
} |
I'm pretty sure this is due a change in variance … the lifetime params of lazy type aliases are currently unconditionally invariant it seems. |
Minimal pass→fail reproducers (passes without the feature flag and fails with lazy type aliases enabled): contravariant → invariant: struct S<'a>(T<'a>);
type T<'a> = fn(&'a ());
fn f<'a>(s: S<'a>) { let _: S<'static> = s; }
fn main() {} covariant → invariant: struct S<'a>(T<'a>);
type T<'a> = &'a ();
fn f<'a>(s: S<'static>) { let _: S<'a> = s; }
fn main() {} @rustbot label S-has-mcve |
Not expert enough to know if this can & should be fixed (computing variances) or if this works as intended for lazy type aliases 🤔 |
We could theoretically compute variances for lazy type aliases. |
@rustbot claim |
…ty-aliases, r=oli-obk Compute variances for lazy type aliases Fixes rust-lang#114221. CC `@oli-obk` r? types
I tried this code:
tests/ui/regions/regions-scope-chain-example.rs
without `-Zcrate-attr=feature(lazy_type_alias)´: no warnings
with
-Zcrate-attr=feature(lazy_type_alias)
:The text was updated successfully, but these errors were encountered: