Skip to content
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

Type is not exported if type with same name is introduced via use #105235

Closed
wusticality opened this issue Dec 4, 2022 · 2 comments · Fixed by #113099
Closed

Type is not exported if type with same name is introduced via use #105235

wusticality opened this issue Dec 4, 2022 · 2 comments · Fixed by #113099
Labels
C-bug Category: This is a bug.

Comments

@wusticality
Copy link

wusticality commented Dec 4, 2022

I'm seeing a strange issue where a type is not being exported from a module if that module imports a type with the same name. Here is an example that demonstrates this issue:

mod abc {
    pub struct Beeblebrox;
    pub struct Zaphod;
}

mod foo {
    pub mod bar {
        use crate::abc::*;
        
        #[derive(Debug)]
        pub enum Zaphod {
            Whale,
            President,
        }
    }

    pub use bar::*;
}
mod baz {
    pub fn do_something() {
        println!("{:?}", crate::foo::Zaphod::Whale);
    }
}

fn main() {
    baz::do_something();
}

In module bar, we're importing abc::Zaphod, and then defining a type of the same name. When exporting everything from bar via pub use bar::*, the Zaphod type is not exported. Is this expected behavior? It seems wrong to me.

I would have expected the type that's actually declared in bar to take precedence and be exported. Either that, or the compiler should emit a useful error describing the collision. At present, the type is silently omitted.

Meta

rustc 1.67.0-nightly (215e3cd21 2022-11-03)
binary: rustc
commit-hash: 215e3cd218b83b8a3152d84d92f17109253c25e1
commit-date: 2022-11-03
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
Backtrace

Compiling playground v0.0.1 (/playground)
error[[E0433]](https://doc.rust-lang.org/nightly/error-index.html#E0433): failed to resolve: could not find `Zaphod` in `foo`
  --> src/main.rs:20:38
   |
20 |         println!("{:?}", crate::foo::Zaphod::Whale);
   |                                      ^^^^^^ could not find `Zaphod` in `foo`

warning: unused import: `crate::abc::*`
 --> src/main.rs:8:13
  |
8 |         [use crate::abc::*;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=1980019cec4c271a2bfddb14e2f016f0#)
  |             ^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

For more information about this error, try `rustc --explain E0433`.
warning: `playground` (bin "playground") generated 1 warning
error: could not compile `playground` due to previous error; 1 warning emitted

@wusticality wusticality added the C-bug Category: This is a bug. label Dec 4, 2022
@SNCPlay42
Copy link
Contributor

Duplicate of #56593

@wusticality
Copy link
Author

@SNCPlay42 Should I close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants