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

Handle stability of struct fields #22803

Merged
merged 3 commits into from
Feb 28, 2015
Merged

Conversation

huonw
Copy link
Member

@huonw huonw commented Feb 25, 2015

We were recording stability attributes applied to fields in the
compiler, and even annotating it in the libs, but the compiler didn't
actually do the checks to give errors/warnings in user crates.

Details in the commit messages.

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@huonw
Copy link
Member Author

huonw commented Feb 25, 2015

r? @brson, @aturon, @alexcrichton

NB. I've had to add 3 stability attributes.

@rust-highfive rust-highfive assigned brson and unassigned eddyb Feb 25, 2015
@alexcrichton
Copy link
Member

This looks good to me, nice work! Could this also be expanded to cover fields mentioned in patterns as well for structs? Other than that I think it covers everything.

.unwrap_or_else(|| {
tcx.sess.span_bug(field.span,
"stability::check_expr: unknown named field access")
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this sort of lookup would be candidate for a good helper in middle::ty

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think how we handle structs in the compiler will be changing with #22564, so I'll leave it for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, this can wait then. r=me with patterns handled as well

We were recording stability attributes applied to fields in the
compiler, and even annotating it in the libs, but the compiler didn't
actually do the checks to give errors/warnings in user crates.
The stability check checks the `PublicItems` map when giving errors if
there is a #[stable] item with a public contents that doesn't not have
its own stability. Without recording this, struct fields and enum
variants will not get errors for e.g. stable modules with unmarked
functions internally.

This is just improving the compiler's precision to give the standard
library developers more information earlier.

E.g.

    #![staged_api]
    #![feature(staged_api)]
    #![crate_type = "lib"]

    #[stable(feature = "rust1", since = "1.0.0")]
    pub struct Foo {
        pub x: i32
    }

    #[stable(feature = "rust1", since = "1.0.0")]
    pub mod bar {
        pub fn baz() {}
    }

Without the patch it gives:

    test.rs:12:5: 12:20 error: This node does not have a stability attribute
    test.rs:12     pub fn baz() {}
                   ^~~~~~~~~~~~~~~
    error: aborting due to previous error

With the patch it gives:

    test.rs:7:9: 7:15 error: This node does not have a stability attribute
    test.rs:7     pub x: i32
                      ^~~~~~
    test.rs:12:5: 12:20 error: This node does not have a stability attribute
    test.rs:12     pub fn baz() {}
                   ^~~~~~~~~~~~~~~
    error: aborting due to 2 previous errors
@huonw huonw force-pushed the field-stability branch 2 times, most recently from 8819038 to 1494196 Compare February 26, 2015 05:45
@huonw
Copy link
Member Author

huonw commented Feb 26, 2015

@bors r=alexcrichton 1494

@bors
Copy link
Contributor

bors commented Feb 26, 2015

⌛ Testing commit 1494196 with merge 31c85cb...

@bors
Copy link
Contributor

bors commented Feb 26, 2015

💔 Test failed - auto-linux-64-nopt-t

@alexcrichton
Copy link
Member

(cancelled build as we discovered some interesting tidbits on IRC)

@alexcrichton
Copy link
Member

@bors: retry

nevermind

@bors
Copy link
Contributor

bors commented Feb 26, 2015

⌛ Testing commit 1494196 with merge 50e209d...

@bors
Copy link
Contributor

bors commented Feb 26, 2015

💔 Test failed - auto-mac-64-opt

@huonw
Copy link
Member Author

huonw commented Feb 27, 2015

@bors r=alexcrichton 0606

@bors
Copy link
Contributor

bors commented Feb 27, 2015

⌛ Testing commit 060661d with merge 73d4eb5...

@bors
Copy link
Contributor

bors commented Feb 27, 2015

💔 Test failed - auto-linux-64-x-android-t

@Manishearth
Copy link
Member

(Manual cancel due to rollup)

Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 27, 2015
 We were recording stability attributes applied to fields in the
compiler, and even annotating it in the libs, but the compiler didn't
actually do the checks to give errors/warnings in user crates.

Details in the commit messages.
@alexcrichton
Copy link
Member

@bors: retry

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.

7 participants