Skip to content

Commit eafdc71

Browse files
committed
Record the publicity of struct fields and enum variants.
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
1 parent 19cb8f3 commit eafdc71

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/librustc_privacy/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
233233
ast::ItemEnum(ref def, _) if public_first => {
234234
for variant in &def.variants {
235235
self.exported_items.insert(variant.node.id);
236+
self.public_items.insert(variant.node.id);
236237
}
237238
}
238239

@@ -321,6 +322,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
321322
Some(id) => { self.exported_items.insert(id); }
322323
None => {}
323324
}
325+
// fields can be public or private, so lets check
326+
for field in &def.fields {
327+
let vis = match field.node.kind {
328+
ast::NamedField(_, vis) | ast::UnnamedField(vis) => vis
329+
};
330+
if vis == ast::Public {
331+
self.public_items.insert(field.node.id);
332+
}
333+
}
324334
}
325335

326336
ast::ItemTy(ref ty, _) if public_first => {

0 commit comments

Comments
 (0)