I found a problem with the way we were doing default-number resolution.
as an example, in #12228, argv.fold(0, |size, arg| size + arg.to_utf8().len() did not have enough type information for the compiler to figure out what type size should have, because size + arg.to_utf8().len() desugars to size.plus(arg.to_utf8().len()) and the only type information it has about size at that point is that it starts at 0 (from the first argument to fold) - so it's a number, but it could be any number, even a custom user-defined number!
we used to require that when desugaring operators, the plus method call we desugared + into would be required to have the type a, a -> a - so, its arguments and return type are all the same type. That fixes this case (because arg.to_utf8().len() returns U64, which in turn means size must be U64, and size.plus(...) resolves to U64.plus(...) - but that relies on plus having the constraint of "both arguments and the return type have the same type.")
we changed this so that operator desugaring could be more flexible, e.g. so a Duration could support * on a U64, e.g. my_duration * 12 instead of requiring the 12 to also have the type Duration
and there was another thread on Zulip somewhere (I forget where offhand) where there was interest in relaxing this all the way to just a + b desugars to a.plus(b)
I discovered there are some pretty substantial performance downsides to the sort of "in-between" approach we were doing for this, where we partially constrained the desugared methods and then also had some builtin-specific special-cases (for number types other than Dec)
I think this is going to be a bit of a design rabbit hole, weighing the tradeoffs and compiler perf, so for 0.1.0 I've decided to go back to the option that has the best compiler perf (and also works the best for the builtin number types and "normal" custom numbers) even though it's the least flexible in terms of user-defined types: require a, a -> a for plus and similar
this will give everyone the best build times (and number literals and arithmetic come up a lot, so degrading perf for them is not a small downside) and also the fewest incidents of type errors due to the compiler not knowing which type you meant (such as the example from the issue above)
then from that baseline, we can discuss motivating examples (like Duration) that could justify changing the desugaring rules, what it would cost in terms of compiler perf and examples like the issue here becoming compiler errors vs. the benefits, etc. - sometime after 0.1.0 ships
in the immediate term, that will be a breaking change, because stuff like Duration will need to change its types
this hasn't landed yet, but I wanted to announce it in advance since it's coming
separately, there's another breaking change which hopefully will be pretty minor: I discovered that shadowing rules weren't being applied correctly in nested type declarations. so if you have nested type declarations, once that lands, you might start seeing shadowing warnings for things that were always shadowing but which previously didn't cause a warning.
11 messages were moved from this topic to #ideas > requiring more type annotations? by Anton.
and there was another thread on Zulip somewhere (I forget where offhand) where there was interest in relaxing this all the way to just
a + bdesugars toa.plus(b)
#beginners > Binary search / Interpolation search
The shadowing change seems to have introduced a regression: when the same function is defined in a type and its nested type, then we get a duplicate definition warning, even though these are two different types. In some cases, it's easy to work around this issue by just renaming one function, but when it's a special function (e.g., is_eq), then there's no workaround. This broke 3 Exercism exercises. I filed issue #13192.
oh I changed the builtins to demonstrate this - what you do is move the nested type definition to the top level, and then make an alias to the type be what's nested
I'm not sure if that's the design we'll go with long-term, but I want to try it out. so far it feels fine for builtins but I want to see how it feels in broader use.
Last updated: Nov 26 2026 at 20:35 UTC