Skip to content

Commit 736e8eb

Browse files
authored
Rollup merge of #89730 - crlf0710:type_changing_feature, r=jackh726
add feature flag for `type_changing_struct_update` This implements the PR0 part of the mentoring notes within #86618. overrides the previous inactive #86646 pr. r? ```@nikomatsakis```
2 parents 0f81c7f + 7d7ebf8 commit 736e8eb

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

Diff for: compiler/rustc_feature/src/active.rs

+4
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,10 @@ declare_features! (
684684
/// Allows using the `non_exhaustive_omitted_patterns` lint.
685685
(active, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554), None),
686686

687+
/// Allows creation of instances of a struct by moving fields that have
688+
/// not changed from prior instances of the same struct (RFC #2528)
689+
(incomplete, type_changing_struct_update, "1.58.0", Some(86555), None),
690+
687691
// -------------------------------------------------------------------------
688692
// feature-group-end: actual feature gates
689693
// -------------------------------------------------------------------------

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ symbols! {
13381338
type_alias_enum_variants,
13391339
type_alias_impl_trait,
13401340
type_ascription,
1341+
type_changing_struct_update,
13411342
type_id,
13421343
type_length_limit,
13431344
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)