Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add failing tests for type_changing_struct_update feature flag #86660

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -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<S> {
state: S,
common_field1: &'static str,
common_field2: i32,
}

struct State1;
struct State2;

impl Machine<State1> {
fn into_state2(self) -> Machine<State2> {
// 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<State1> = Machine {
state: State1,
common_field1: "hello",
common_field2: 2,
};
let m2: Machine<State2> = m1.into_state2();
assert_eq!(State2, m2.state);
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -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<State2>`
found struct `Machine<State1>`