Annoying limitations with `use` of same symbols

I’ve recently hit some annoying limitations with use statement, exemplified here:

mod Foo {
    pub struct Type;
    pub struct Xxx;
}

mod Foo2 {
    pub use super::Foo::Type; 
    pub struct Xxx;
}

use Foo::Type;
use Foo2::Type; // Error: has already been imported in this module

The error seems arbitrary and totally unnecessary since the imported symbol is exactly the same. It might make sense to fail for Xxx because they are different elements, but not Type . This situation is even more common if globs are used. Has it been suggested that this behaviour be changed to allow duplicate imports if they refer to the same element?

I can think of going even further, and actually allowing imports of two symbols with same name even if they are not the same element (like Xxx), and only error out if the symbol is actually used. This would make glob imports work a lot better. (D uses this behaviour, and I think it works quite well)

So for example, in the code above, it would allow writing:

use Foo::*;
use Foo2::*;
type MyType = Type; // Okay - imported `Type` is the same
// type MyXxx = Xxx; // Error - `Xxx` is ambigous

Right, just found this in the meanwhile: https://github.com/rust-lang/rfcs/issues/553

I think this would be covered here:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.