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

Commit 978dae7

Browse files
committed
Auto merge of #229 - GuillaumeGomez:more-flexible-rule, r=JohnTitor
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.
2 parents 7dcda36 + a3d2d7c commit 978dae7

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

src/changes.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ impl<'tcx> ChangeType<'tcx> {
370370
pub fn to_category(&self) -> ChangeCategory {
371371
// TODO: slightly messy and unreadable.
372372
match *self {
373+
//
374+
// Breaking
375+
//
373376
ItemMadePrivate |
374377
KindDifference |
375378
StaticMutabilityChanged { now_mut: false } |
@@ -381,8 +384,7 @@ impl<'tcx> ChangeType<'tcx> {
381384
TypeParameterRemoved { .. } |
382385
VariantAdded |
383386
VariantRemoved |
384-
VariantFieldAdded { public: true, .. } |
385-
VariantFieldAdded { public: false, total_public: true, .. } |
387+
VariantFieldAdded { total_public: true, .. } |
386388
VariantFieldRemoved { public: true, .. } |
387389
VariantFieldRemoved { public: false, is_enum: true, .. } |
388390
VariantStyleChanged { .. } |
@@ -397,12 +399,19 @@ impl<'tcx> ChangeType<'tcx> {
397399
TraitImplTightened |
398400
AssociatedItemRemoved |
399401
Unknown => Breaking,
402+
//
403+
// Technically breaking
404+
//
400405
MethodSelfChanged { now_self: true } |
401406
TraitItemAdded { .. } | // either defaulted or sealed
402407
BoundsLoosened { trait_def: false, .. } |
403408
TraitImplLoosened |
404409
AssociatedItemAdded |
410+
VariantFieldAdded { public: true, .. } |
405411
ItemMadePublic => TechnicallyBreaking,
412+
//
413+
// Non breaking
414+
//
406415
StaticMutabilityChanged { now_mut: true } |
407416
VarianceLoosened |
408417
TypeParameterAdded { defaulted: true } |

tests/cases/structs/new.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ pub struct Ghi {
2626
pub struct Hij {
2727
field: u8,
2828
}
29+
30+
pub struct Iij {
31+
pub field1: u8,
32+
pub field2: u8,
33+
}

tests/cases/structs/old.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ pub struct Ghi {
2424
}
2525

2626
pub struct Hij(u8);
27+
28+
pub struct Iij {
29+
field: u16,
30+
}

tests/cases/structs/stdout

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,29 @@ warning: tuple struct with no public fields changed to a regular struct (breakin
7979
28 | | }
8080
| |_^
8181

82-
error: aborting due to 4 previous errors; 2 warnings emitted
82+
warning: technically breaking changes in `Iij`
83+
--> structs/new.rs:30:1
84+
|
85+
30 | / pub struct Iij {
86+
31 | | pub field1: u8,
87+
32 | | pub field2: u8,
88+
33 | | }
89+
| |_^
90+
|
91+
note: private field removed from struct with private fields (non-breaking)
92+
--> structs/old.rs:29:5
93+
|
94+
29 | field: u16,
95+
| ^^^^^^^^^^
96+
note: public field added to struct with private fields (technically breaking)
97+
--> structs/new.rs:31:5
98+
|
99+
31 | pub field1: u8,
100+
| ^^^^^^^^^^^^^^
101+
note: public field added to struct with private fields (technically breaking)
102+
--> structs/new.rs:32:5
103+
|
104+
32 | pub field2: u8,
105+
| ^^^^^^^^^^^^^^
83106

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

0 commit comments

Comments
 (0)