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

Module shadowing is prohibited in RFC but allowed by rustc #111339

Closed
obi1kenobi opened this issue May 8, 2023 · 3 comments
Closed

Module shadowing is prohibited in RFC but allowed by rustc #111339

obi1kenobi opened this issue May 8, 2023 · 3 comments
Labels
C-bug Category: This is a bug.

Comments

@obi1kenobi
Copy link
Member

I tried this code:

mod a {
    pub mod collide {
        pub struct Foo {}   
    }
}

pub use a::*;

pub mod collide {
    pub struct Bar {}
}

playground

I expected to see this happen: compilation error, since RFC 116 seems to explicitly prohibit shadowing modules.

Instead, this happened: compiles successfully and the collide module is shadowed, playground.

Related to #111336 which looks at other glob shadowing problems.

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (39c6804b9 2023-04-19)
binary: rustc
commit-hash: 39c6804b92aa202369e402525cee329556bc1db0
commit-date: 2023-04-19
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

Also tested on Nightly version: 1.71.0-nightly (2023-05-07 c4190f2d3a46a59f435f) via the playground.

If RFC 116 has been superseded or withdrawn, I'm sorry — after some digging, I wasn't able to find any information to that effect, but perhaps I wasn't looking in the right places.

@obi1kenobi obi1kenobi added the C-bug Category: This is a bug. label May 8, 2023
@petrochenkov
Copy link
Contributor

If RFC 116 has been superseded or withdrawn

That's what happened, yes.
That RFC is ancient, almost a year before the language was stabilized as Rust 1.0.

In this case the current rules should be closer to https://github.com/rust-lang/rfcs/blob/master/text/1560-name-resolution.md

@obi1kenobi
Copy link
Member Author

Great, thanks for the prompt reply!

Out of curiosity, was there a place I could have found this out on my own without asking here first? Wondering if the underlying issue is "I didn't look hard enough, do better next time" or "superseded RFCs aren't marked as such, open an issue on rust-lang/rfcs".

@petrochenkov
Copy link
Contributor

In theory it should be documented in the language reference somewhere around here https://doc.rust-lang.org/reference/items/use-declarations.html.
It's not yet actually documented though (cc rust-lang/reference#568).

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

No branches or pull requests

2 participants