-
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
use some::Trait as _; #1311
Comments
yes yes yes! |
If these can be public and glob imports match them they would be nice for preludes. I imagine they would have been used for |
@wthrowe good point, I like that suggestion. |
+1, this would be nice to have. |
Also +1, I like this idea. One potential downside is extra complexity for |
Looks reasonable. |
cc me |
Yeah, I am 👍 on this basic idea. |
I was just looking into this today, glad someone beat me to it |
I feel like this doesn't work well for the |
@briansmith n.b. After #1560 is done (c.f. rust-lang/rust#35894), we won't need mod a { pub fn f() {} }
mod b { pub fn f() {} }
fn main() {
use a::*;
use b::*;
f(); // This is an error, since `f` could be `a::f` or `b::f`.
// use a::f; // uncommenting this fixes the error.
//^ Adding this is analogous to appending `hiding {f}` to `use b::*;`.
} |
I wonder if the opposite behavior is ever useful - the trait's name is in scope, but the trait doesn't participate in method/ufcs-path resolution. |
I have never actually wanted this behavior, but I can imagine On Wed, Aug 24, 2016 at 02:09:24AM -0700, Vadim Petrochenkov wrote:
|
Definitely a way to omit specific names from glob would be useful. On Tue, Aug 23, 2016 at 07:01:18PM -0700, Brian Smith wrote:
|
Can |
Can
|
I think so -- it seems more consistent and could be useful. |
In this case |
RFC is proposed. #2166 |
Closing in favor of rust-lang/rust#48216. |
mini/pre RFC
use some::Trait as _;
This would allow importing a trait into scope for resolution reasons, without being able to reference it by ident directly.
Motivation
I've found a need for
use some::Trait as __Trait;
in order to avoid conflicts with another type in scope. It tends to come up when dealing with abstractions and wrappers that have similar type names.Alternatives
use some::Trait as __Trait;
use some; some::Trait::method(etc);
TraitImp
for your concrete types instead.Unresolved Questions
Wildcard version?
use some::* as _
could work well for importing preludes.Allow use with
pub
to make them available for constructing preludes?Actual design? A simple approach might be to simply implement this as sugar for mangling the trait name in some way (ideally with the full path of the module to accomodate for
pub
exporting). A real implementation would make them truly hidden as identifiers, but otherwise usable for deciding whether a trait is applicable.Would this be valid for non-trait types such as structures, type aliases, etc? I'd imagine the wildcard case would simply ignore them, but the explicit syntax would be weird and useless.
The text was updated successfully, but these errors were encountered: