Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC: Allow re-exporting associated items with `use` #1150
Conversation
huonw
added
the
T-lang
label
Jun 3, 2015
This comment has been minimized.
This comment has been minimized.
|
Added an example. |
This comment has been minimized.
This comment has been minimized.
|
I greatly prefer the alternative, where one could do |
This comment has been minimized.
This comment has been minimized.
|
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 |
tshepang
reviewed
Jun 4, 2015
| 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. |
This comment has been minimized.
This comment has been minimized.
tshepang
Jun 4, 2015
Contributor
I only know of 2:
- size_hint -> len_hint
- ExactSizeIterator -> ExactLenIterator
What are the others?
This comment has been minimized.
This comment has been minimized.
Gankro
Jun 4, 2015
Author
Contributor
- There's a lot of
mut_**_mutthings you could argue. - min_align_of is being renamed to align_of, removing align_of entirely: rust-lang/rust#25646
- connect -> join: #1102
- slice::tail/init: #1058
Just off the top of my head
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Gankro
Jun 5, 2015
Author
Contributor
Only tail/init are unstable, and people are proposing renaming other methods in that RFC (first/last)
tshepang
reviewed
Jun 4, 2015
| desirable to deprecate these in favour of a rename. However to avoid breaking everyone | ||
| there needs to be some trick to make impls still work. There are a few ways to do this today, | ||
| but all of them cause janky behaviour for *trait methods*, because they have a diverse. | ||
| Set of implementors and default implementations. For instance consumers of one |
This comment has been minimized.
This comment has been minimized.
petrochenkov
reviewed
Jun 4, 2015
|
|
||
| # Alternatives | ||
|
|
||
| Enable full `fn` aliases via a `fn foo = bar;` syntax. This would allow renaming |
This comment has been minimized.
This comment has been minimized.
petrochenkov
Jun 4, 2015
Contributor
use bar as foo; works today to some extent.
http://is.gd/SQpfGX
It's similar to the proposed fn foo = bar; because it works on the name level and can be adjusted to work in more places.
This comment has been minimized.
This comment has been minimized.
eddyb
Jun 4, 2015
Member
Keep in mind this is an issue specifically for methods (the RFC could definitely be more clear about that).
Adding use syntax for methods could work, but the attribute method was proposed because it requires no syntax changes.
This comment has been minimized.
This comment has been minimized.
jmesmon
commented
Jun 4, 2015
|
I'd be also be in favor of generalizing |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Jun 4, 2015
|
@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. |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Jun 4, 2015
|
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. |
This comment has been minimized.
This comment has been minimized.
arthurprs
commented
Jun 4, 2015
|
I'm strongly in favor of this as it allows easier decisions ongoing. But shouldn't this (optionally) go into the deprecated attribute itself? |
This comment has been minimized.
This comment has been minimized.
jmesmon
commented
Jun 5, 2015
|
@bluss I suppose I'd expect one to have a non-deprecated implementation (of, in this case, the method) and a |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Jun 5, 2015
|
@llogiq That is not enough to solve |
alexcrichton
referenced this pull request
Jun 9, 2015
Closed
RFC: Deprecate `Iterator::size_hint` and `ExactSizeIterator` for better named alternatives. #1034
This comment has been minimized.
This comment has been minimized.
|
I am for extending @arthurprs, IMHO, extending |
nrc
assigned
Gankro
Jun 12, 2015
Gankro
changed the title
RFC: rename attribute
RFC: Allow re-exporting associated items with `use`
Jul 1, 2015
This comment has been minimized.
This comment has been minimized.
|
I've completely rewritten the RFC to just use |
This comment has been minimized.
This comment has been minimized.
|
Hm, why do
Well, because
Can the same logic be applied to function aliases? Do we ever need something like:
? |
This comment has been minimized.
This comment has been minimized.
arthurprs
commented
Jul 4, 2015
|
This is good @Gankro |
This comment has been minimized.
This comment has been minimized.
|
-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. |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Jul 9, 2015
|
@nrc: We need this for renaming/deprecating of methods that you usually chain / delegate off. The example that sparked this RFC was |
This comment has been minimized.
This comment has been minimized.
|
@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, |
This comment has been minimized.
This comment has been minimized.
|
"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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
Hear ye, hear ye. This RFC is now entering final comment period. |
nikomatsakis
added
the
final-comment-period
label
Jul 9, 2015
This comment has been minimized.
This comment has been minimized.
bluss
commented
Jul 9, 2015
|
@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 |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
+1, this is a nice solution
|
This comment has been minimized.
This comment has been minimized.
|
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). |
This comment has been minimized.
This comment has been minimized.
|
I like this functionality in theory. But it is relatively complicated and only serves... one use-case ( |
This comment has been minimized.
This comment has been minimized.
arthurprs
commented
Jul 14, 2015
|
Not really sure but we could generalize it to support renaming traits and structures as well. |
This comment has been minimized.
This comment has been minimized.
|
@arthurprs But that's already possible! |
This comment has been minimized.
This comment has been minimized.
|
I have definitely deprecated re-exports of modules and types in std before. |
This comment has been minimized.
This comment has been minimized.
arthurprs
commented
Jul 14, 2015
|
Ya, I'm felling stupid right now, sorry. |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
Hmm... maybe I hallucinated that... |
This comment has been minimized.
This comment has been minimized.
|
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. |
Gankro commentedJun 3, 2015
Extend
useto 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