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

private constants should not be accessed from outer namespace #2636

Open
tamaroning opened this issue Sep 22, 2023 · 1 comment
Open

private constants should not be accessed from outer namespace #2636

tamaroning opened this issue Sep 22, 2023 · 1 comment

Comments

@tamaroning
Copy link
Contributor

It is also true for static items?

I tried this code:

pub mod module_a {
    const CONST_I32: i32 = 0;
}

fn main() {
    let _ = module_a::CONST_I32;
}

I expected to see this happen:

error[E0603]: constant `CONST_I32` is private
 --> <source>:6:23
  |
6 |     let _ = module_a::CONST_I32;
  |                       ^^^^^^^^^ private constant
  |
note: the constant `CONST_I32` is defined here
 --> <source>:2:5
  |
2 |     const CONST_I32: i32 = 0;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Instead, this happened:
compiled.

Meta

  • What version of Rust GCC were you using, git sha if possible.
@tamaroning tamaroning added the bug label Sep 22, 2023
@CohenArthur
Copy link
Member

Yeah, this is also true for static items: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=127506396739337c8e60b56c91427c69

Thanks for the report!

@dkm dkm changed the title private constatnts should not be accessed from outer namespace private constants should not be accessed from outer namespace Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants