diff options
| author | Charles Lew <crlf0710@gmail.com> | 2021-10-10 14:50:39 +0800 |
|---|---|---|
| committer | jackh726 <jack.huey@umassmed.edu> | 2021-10-22 11:46:55 -0400 |
| commit | 7d7ebf88057ad6e16331e02a86c5951ecd1f23db (patch) | |
| tree | 24fe7f96878bb4b61f4ac53f0235fd8ed74380f5 | |
| parent | 1ddd4e6d7ed446934abd428a08e18535faef5e03 (diff) | |
| download | rust-7d7ebf88057ad6e16331e02a86c5951ecd1f23db.tar.gz rust-7d7ebf88057ad6e16331e02a86c5951ecd1f23db.zip | |
add feature flag for `type_changing_struct_update`
4 files changed, 43 insertions, 0 deletions
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index a2fadb13a57..af40705cbfc 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -681,6 +681,10 @@ declare_features! ( /// Allows using the `non_exhaustive_omitted_patterns` lint. (active, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554), None), + /// Allows creation of instances of a struct by moving fields that have + /// not changed from prior instances of the same struct (RFC #2528) + (incomplete, type_changing_struct_update, "1.58.0", Some(86555), None), + // ------------------------------------------------------------------------- // feature-group-end: actual feature gates // ------------------------------------------------------------------------- diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 9551120ca55..0327e56f9d7 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1335,6 +1335,7 @@ symbols! { type_alias_enum_variants, type_alias_impl_trait, type_ascription, + type_changing_struct_update, type_id, type_length_limit, type_macros, diff --git a/src/test/ui/feature-gates/feature-gate-type_changing_struct_update.rs b/src/test/ui/feature-gates/feature-gate-type_changing_struct_update.rs new file mode 100644 index 00000000000..520c1478f32 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-type_changing_struct_update.rs @@ -0,0 +1,26 @@ +#[derive(Debug)] +struct Machine<S> { + state: S, + common_field1: &'static str, + common_field2: i32, +} +#[derive(Debug)] +struct State1; +#[derive(Debug, PartialEq)] +struct State2; + +fn update_to_state2() { + let m1: Machine<State1> = Machine { + state: State1, + common_field1: "hello", + common_field2: 2, + }; + let m2: Machine<State2> = Machine { + state: State2, + ..m1 //~ ERROR mismatched types + }; + // FIXME: this should trigger feature gate + assert_eq!(State2, m2.state); +} + +fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-type_changing_struct_update.stderr b/src/test/ui/feature-gates/feature-gate-type_changing_struct_update.stderr new file mode 100644 index 00000000000..9934fe68164 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-type_changing_struct_update.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/feature-gate-type_changing_struct_update.rs:20:11 + | +LL | ..m1 + | ^^ expected struct `State2`, found struct `State1` + | + = note: expected struct `Machine<State2>` + found struct `Machine<State1>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. |
