-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CHANGE: Rename Rng::gen
to avoid conflicting with a keyword in Rust 2024
#1435
Comments
Renaming it to something like |
Thanks for raising this with us @PatchMixolydic. This gives us strong motivation for actually getting a new release out this year! In other languages, it can be common practice to do something like |
There are a lot of offending uses of
Probably then quite a few users of this library will be impacted. |
We should probably keep `Rng::gen` to make the migration to the new edition
easier, but we might want to deprecate it. (I think cargo can automatically
add `r#` when migrating to a new edition.)
`Rng::random` could be a good alternative name, because `Rng::gen` is the
analogue to `rand::random`.
|
Reusing the |
Best choice yet
We already have |
This anticipates `gen` being a keyword in Rust 2024. A deprecated alias for `Rng::gen` stays in place to make the transition easier. Fixes rust-random#1435.
This anticipates `gen` being a keyword in Rust 2024. A deprecated alias for `Rng::gen` stays in place to make the transition easier. Fixes rust-random#1435.
Forgive me if this has been posted before, but I couldn't find an issue tracking this.
Summary
RFC 3513, which reserves
gen
as a keyword for generators in Rust 2024, has been accepted (tracking issue). This conflicts with the naming ofRng::gen
. This issue proposes renaming or adding an alias forRng::gen
.Details
The internal implementation is the easy part:
Rng::gen
should either be removed or deprecated, and a new method with the same functionality should be added. The difficult part would be deciding on what this new method should be called. This issue is meant to provide an avenue for bikeshedding the new name.One possibility could be
Rng::generate
, though this seems slightly unwieldy.Motivation
In Rust 2024,
gen
is slated to become a keyword. This means that anyone who callsRng::gen
will have to use a raw identifier:This is suboptimal for several reasons: it requires the use of a somewhat obscure feature, it is much less readable at a glance, it's more difficult to type, it runs the risk of turning into sigil soup (especially when using a turbofish), etc. Picking a different name would improve the UX of this common method in Rust 2024 and beyond.
Alternatives
Do nothing
Rng::gen
will stay as it is, and anyone who uses Rust 2024 and above will have to call it using a raw identifier. This is suboptimal for the reasons detailed in the Motivation section, but avoids the resulting ecosystem churn from renaming a common method.Convince the Rust language team to adopt a different keyword
As can be seen on the tracking issue, whether
gen
is the right keyword for generators is an unresolved question. Sincerand
usesgen
prominently, it might be worthwhile forrust-random
to weigh in if it hasn't already.Remove
Rng::gen
As far as I can tell,
Rng::gen
is a convenience alias forRng::sample(Standard)
. This implies thatRng::gen
could be removed entirely. However, this would cause just as much churn as renamingRng::gen
, and maintainers would probably want to understand whatStandard
andRng::sample
are before switching to them. This would also create a pain point for newcomers, as they'd no longer have an obvious starting point for generating an arbitrary random value for a given type.The text was updated successfully, but these errors were encountered: