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

Paper over privacy issues with Deref by changing field names. #14402

Merged
merged 1 commit into from
May 25, 2014

Conversation

huonw
Copy link
Member

@huonw huonw commented May 24, 2014

Paper over privacy issues with Deref by changing field names.

Types that implement Deref can cause weird error messages due to their
private fields conflicting with a field of the type they deref to, e.g.,
previously

struct Foo { x: int }

let a: Arc<Foo> = ...;
println!("{}", a.x);

would complain the the x field of Arc was private (since Arc has a
private field called x) rather than just ignoring it.

This patch doesn't fix that issue, but does mean one would have to write
a._ptr to hit the same error message, which seems far less
common. (This patch _-prefixes all private fields of
Deref-implementing types.)

cc #12808

@emberian
Copy link
Member

A hack, but an effective one.

@alexcrichton
Copy link
Member

r=me if you add FIXME annotations to the field definitions.

Types that implement Deref can cause weird error messages due to their
private fields conflicting with a field of the type they deref to, e.g.,
previously

    struct Foo { x: int }

    let a: Arc<Foo> = ...;
    println!("{}", a.x);

would complain the the `x` field of `Arc` was private (since Arc has a
private field called `x`) rather than just ignoring it.

This patch doesn't fix that issue, but does mean one would have to write
`a._ptr` to hit the same error message, which seems far less
common. (This patch `_`-prefixes all private fields of
`Deref`-implementing types.)

cc rust-lang#12808
bors added a commit that referenced this pull request May 25, 2014
Paper over privacy issues with Deref by changing field names.

Types that implement Deref can cause weird error messages due to their
private fields conflicting with a field of the type they deref to, e.g.,
previously

    struct Foo { x: int }

    let a: Arc<Foo> = ...;
    println!("{}", a.x);

would complain the the `x` field of `Arc` was private (since Arc has a
private field called `x`) rather than just ignoring it.

This patch doesn't fix that issue, but does mean one would have to write
`a._ptr` to hit the same error message, which seems far less
common. (This patch `_`-prefixes all private fields of
`Deref`-implementing types.)

cc #12808
@bors bors closed this May 25, 2014
@bors bors merged commit 9698221 into rust-lang:master May 25, 2014
@huonw huonw deleted the arc-field-rename branch June 27, 2014 06:47
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants