Uh oh!
There was an error while loading. Please reload this page.
RFC for removing integer inference fallback - #115
Conversation
There was a problem hiding this comment.
Perhaps default type parameters could be dual-purposed to provide a fallback type for this case (see rust-lang/rust#13702). I.e. the signature of range would become:
pubfnrange<A:Add<A,A> + PartialOrd + Clone + One = uint>(start:A,stop:A) -> Range<A>although it wasn't clear to me if the original issue was motivated by this very function defaulting to int too often.
alexcrichton
commented
Jun 11, 2014
It would be nice to have statistics on the amount of the changes required (ascriptions necessary) to code after these tweaks were implemented. This is a difficult statistic to gather, however, and I would think that it would fall out of the implementation regardless. |
There was a problem hiding this comment.
Do you really mean "cast" here?
There was a problem hiding this comment.
No, I meant 'provide type hints'. Will change.
bstrie
commented
Jun 12, 2014
I think I'm for this. In ancient Rust this was a useful hack, but nowadays it's probably too magical. And if we decide that we want the old behavior again later, adding the integral fallback back in would be a backwards-compatible change, yeah? |
thestinger
commented
Jun 12, 2014
@bstrie: Yeah, adding a fallback would be backwards compatible. In the case of floats, I think |
pcwalton
commented
Jun 12, 2014
@alexcrichton I believe @nikomatsakis has already gathered these statistics. |
brendanzab
commented
Jun 12, 2014
I'm in favor of this. I have been bitten by it before too. |
Kimundi
commented
Jun 12, 2014
I'm also in favor of this. |
There was a problem hiding this comment.
Shouldn't enum discriminants be the smallest type that allows to represent them all? (with preference for either signed or unsigned, not sure)
Or maybe we could introduce integer range types, and then it could be the smallest range covering them all, with no ambiguity.
There was a problem hiding this comment.
I believe that is going to be the rule. Enums are the smallest type (probably not specced as such), unless using #[repr(...)].
bstrie
commented
Jun 12, 2014
@thestinger, I'm fine with the f64 fallback for floats because at least it's falling back to a type whose size doesn't vary per-platform. In the past I've floated the idea of changing our integral fallback from int to i32, but that may very well be a worse idea than just removing the fallback altogether. :) |
nikomatsakis
commented
Jun 12, 2014
@alexcrichton I did gather such statistics in the original issue. |
alexcrichton
commented
Jun 12, 2014
@nikomatsakis, @pcwalton ah of course, I forgot! For those wondering, the analysis is here: https://gist.github.com/nikomatsakis/11179747 |
brson
commented
Jun 18, 2014
alexcrichton
commented
Jun 18, 2014
Merging per the discussion that @brson has linked to. |
alexchandel
commented
Jun 28, 2014
Too bad I arrived late to the party. Feel free to show me the light, but this feels like a significant backwards step in the elegance of Rust. When I type "let a = 4", I expect |
thestinger
commented
Jun 28, 2014
Integer literals are generic, the type of |
Rust infers primitive integer types, but when it can't find a solution it currently defaults to
int. This is often seen as a potential subtle footgun. This RFC describes how to remove the feature, per rust-lang/rust#6023.