-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Allow re-exporting associated items with use
#1150
Conversation
Added an example. |
I greatly prefer the alternative, where one could do |
I would personally find this somewhat surprising in that an attribute is now greatly affecting name lookup and method resolution, where attributes normally don't have much effect on these sorts of phases of the compiler. I would also probably prefer a more first-class |
to support some kind of "currying" like `type` does with `type<T> = Foo<Concrete, T>`?) | ||
|
||
The RFC author would like to have a tool for this in the short-term, as there are | ||
several outstanding rename requests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only know of 2:
- size_hint -> len_hint
- ExactSizeIterator -> ExactLenIterator
What are the others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- There's a lot of
mut_*
*_mut
things you could argue. - min_align_of is being renamed to align_of, removing align_of entirely: Make
align_of
behave likemin_align_of
. rust#25646 - connect -> join: Rename connect to join #1102
- slice::tail/init: RFC for replacing slice::tail()/init() with new methods #1058
Just off the top of my head
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of those (I don't know about the rest) are Unstable though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only tail/init are unstable, and people are proposing renaming other methods in that RFC (first/last)
I'd be also be in favor of generalizing |
@jmesmon The old name needs to be deprecated and the new name not, and rust must not allow implementing both method names. If that works, then it's fine. |
The attribute acts like a rename and deprecation of the old value. Deprecations already use attributes, so that part is fine. The novel thing is just redirecting an old name, specified in the rename, to the new method. |
I'm strongly in favor of this as it allows easier decisions ongoing. But shouldn't this (optionally) go into the deprecated attribute itself? |
@bluss I suppose I'd expect one to have a non-deprecated implementation (of, in this case, the method) and a |
Currently, this could be done with #[deprecated(since = "1.2.3")]
fn deprecated_method(...) { replacement_method(...) } I don't think that situation is so bad that we need a new language feature to handle it, but then I'm not the one maintaining the language. 😉 |
@llogiq That is not enough to solve |
I am for extending @arthurprs, IMHO, extending |
use
I've completely rewritten the RFC to just use |
Hm, why do
Well, because
Can the same logic be applied to function aliases? Do we ever need something like:
? |
This is good @gankro 👍 |
-1 Why not just leave the deprecated method as just a call to the new method? This seems like a lot of added complexity (especially when reading code) for not very much gain. If this needs a solution (and I'm not sure it does), then it seems it should be done with tooling, rather than with a language feature. |
@nrc: We need this for renaming/deprecating of methods that you usually chain / delegate off. The example that sparked this RFC was |
@nrc that doesn't work. However, a simple attribute for renaming a method would be enough. It would just work (and you should keep it unstable while designing a better solution). If @gankro wants to go the But it's a lot more specification and implementation work than this RFC assumes: Finally, you have to define re-export semantics in trait definitions that happen to also allow the kind of renaming desired here, which requires traits not only to expose those items, but also catch their implementations (only when the re-export is same-trait). What would re-exporting something that isn't an associated item do? Just behave as if the trait was a module, and ignore them on method lookup or in In any case, 👎 for this RFC as it is written right now, it's missing a lot of details and it would not be prudent to accept it in this state. That said, I'm warming up to this use of |
"doesn't work" seems to mean causes some loss of efficiency and possible confusion for implementers. The trade off for size_hint in particular seems to be - having a sub-optimal name or some degree of performance loss (and implementer confusion), satisfying that trade-off doesn't seem worth extra language-level complexity. |
Am I right in my interpretation that everyone who is saying "that doesn't work" in response to @llogiq and @nrc is basing their statement on a (hypothetical) requirement that when deprecating an API due to a trivial rename, one wants to enforce that old_name and new_name are in sync? NOTE: I used the word "trivial" not to make the problem sound easy, but rather to stress the fact that connecting up such synchronization in that specific case (where it is just a rename, no parameter reordering or conversions) seems to be tightly wound up with the feature being added here. It seems to me like there are other ways, perhaps lint-based, to enforce such synchronization that, IMO, would have a prayer of generalizing to more complex scenarios. Update: Off the top of my head, here's one idea: If the deprecated trait method can be expressed in terms of a default method that calls the new one in some manner, then we add an attribute to the deprecated method in the trait that says "warn on override". Where would that go wrong ? Implementers would be told they need to now implement the new method (if they have not already), and they would be told not to provide their own impl of the defaulted one anymore. |
Hear ye, hear ye. This RFC is now entering final comment period. |
@nrc: Ah but correcting a slightly worse name doesn't warrant the trouble that an imperfect rename involves. I think we need “perfect” name deprecations to even consider deprecations just because of these kinds of small blemishes in the varnish. What I think of renaming |
@pnkfelix Yes, this RFC is largely trying to address the problem of keeping old and new names in sync, particularly when previous defaults prevent you from just building a default cycle or redirection. |
+1, this is a nice solution
|
Using This comment is not meant as an endorsement of the underlying functionality. I have to think over how much work and complexity it is (as @eddyb suggests). |
I like this functionality in theory. But it is relatively complicated and only serves... one use-case ( |
Not really sure but we could generalize it to support renaming traits and structures as well. |
@arthurprs But that's already possible! |
I have definitely deprecated re-exports of modules and types in std before. |
Ya, I'm felling stupid right now, sorry. |
@gankro it doesn't work. // deprecated.rs
#![crate_type = "lib"]
#![staged_api]
#![feature(staged_api)]
#![stable(feature = "x", since = "1.0.0")]
#[stable(feature="x", since="1.0.0")]
pub mod foo {
#[stable(feature="x", since="1.0.0")]
pub fn f() {}
}
#[deprecated(since="1.1.0")]
#[stable(feature="x", since="1.0.0")]
pub use foo as bar; extern crate deprecated;
fn main() {
deprecated::foo::f();
deprecated::bar::f();
} All compiles without a peep. |
Hmm... maybe I hallucinated that... |
This proposal has enough issues that I'm just going to close it. I think the right idea is in here somewhere, but I'm not the one to find it. |
Extend
use
to work in trait definitions and impl blocks for re-exporting associateditems under different names. This provides a clean way to rename items harmlessly, and
provides a more ergonomic way to provide the same functionality under different names
when necessary to satisfy an API.
This enables
Rendered