-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Change which type variables fall back to !
#40801
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
Comments
cc @rust-lang/lang @canndrew |
Your change is far more easily visible - it allows you to do |
@arielb1 True, though I would argue that they are both easily visible -- using the |
Apparently Perhaps here the problem isn't that |
I see. So, yeah ,basically, the reason that |
!
!
So @arielb1 and I were talking about this. We decided to close this issue on the following grounds:
Just for future reference, the relevant examples are:
match Err(E) {
Ok(v) => v, // yields an unconstrainted type variable `?T`
Err(e) => return Err(e) // yields an unconstrained type variable `?U` with fallback
} As a result, However, today's rules do something undesirable in a case like this (which occurred in serde)
what happens here is that this "desugars" to
where The proposed rule here would result in an "unresolved type variable error" -- which is better, but backwards incompatible. However, the proposed rule will default in an example like this:
The end-result is that the call to deserialize is |
Sounds fine to me. By the way |
I'm not totally clear on the resolution here-- does this mean that |
No - the final decision is to create |
Right now, type variables fallback to
!
if they are the result of areturn
etc. The idea was that this represents a "dead control flow path", but it is not clear that this is the right rule, because those type variables often get 'caught up' in other paths.In #40224, I outlined another possibility in a comment:
in particular, this would mean that
Deserialize::deserialize()?;
would error out, whereas today it defaults to deserializing the!
type (and hence ... probably ... panics?). This feels like a case where I would expect an "unconstrained type variable" error -- but we don't get one today because one of the arms is dead, and hence generates a diverging fallback when coerced.There is an obvious backwards compatibility concern here. It's not clear how much we can change these paths. But I suspect we have some leeway, if what we do is tailored enough.
The text was updated successfully, but these errors were encountered: