-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Add #[rustc_per_edition] for edition-dependent type aliases. #82489
Conversation
This comment has been minimized.
This comment has been minimized.
One very important design decision is that It might be more desirable to have imports also force choosing one of the alternatives, and if we can do it at the import level, it would work for other items as well, but it is trickier. Something I was thinking might work is have a setup like this: #[rustc_per_edition]
pub use self::rust_0000::Range;
mod rust_2015 { pub use crate::iter::Range; }
mod rust_2018 { pub use crate::iter::Range; }
mod rust_2021 { pub struct Range<T> {...} ... } Where (Other than replacing an identifier, we could instead inject an extra path component just before the last one or w/e, but that feels "more magical") While it would resolve to |
Could someone explain what are the goals exactly?
|
I'd like to find a way to make it possible to use editions for small breaking changes in the standard library as well, instead of only in the language. (E.g. for renaming/moving items.) This seems to be a way to achieve that without making things too complicated. For Basically: It'd be nice if in Edition 2021 code, |
We already did something like this for |
@m-ou-se any updates on this? |
☔ The latest upstream changes (presumably #97694) made this pull request unmergeable. Please resolve the merge conflicts. |
This will make it possible to have e.g.
std::ops::Range
refer to different types depending on the edition of the code using that alias.Marking this as experimental for now, because I don't know yet if this is something we want.
Thanks @eddyb for pointing out this can be done relatively easily with type aliases.
cc @sfackler, since you're working on the new Range types, for which this could be useful.
As this PR shows, the change to rustc itself is pretty simple. But rustdoc (and racer/rls and rust-analyzer) would also need special support for this, which I haven't looked into yet.
r? @ghost