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

Privacy can be violated using pointers #3763

Closed
Dretch opened this issue Oct 14, 2012 · 1 comment
Closed

Privacy can be violated using pointers #3763

Dretch opened this issue Oct 14, 2012 · 1 comment
Labels
A-typesystem Area: The type system
Milestone

Comments

@Dretch
Copy link
Contributor

Dretch commented Oct 14, 2012

When a struct is accessed via a pointer then its private fields are accessible:

mod my_mod {
    pub struct MyStruct {
        priv priv_field: int
    }
    pub fn MyStruct () -> MyStruct {
        MyStruct {priv_field: 4}
    }
}

fn main() {
    let my_struct = my_mod::MyStruct();
    let _woohoo = (&my_struct).priv_field; // compiles but shouldn't
    let _woohoo = (~my_struct).priv_field; // ditto
    let _woohoo = (@my_struct).priv_field; // ditto
    let nope = my_struct.priv_field;       // compile error as expected
}
@catamorphism
Copy link
Contributor

Reproduced as of d2ad028

@ghost ghost assigned catamorphism Dec 12, 2012
bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
RalfJung pushed a commit to RalfJung/rust that referenced this issue Jul 29, 2024
Insert FileDescription instead of FileDescriptor in ``insert_fd``

This PR moves the creation of ``FileDescriptor`` inside ``insert_fd``, and ``insert_fd`` now takes in ``FileDescription`` instead of ``FileDescriptor``.  This change is needed by rust-lang#3712.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

2 participants