Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Auto merge of #229 - GuillaumeGomez:more-flexible-rule, r=JohnTitor
Browse files Browse the repository at this point in the history
More flexible rule around adding public fields to struct with private fields

This comes from rust-lang/libc#2451.

Before this PR, the `kinfo_proc` struct only had one field which was private. I added the missing fields and made them all public. It doesn't seem to be a semver breaking change as the code using this struct previously will still work exactly the same.
  • Loading branch information
bors committed Oct 19, 2021
2 parents 7dcda36 + a3d2d7c commit 978dae7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ impl<'tcx> ChangeType<'tcx> {
pub fn to_category(&self) -> ChangeCategory {
// TODO: slightly messy and unreadable.
match *self {
//
// Breaking
//
ItemMadePrivate |
KindDifference |
StaticMutabilityChanged { now_mut: false } |
Expand All @@ -381,8 +384,7 @@ impl<'tcx> ChangeType<'tcx> {
TypeParameterRemoved { .. } |
VariantAdded |
VariantRemoved |
VariantFieldAdded { public: true, .. } |
VariantFieldAdded { public: false, total_public: true, .. } |
VariantFieldAdded { total_public: true, .. } |
VariantFieldRemoved { public: true, .. } |
VariantFieldRemoved { public: false, is_enum: true, .. } |
VariantStyleChanged { .. } |
Expand All @@ -397,12 +399,19 @@ impl<'tcx> ChangeType<'tcx> {
TraitImplTightened |
AssociatedItemRemoved |
Unknown => Breaking,
//
// Technically breaking
//
MethodSelfChanged { now_self: true } |
TraitItemAdded { .. } | // either defaulted or sealed
BoundsLoosened { trait_def: false, .. } |
TraitImplLoosened |
AssociatedItemAdded |
VariantFieldAdded { public: true, .. } |
ItemMadePublic => TechnicallyBreaking,
//
// Non breaking
//
StaticMutabilityChanged { now_mut: true } |
VarianceLoosened |
TypeParameterAdded { defaulted: true } |
Expand Down
5 changes: 5 additions & 0 deletions tests/cases/structs/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ pub struct Ghi {
pub struct Hij {
field: u8,
}

pub struct Iij {
pub field1: u8,
pub field2: u8,
}
4 changes: 4 additions & 0 deletions tests/cases/structs/old.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ pub struct Ghi {
}

pub struct Hij(u8);

pub struct Iij {
field: u16,
}
26 changes: 25 additions & 1 deletion tests/cases/structs/stdout
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,29 @@ warning: tuple struct with no public fields changed to a regular struct (breakin
28 | | }
| |_^

error: aborting due to 4 previous errors; 2 warnings emitted
warning: technically breaking changes in `Iij`
--> structs/new.rs:30:1
|
30 | / pub struct Iij {
31 | | pub field1: u8,
32 | | pub field2: u8,
33 | | }
| |_^
|
note: private field removed from struct with private fields (non-breaking)
--> structs/old.rs:29:5
|
29 | field: u16,
| ^^^^^^^^^^
note: public field added to struct with private fields (technically breaking)
--> structs/new.rs:31:5
|
31 | pub field1: u8,
| ^^^^^^^^^^^^^^
note: public field added to struct with private fields (technically breaking)
--> structs/new.rs:32:5
|
32 | pub field2: u8,
| ^^^^^^^^^^^^^^

error: aborting due to 4 previous errors; 3 warnings emitted

0 comments on commit 978dae7

Please sign in to comment.