3 ms·
Several of those de-sugarings are wrong. The book explains how Rust's `for` is actually de-sugared, and that ? is a Try operator, so unsurprisingly it de-sugars
by tialaramex 2y ago
Several of those de-sugarings are wrong. The book explains how Rust's `for` is actually de-sugared, and that ? is a Try operator, so unsurprisingly it de-sugars to a use of Try::branch and that gets you a ControlFlow which is then pattern matched.
Also, they don't need to live "at well known paths". Instead they're marked as "langitems", with the magic attribute lang:
#[lang = "add_assign"] // Signifies that this trait is what the compiler wanted to make the += operator work in the language.
- dietr1ch 2y agoIs there a way of looking at desugared code? Maybe things won't change that much, but I feel that documentation on how desugaring is supposed to be done will be increasingly wrong as things change. Maybe it's stable enough, but It'd be cool to have a nice way of verifying things are happening the way they are supposed to.
- junon 2y agoYes, while you're correct, my comment was more or less illustrative. Apologies if that wasn't clear. Explaining the nuance of langitems wasn't really the point I was trying to make. Also AFAIR Try traits are relatively new, and are still unstable. Last I checked it was indeed a desugar to either From or Into (pretty sure it was From).