From a0d1bb3e303f023e477979b7851582078b9493b8 Mon Sep 17 00:00:00 2001 From: Predrag Gruevski Date: Tue, 31 Jan 2023 01:32:09 +0000 Subject: [PATCH] Test case: replace type with a more generic one without major change. --- .../new/Cargo.toml | 7 ++ .../new/src/lib.rs | 78 +++++++++++++++++++ .../old/Cargo.toml | 7 ++ .../old/src/lib.rs | 46 +++++++++++ 4 files changed, 138 insertions(+) create mode 100644 test_crates/type_alias_over_more_generic_underlying/new/Cargo.toml create mode 100644 test_crates/type_alias_over_more_generic_underlying/new/src/lib.rs create mode 100644 test_crates/type_alias_over_more_generic_underlying/old/Cargo.toml create mode 100644 test_crates/type_alias_over_more_generic_underlying/old/src/lib.rs diff --git a/test_crates/type_alias_over_more_generic_underlying/new/Cargo.toml b/test_crates/type_alias_over_more_generic_underlying/new/Cargo.toml new file mode 100644 index 00000000..46ab5ffa --- /dev/null +++ b/test_crates/type_alias_over_more_generic_underlying/new/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "type_alias_over_more_generic_underlying" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/type_alias_over_more_generic_underlying/new/src/lib.rs b/test_crates/type_alias_over_more_generic_underlying/new/src/lib.rs new file mode 100644 index 00000000..5ab8cd01 --- /dev/null +++ b/test_crates/type_alias_over_more_generic_underlying/new/src/lib.rs @@ -0,0 +1,78 @@ +//! We're going to replace the original type (named like `OriginalType`) with two types: +//! - `pub struct NewType` +//! - `pub type OriginalType = NewType` +//! +//! This is not semver-major, since the type alias has: +//! - the same name +//! - the same fields/variants +//! - the same constructibility and pattern-matching behavior. + +pub struct NewStructOnlyPrivateFields { + _marker: std::marker::PhantomData, +} + +pub type OriginalStructOnlyPrivateFields = NewStructOnlyPrivateFields<()>; + +// --- + +pub struct NewStructGeneric { + _marker: std::marker::PhantomData<(A, B)>, +} + +pub type OriginalStructGeneric = NewStructGeneric; + +// --- + +pub struct NewStructMixOfFields { + _marker: std::marker::PhantomData, + pub x: i64, +} + +pub type OriginalStructMixOfFields = NewStructMixOfFields<()>; + +// --- + +pub struct NewStructConstructible { + pub x: T, +} + +pub type OriginalStructConstructible = NewStructConstructible; + +// --- + +pub struct NewStructEmpty { + _marker: std::marker::PhantomData, +} + +pub type OriginalStructEmpty = NewStructEmpty<()>; + +// --- + +#[non_exhaustive] +pub struct NewStructConstructibleNonexhaustive { + pub x: A, +} + +pub type OriginalStructConstructibleNonexhaustive = NewStructConstructibleNonexhaustive; + +// --- + +#[non_exhaustive] +pub struct NewStructEmptyNonexhaustive { + pub x: A, +} + +pub type OriginalStructEmptyNonexhaustive = NewStructEmptyNonexhaustive; + +// --- +// The enum case is interesting: to add a generic parameter, we need to use it somewhere. +// We'll need to add a variant, so the original enum must have been non-exhaustive +// to avoid an immediate major breaking change. + +#[non_exhaustive] +pub enum NewEnumNonexhaustive { + First, + Second(A), +} + +pub type OriginalEnumNonexhaustive = NewEnumNonexhaustive<()>; diff --git a/test_crates/type_alias_over_more_generic_underlying/old/Cargo.toml b/test_crates/type_alias_over_more_generic_underlying/old/Cargo.toml new file mode 100644 index 00000000..46ab5ffa --- /dev/null +++ b/test_crates/type_alias_over_more_generic_underlying/old/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "type_alias_over_more_generic_underlying" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/type_alias_over_more_generic_underlying/old/src/lib.rs b/test_crates/type_alias_over_more_generic_underlying/old/src/lib.rs new file mode 100644 index 00000000..f141436b --- /dev/null +++ b/test_crates/type_alias_over_more_generic_underlying/old/src/lib.rs @@ -0,0 +1,46 @@ +//! We're going to replace the original type (named like `OriginalType`) with two types: +//! - `pub struct NewType` +//! - `pub type OriginalType = NewType` +//! +//! This is not semver-major, since the type alias has: +//! - the same name +//! - the same fields +//! - the same constructibility and pattern-matching behavior. + +pub struct OriginalStructOnlyPrivateFields { + _marker: std::marker::PhantomData<()>, +} + +pub struct OriginalStructGeneric { + _marker: std::marker::PhantomData, +} + +pub struct OriginalStructMixOfFields { + _marker: std::marker::PhantomData<()>, + pub x: i64, +} + +pub struct OriginalStructConstructible { + pub x: i64, +} + +pub struct OriginalStructEmpty {} + +#[non_exhaustive] +pub struct OriginalStructConstructibleNonexhaustive { + pub x: i64, +} + +#[non_exhaustive] +pub struct OriginalStructEmptyNonexhaustive { + pub x: i64, +} + +// The enum case is interesting: to add a generic parameter, we need to use it somewhere. +// We'll need to add a variant, so the original enum must have been non-exhaustive +// to avoid an immediate major breaking change. + +#[non_exhaustive] +pub enum OriginalEnumNonexhaustive { + First, +}