Skip to content

Commit 7d7ebf8

Browse files
crlf0710jackh726
authored andcommitted
add feature flag for type_changing_struct_update
1 parent 1ddd4e6 commit 7d7ebf8

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

compiler/rustc_feature/src/active.rs

+4
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,10 @@ declare_features! (
681681
/// Allows using the `non_exhaustive_omitted_patterns` lint.
682682
(active, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554), None),
683683

684+
/// Allows creation of instances of a struct by moving fields that have
685+
/// not changed from prior instances of the same struct (RFC #2528)
686+
(incomplete, type_changing_struct_update, "1.58.0", Some(86555), None),
687+
684688
// -------------------------------------------------------------------------
685689
// feature-group-end: actual feature gates
686690
// -------------------------------------------------------------------------

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,7 @@ symbols! {
13351335
type_alias_enum_variants,
13361336
type_alias_impl_trait,
13371337
type_ascription,
1338+
type_changing_struct_update,
13381339
type_id,
13391340
type_length_limit,
13401341
type_macros,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#[derive(Debug)]
2+
struct Machine<S> {
3+
state: S,
4+
common_field1: &'static str,
5+
common_field2: i32,
6+
}
7+
#[derive(Debug)]
8+
struct State1;
9+
#[derive(Debug, PartialEq)]
10+
struct State2;
11+
12+
fn update_to_state2() {
13+
let m1: Machine<State1> = Machine {
14+
state: State1,
15+
common_field1: "hello",
16+
common_field2: 2,
17+
};
18+
let m2: Machine<State2> = Machine {
19+
state: State2,
20+
..m1 //~ ERROR mismatched types
21+
};
22+
// FIXME: this should trigger feature gate
23+
assert_eq!(State2, m2.state);
24+
}
25+
26+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/feature-gate-type_changing_struct_update.rs:20:11
3+
|
4+
LL | ..m1
5+
| ^^ expected struct `State2`, found struct `State1`
6+
|
7+
= note: expected struct `Machine<State2>`
8+
found struct `Machine<State1>`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)