Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upChange which type variables fall back to `!` #40801
Comments
This comment has been minimized.
This comment has been minimized.
nikomatsakis
referenced this issue
Mar 24, 2017
Open
Tracking issue for promoting `!` to a type (RFC 1216) #35121
nikomatsakis
added
T-compiler
T-lang
A-typesystem
and removed
T-compiler
labels
Mar 24, 2017
This comment has been minimized.
This comment has been minimized.
|
Your change is far more easily visible - it allows you to do |
This comment has been minimized.
This comment has been minimized.
|
@arielb1 True, though I would argue that they are both easily visible -- using the |
This comment has been minimized.
This comment has been minimized.
|
Apparently Perhaps here the problem isn't that |
This comment has been minimized.
This comment has been minimized.
I see. So, yeah ,basically, the reason that |
Mark-Simulacrum
added
the
C-feature-request
label
Jul 27, 2017
shepmaster
changed the title
change which type variables fallback to `!`
Change which type variables fall back to `!`
Aug 3, 2017
This comment has been minimized.
This comment has been minimized.
|
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 |
nikomatsakis
closed this
Oct 25, 2017
This comment has been minimized.
This comment has been minimized.
|
Sounds fine to me. By the way |
This comment has been minimized.
This comment has been minimized.
|
I'm not totally clear on the resolution here-- does this mean that |
This comment has been minimized.
This comment has been minimized.
|
No - the final decision is to create |
nikomatsakis commentedMar 24, 2017
•
edited
Right now, type variables fallback to
!if they are the result of areturnetc. 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.