Skip to content

use some::Trait as _; #1311

Closed
Closed
@arcnmx

Description

@arcnmx

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

  • Some other syntax? I feel like this choice meshes well with Rust in general.
  • Not doing this at all. Is it necessary/useful enough to warrant the minor language change?
  • Workarounds in current rust:
    • use some::Trait as __Trait;
    • UFCS: use some; some::Trait::method(etc);
    • Using names like 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions