From 712673cd8f11fd033872e52f8c078263615006fb Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 18 Jan 2025 22:17:54 +0100 Subject: [PATCH] Make `structural` displayable without state --- src/rulesets/ty_based.rs | 6 +- .../bundle_rules@structural-Expression.snap | 16 ++-- ...ndle_rules@structural-SequentInMemory.snap | 16 ++-- ...e_rules@structural-SequentUserVisible.snap | 42 +++++----- .../trace_cli@10939586865865297633.snap | 76 ++++++++++++------- .../trace_cli@14439240379964399004.snap | 36 +++++---- .../trace_cli@5650066042996044784.snap | 28 ++++--- 7 files changed, 130 insertions(+), 90 deletions(-) diff --git a/src/rulesets/ty_based.rs b/src/rulesets/ty_based.rs index 52e3715..c3662b8 100644 --- a/src/rulesets/ty_based.rs +++ b/src/rulesets/ty_based.rs @@ -436,10 +436,8 @@ impl RuleOptions { /// Purely structural matching, with no match ergonomics. pub const STRUCTURAL: Self = RuleOptions { - match_constructor_through_ref: false, - ref_binding_on_inherited: RefBindingOnInheritedBehavior::Error, - mut_binding_on_inherited: MutBindingOnInheritedBehavior::Error, inherited_ref_on_ref: InheritedRefOnRefBehavior::Error, + match_constructor_through_ref: false, allow_ref_pat_on_ref_mut: false, eat_inherited_ref_alone: false, eat_mut_inside_shared: false, @@ -448,6 +446,8 @@ impl RuleOptions { /// The minimal amout of match ergonomics that's forward-compatible with most proposals. pub const MIN_ERGONOMICS: Self = RuleOptions { + ref_binding_on_inherited: RefBindingOnInheritedBehavior::Error, + mut_binding_on_inherited: MutBindingOnInheritedBehavior::Error, match_constructor_through_ref: true, ..Self::STRUCTURAL }; diff --git a/tests/snapshots/bundle_rules@structural-Expression.snap b/tests/snapshots/bundle_rules@structural-Expression.snap index 913ee82..e81f873 100644 --- a/tests/snapshots/bundle_rules@structural-Expression.snap +++ b/tests/snapshots/bundle_rules@structural-Expression.snap @@ -11,8 +11,8 @@ info: simplify_deref_mut: true downgrade_mut_inside_shared: false eat_mut_inside_shared: false - ref_binding_on_inherited: Error - mut_binding_on_inherited: Error + ref_binding_on_inherited: AllocTemporary + mut_binding_on_inherited: Keep --- p0 @ e.0: T0, p1 @ e.1: T1 --------------------------- "Constructor" @@ -27,17 +27,17 @@ p @ *e: T &mut p @ e: &mut T x @ &e: &T ----------------------------------- "BindingBorrow" -ref x @ e: T, e is not a reference +------------ "BindingBorrow" +ref x @ e: T x @ &mut e: &mut T --------------------------------------- "BindingBorrow" -ref mut x @ e: T, e is not a reference +------------------ "BindingBorrow" +ref mut x @ e: T -------- "Binding" x @ e: T ----------------------------------- "Binding" -mut x @ e: T, e is not a reference +------------ "Binding" +mut x @ e: T diff --git a/tests/snapshots/bundle_rules@structural-SequentInMemory.snap b/tests/snapshots/bundle_rules@structural-SequentInMemory.snap index 9adce06..f1b40df 100644 --- a/tests/snapshots/bundle_rules@structural-SequentInMemory.snap +++ b/tests/snapshots/bundle_rules@structural-SequentInMemory.snap @@ -11,8 +11,8 @@ info: simplify_deref_mut: true downgrade_mut_inside_shared: false eat_mut_inside_shared: false - ref_binding_on_inherited: Error - mut_binding_on_inherited: Error + ref_binding_on_inherited: AllocTemporary + mut_binding_on_inherited: Keep --- move ⊢ p0: T0, move ⊢ p1: T1 ----------------------------- "Constructor" @@ -27,17 +27,17 @@ move ⊢ p: T move ⊢ &mut p: &mut T ref ⊢ x: T ---------------- "BindingBorrow" -move ⊢ ref x: T +------------- "BindingBorrow" +bm ⊢ ref x: T ref mut ⊢ x: T -------------------- "BindingBorrow" -move ⊢ ref mut x: T +----------------- "BindingBorrow" +bm ⊢ ref mut x: T --------- "Binding" bm ⊢ x: T ---------------- "Binding" -move ⊢ mut x: T +------------- "Binding" +bm ⊢ mut x: T diff --git a/tests/snapshots/bundle_rules@structural-SequentUserVisible.snap b/tests/snapshots/bundle_rules@structural-SequentUserVisible.snap index 2cfc389..15b9d74 100644 --- a/tests/snapshots/bundle_rules@structural-SequentUserVisible.snap +++ b/tests/snapshots/bundle_rules@structural-SequentUserVisible.snap @@ -11,33 +11,33 @@ info: simplify_deref_mut: true downgrade_mut_inside_shared: false eat_mut_inside_shared: false - ref_binding_on_inherited: Error - mut_binding_on_inherited: Error + ref_binding_on_inherited: AllocTemporary + mut_binding_on_inherited: Keep --- -real ⊢ p0: T0, real ⊢ p1: T1 ------------------------------ "Constructor" -_ ⊢ [p0, p1]: [T0, T1] +p0: T0, p1: T1 +------------------ "Constructor" +[p0, p1]: [T0, T1] -real ⊢ p: T ------------ "Deref" -r ⊢ &p: &T +p: T +------ "Deref" +&p: &T -real ⊢ p: T ------------------- "Deref" -r ⊢ &mut p: &mut T +p: T +-------------- "Deref" +&mut p: &mut T -inh ⊢ x: &T ---------------- "BindingBorrow" -real ⊢ ref x: T +x: &T +-------- "BindingBorrow" +ref x: T -inh ⊢ x: &mut T -------------------- "BindingBorrow" -real ⊢ ref mut x: T +x: &mut T +------------ "BindingBorrow" +ref mut x: T --------- "Binding" -r ⊢ x: T +---- "Binding" +x: T ---------------- "Binding" -real ⊢ mut x: T +-------- "Binding" +mut x: T diff --git a/tests/snapshots/trace_cli@10939586865865297633.snap b/tests/snapshots/trace_cli@10939586865865297633.snap index 8fd0df5..41db23f 100644 --- a/tests/snapshots/trace_cli@10939586865865297633.snap +++ b/tests/snapshots/trace_cli@10939586865865297633.snap @@ -34,13 +34,21 @@ The old ruleset is on the left, and the new one on the right. ----------------- "DerefMutWithShared" | r, m ⊢ &p: &mut T | - | - ------------------ "Binding" | - inh, m ⊢ mut x: &T | + | inh, m ⊢ x: &&T + | ------------------ "BindingBorrow" + | inh, m ⊢ ref x: &T - | - ---------------------- "Binding" | - inh, m ⊢ mut x: &mut T | + | inh, m ⊢ x: &&mut T + | ---------------------- "BindingBorrow" + | inh, m ⊢ ref x: &mut T + + | inh, m ⊢ x: &mut &T + | ---------------------- "BindingBorrow" + | inh, m ⊢ ref mut x: &T + + | inh, m ⊢ x: &mut &mut T + | -------------------------- "BindingBorrow" + | inh, m ⊢ ref mut x: &mut T allow_ref_pat_on_ref_mut: true -> false @@ -50,8 +58,8 @@ eat_mut_inside_shared: true -> false fallback_to_outer: "No" inherited_ref_on_ref: "EatOuter" -> "Error" match_constructor_through_ref: true -> false -mut_binding_on_inherited: "Keep" -> "Error" -ref_binding_on_inherited: "Error" +mut_binding_on_inherited: "Keep" +ref_binding_on_inherited: "Error" -> "AllocTemporary" simplify_deref_mut: true Current and saved rulesets were swapped The two rulesets are described by the following sets of rules, with differences highlighted. @@ -85,13 +93,21 @@ The old current ruleset is on the left, and the new current one on the right. | ----------------- "DerefMutWithShared" | r, m ⊢ &p: &mut T - | - | ------------------ "Binding" - | inh, m ⊢ mut x: &T + inh, m ⊢ x: &&T | + ------------------ "BindingBorrow" | + inh, m ⊢ ref x: &T | - | - | ---------------------- "Binding" - | inh, m ⊢ mut x: &mut T + inh, m ⊢ x: &&mut T | + ---------------------- "BindingBorrow" | + inh, m ⊢ ref x: &mut T | + + inh, m ⊢ x: &mut &T | + ---------------------- "BindingBorrow" | + inh, m ⊢ ref mut x: &T | + + inh, m ⊢ x: &mut &mut T | + -------------------------- "BindingBorrow" | + inh, m ⊢ ref mut x: &mut T | allow_ref_pat_on_ref_mut: false -> true @@ -101,8 +117,8 @@ eat_mut_inside_shared: false -> true fallback_to_outer: "No" inherited_ref_on_ref: "Error" -> "EatOuter" match_constructor_through_ref: false -> true -mut_binding_on_inherited: "Error" -> "Keep" -ref_binding_on_inherited: "Error" +mut_binding_on_inherited: "Keep" +ref_binding_on_inherited: "AllocTemporary" -> "Error" simplify_deref_mut: true Comparing against the saved ruleset. Use `unsave` to forget the saved ruleset. The two rulesets are described by the following sets of rules, with differences highlighted. @@ -152,22 +168,30 @@ The current ruleset is on the left, and the saved one on the right. ------------------ "BindingBorrow" | ------------------ "BindingBorrow" real, m ⊢ ref x: T | real, m ⊢ ref x: T + | inh, m ⊢ x: &&T + | ------------------ "BindingBorrow" + | inh, m ⊢ ref x: &T + + | inh, m ⊢ x: &&mut T + | ---------------------- "BindingBorrow" + | inh, m ⊢ ref x: &mut T + inh, m ⊢ x: &mut T | inh, m ⊢ x: &mut T ---------------------- "BindingBorrow" | ---------------------- "BindingBorrow" real, m ⊢ ref mut x: T | real, m ⊢ ref mut x: T - | - ----------- "Binding" | ----------- "Binding" - r, m ⊢ x: T | r, m ⊢ x: T + | inh, m ⊢ x: &mut &T + | ---------------------- "BindingBorrow" + | inh, m ⊢ ref mut x: &T - | - ------------------ "Binding" | ------------------ "Binding" - real, m ⊢ mut x: T | real, m ⊢ mut x: T + | inh, m ⊢ x: &mut &mut T + | -------------------------- "BindingBorrow" + | inh, m ⊢ ref mut x: &mut T | - ------------------ "Binding" | - inh, m ⊢ mut x: &T | + ----------- "Binding" | ----------- "Binding" + r, m ⊢ x: T | r, m ⊢ x: T | - ---------------------- "Binding" | - inh, m ⊢ mut x: &mut T | + --------------- "Binding" | --------------- "Binding" + r, m ⊢ mut x: T | r, m ⊢ mut x: T diff --git a/tests/snapshots/trace_cli@14439240379964399004.snap b/tests/snapshots/trace_cli@14439240379964399004.snap index 9cd9c89..dadcb29 100644 --- a/tests/snapshots/trace_cli@14439240379964399004.snap +++ b/tests/snapshots/trace_cli@14439240379964399004.snap @@ -33,13 +33,21 @@ The old ruleset is on the left, and the new one on the right. ----------------- "DerefMutWithShared" | r, m ⊢ &p: &mut T | - | - ------------------ "Binding" | - inh, m ⊢ mut x: &T | + | inh, m ⊢ x: &&T + | ------------------ "BindingBorrow" + | inh, m ⊢ ref x: &T - | - ---------------------- "Binding" | - inh, m ⊢ mut x: &mut T | + | inh, m ⊢ x: &&mut T + | ---------------------- "BindingBorrow" + | inh, m ⊢ ref x: &mut T + + | inh, m ⊢ x: &mut &T + | ---------------------- "BindingBorrow" + | inh, m ⊢ ref mut x: &T + + | inh, m ⊢ x: &mut &mut T + | -------------------------- "BindingBorrow" + | inh, m ⊢ ref mut x: &mut T allow_ref_pat_on_ref_mut: true -> false @@ -49,8 +57,8 @@ eat_mut_inside_shared: true -> false fallback_to_outer: "No" inherited_ref_on_ref: "EatOuter" -> "Error" match_constructor_through_ref: true -> false -mut_binding_on_inherited: "Keep" -> "Error" -ref_binding_on_inherited: "Error" +mut_binding_on_inherited: "Keep" +ref_binding_on_inherited: "Error" -> "AllocTemporary" simplify_deref_mut: true The current options can be fully described as the following set of rules. The typing predicate looks like `r, m ⊢ p: T`, where @@ -72,17 +80,17 @@ real, m ⊢ p: T r, m ⊢ &mut p: &mut T inh, m ⊢ x: &T ------------------- "BindingBorrow" -real, m ⊢ ref x: T +--------------- "BindingBorrow" +r, m ⊢ ref x: T inh, m ⊢ x: &mut T ----------------------- "BindingBorrow" -real, m ⊢ ref mut x: T +------------------- "BindingBorrow" +r, m ⊢ ref mut x: T ----------- "Binding" r, m ⊢ x: T ------------------- "Binding" -real, m ⊢ mut x: T +--------------- "Binding" +r, m ⊢ mut x: T diff --git a/tests/snapshots/trace_cli@5650066042996044784.snap b/tests/snapshots/trace_cli@5650066042996044784.snap index 096cbfd..8d7ddf1 100644 --- a/tests/snapshots/trace_cli@5650066042996044784.snap +++ b/tests/snapshots/trace_cli@5650066042996044784.snap @@ -34,13 +34,21 @@ The old ruleset is on the left, and the new one on the right. ----------------- "DerefMutWithShared" | r, m ⊢ &p: &mut T | - | - ------------------ "Binding" | - inh, m ⊢ mut x: &T | + | inh, m ⊢ x: &&T + | ------------------ "BindingBorrow" + | inh, m ⊢ ref x: &T - | - ---------------------- "Binding" | - inh, m ⊢ mut x: &mut T | + | inh, m ⊢ x: &&mut T + | ---------------------- "BindingBorrow" + | inh, m ⊢ ref x: &mut T + + | inh, m ⊢ x: &mut &T + | ---------------------- "BindingBorrow" + | inh, m ⊢ ref mut x: &T + + | inh, m ⊢ x: &mut &mut T + | -------------------------- "BindingBorrow" + | inh, m ⊢ ref mut x: &mut T allow_ref_pat_on_ref_mut: true -> false @@ -50,8 +58,8 @@ eat_mut_inside_shared: true -> false fallback_to_outer: "No" inherited_ref_on_ref: "EatOuter" -> "Error" match_constructor_through_ref: true -> false -mut_binding_on_inherited: "Keep" -> "Error" -ref_binding_on_inherited: "Error" +mut_binding_on_inherited: "Keep" +ref_binding_on_inherited: "Error" -> "AllocTemporary" simplify_deref_mut: true Comparing against the saved ruleset. Use `unsave` to forget the saved ruleset. The current ruleset is on the left, and the saved one on the right. @@ -62,6 +70,6 @@ eat_mut_inside_shared: false -> true fallback_to_outer: "No" inherited_ref_on_ref: "Error" -> "EatOuter" match_constructor_through_ref: false -> true -mut_binding_on_inherited: "Error" -> "Keep" -ref_binding_on_inherited: "Error" +mut_binding_on_inherited: "Keep" +ref_binding_on_inherited: "AllocTemporary" -> "Error" simplify_deref_mut: true