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

More flexible rule around adding public fields to struct with private fields #229

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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