diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 56a320c8d3bce..d8e35ceb977b5 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -666,6 +666,10 @@ declare_features! ( /// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns. (active, more_qualified_paths, "1.54.0", Some(80080), None), + /// Allows creation of instances of a struct by moving fields that have + /// not changed from prior instances of the same struct (RFC #2528) + (active, type_changing_struct_update, "1.55.0", Some(86618), None) + // ------------------------------------------------------------------------- // feature-group-end: actual feature gates // ------------------------------------------------------------------------- diff --git a/src/test/ui/type_changing_struct_update_rfc_2528/basic_tests_setup.rs b/src/test/ui/type_changing_struct_update_rfc_2528/basic_tests_setup.rs new file mode 100644 index 0000000000000..02791ce491a46 --- /dev/null +++ b/src/test/ui/type_changing_struct_update_rfc_2528/basic_tests_setup.rs @@ -0,0 +1,39 @@ +// gate-test-type_changing_struct_update + +/// Here, we're documenting the current state of affairs related to +/// FRU (functional record update) + +#![feature(type_changing_struct_update)] + +struct Machine { + state: S, + common_field1: &'static str, + common_field2: i32, +} + +struct State1; +struct State2; + +impl Machine { + fn into_state2(self) -> Machine { + // do stuff + Machine { + state: State2, + ..self + } + } +} + +#[test] +#[should_panic] // NOTE: this would be fixed by the implementation of the RFC +fn update_to_state2() { + let m1: Machine = Machine { + state: State1, + common_field1: "hello", + common_field2: 2, + }; + let m2: Machine = m1.into_state2(); + assert_eq!(State2, m2.state); +} + +fn main() {} diff --git a/src/test/ui/type_changing_struct_update_rfc_2528/basic_tests_setup.stderr b/src/test/ui/type_changing_struct_update_rfc_2528/basic_tests_setup.stderr new file mode 100644 index 0000000000000..b9bb1d5d44a44 --- /dev/null +++ b/src/test/ui/type_changing_struct_update_rfc_2528/basic_tests_setup.stderr @@ -0,0 +1,8 @@ +error[E0308]: mismatched types + --> $DIR/basic_tests_setup.rs:19:15 + | +LL | ..self + | ^^^^ expected struct `State2`, found struct `State1` + | + = note: expected struct `Machine` + found struct `Machine`