Registry Mirror
Skip to content

Conversation

@huonw

@huonw huonw commented May 24, 2014

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

A hack, but an effective one.

@alexcrichton

Copy link
Copy Markdown
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