Conversation
|
Just as a reference, Haskell has that: import Foo.Bar.Zoo () -- imports the instances (impls) but not the typeclasses (traits) directly |
|
We'd want this for inherent methods too, not just traits, right? |
|
@burdges inherent methods don't need to be imported to be used. |
|
No need for inherent methods because you never express them in the |
text/0000-impl-only-use.md
Outdated
| # Guide-level explanation | ||
| [guide-level-explanation]: #guide-level-explanation | ||
|
|
||
| Qualyfing a `use` with `_` on a trait imports the trait’s `impl`s but not the symbol directly. It’s |
There was a problem hiding this comment.
Nice catch, thanks!
This RFC gives Rust the syntax: ```rust use foo::FooTrait as _; ``` Here, `_` means that we want to import the `FooTrait` trait’s impls but not the trait symbol directly, because we might declare the same symbol in the moduling issuing the `use`.
0d69fad to
17a50ea
Compare
|
Neat RFC. Also related to traits, but perhaps deserving of a separate RFC... How about importing trait methods of the following form as free functions: trait TheTrait {
fn notUsingInArgPos2(x: T1, y: T2, ...) -> X<TheTrait>;
}where |
|
Hm, isn't conventionally |
|
Yes, and here it’s the same: a concrete thing (a trait) you don’t care about. :) |
text/0000-impl-only-use.md
Outdated
| # Reference-level explanation | ||
| [reference-level-explanation]: #reference-level-explanation | ||
|
|
||
| To be defined. |
There was a problem hiding this comment.
use Trait as _ needs to desugar into use Trait as SomeUniqueNameYouCantReferTo (i.e. SomeUniqueNameYouCantReferTo is a "gensym").
With this scheme glob imports/reexports can work properly with such items, i.e. import/reexport them.
mod m {
pub use Trait as _;
// `Trait` is in scope
}
use m::*;
// `Trait` is in scope too There was a problem hiding this comment.
use NonTrait as _ can work the same way, it will just always be reported as unused import.
extern crate my_crate as _ can work in the same way too (this can be useful for linking-only crates).
There was a problem hiding this comment.
Good comments, I’ll have them added! :)
|
Oh please this. I could use this in the |
117cac3 to
4727667
Compare
4727667 to
459606f
Compare
|
🎉 Every couple months I accidentally do this hoping maybe it got implemented. A small point brought up previously is that this additionally affects rustdoc, and probably requires some special handling/formatting to display without just showing the generated ident. |
|
Nominating for discussion in the @rust-lang/lang team meeting. |
|
@rfcbot fcp merge |
|
Team member @withoutboats has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
The final comment period is now complete. |
|
This RFC has been merged! |
This RFC gives Rust the syntax:
Here,
_means that we want to import theFooTraittrait’s impls butnot the trait symbol directly, because we might declare the same symbol
in the module issuing the
use.Rendered