|
|
Subscribe / Log in / New account

Edition benefits

Edition benefits

Posted Feb 21, 2025 18:46 UTC (Fri) by khim (subscriber, #9252)
In reply to: Edition benefits by tialaramex
Parent article: Rust 1.85.0 released

> But it's a hack, this is not something that is part of Editions itself

Um. That's some kind of hair splitting that I don't understand. How is this hack different from, e.g. disjoint capture in closures?

> There is (unlike for many of these changes) a custom hack which Rust will carry indefinitely, to make this work because it was deemed valuable enough to do that work.

Yes, similarly to how Swift carries a hack for AnyColorBox. And from what I understand the justification was kind of “normally we don't do such hacks, but if it's only for old Edition, then it's acceptable”.

> There is (unlike for many of these changes) a custom hack which Rust will carry indefinitely, to make this work because it was deemed valuable enough to do that work.

How is it different from any other change? Even latest version of Rust have to carry “hack” that would allow your to write simply TraitFoo instead of dyn TraitFoo in Rust 2015 Edition… what makes one of them “depend on edition” and the other “not depend on Edition”?


to post comments

Edition benefits

Posted Feb 21, 2025 23:48 UTC (Fri) by tialaramex (subscriber, #21167) [Link] (2 responses)

I don't think it's hair splitting? It's just a very straight forward description of what happened.

In your disjoint capture example, lets break down the capture functionality today: 1. We need to be able to capture a named variable, 2. we need to be able to capture just part of the variable, not the rest, leaving that to be moved, dropped etc. or captured by something else.

Rust 2015 and 2018 Edition code needs (1) but subsequent Rust code needs both (1) and (2). Preserving (1) isn't a hack or a special case, we still need that too, in fact most of my captures use (1) and I've rarely needed (2) even though I wrote most of my Rust after 2021 Edition was available.

For your other Rust example (dyn traits) that's even more straight forward because it's literally grammar, it's like if your friend Sarah insisted you start calling her Professor Sarah. She's not a different person, but now you say "Professor Sarah" instead of "Sarah".

When I talk about a hack, I mean there's literally Rust code which exists to hide this implementation in old editions. In rustc_hir_typeck/src/method/probe.rs there's:

if self_ty.is_array() && !method_name.span.at_least_rust_2021() {

"Oh, if we're not at least 2021 Edition, this array magically doesn't impl IntoIterator as far you're concerned"

Most of the other edition specific code in Rust is to produce friendly warnings and other diagnostics, but this code is a hack like I said.

Edition benefits

Posted Feb 22, 2025 0:26 UTC (Sat) by khim (subscriber, #9252) [Link] (1 responses)

> Rust 2015 and 2018 Edition code needs (1) but subsequent Rust code needs both (1) and (2).

No. (1) and (2) are two entirely different things. It's impossible to express (1) in Rust 2021. There are no such operation and there are no syntax for that.

That ability is simply gone. Removed. Only kept around for legacy crates.

> Preserving (1) isn't a hack or a special case

It's very much a hack and special case. Semantic is different. It's implemented differently in the compiler (there are special “unique” reference which is not mutable involved), it's really very different mode with different rules.

> in fact most of my captures use (1) and I've rarely needed (2) even though I wrote most of my Rust after 2021 Edition was available

You may pretend that your captures are using (1), but that doesn't change the fact that they not handled that way.

> When I talk about a hack, I mean there's literally Rust code which exists to hide this implementation in old editions.

And how is that different from the exact same hack that does an opposite and allows one to use async in Rust 2015 where it's not allowed to be in Rust 2018?

> Most of the other edition specific code in Rust is to produce friendly warnings and other diagnostics, but this code is a hack like I said.

Not really. Edition specific code is all like that hack. Sometimes it's elevated to the language level (e.g. there's expr_2021 to deal with macros in a backward compatible way), sometimes “the old way” is only available in crate that's specifically compiled in “old edition” mode, but it's all, pretty much, looks like that. How else could you handle that difference, if not by checking some “version” filed or some “bool” (that's enabled for one edition and disabled for the other edition)?

Edition benefits

Posted Feb 22, 2025 19:24 UTC (Sat) by tialaramex (subscriber, #21167) [Link]

Last May I spent far too long trying to get you to understand the bug in SRWLock and at the end, rather than "Oh, I actually completely misunderstood, sorry" I got only a claim that it's not a bug but a "failed optimization" and you imagined a whole suite of benchmarks (which never existed) to support this "optimization" idea instead of it just being a dumb bug that anyone could have written.

I don't have time or energy to perform a similar dance here.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds