@@ -44,6 +44,20 @@ pub enum InheritedRefOnRefBehavior {
4444 Error ,
4545}
4646
47+ /// In `InheritedRefOnRefBehavior::EatBoth` or `EatInner` modes, what to do if a reference pattern
48+ /// fails to match against an underlying place of reference type.
49+ #[ derive(
50+ Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Serialize , Deserialize , Encode , Decode ,
51+ ) ]
52+ pub enum FallbackToOuterBehavior {
53+ /// Do nothing.
54+ No ,
55+ /// If there is an inherited reference, match against it and consume it.
56+ EatOuter ,
57+ /// If there is an inherited reference, match against it and consume both references.
58+ EatBoth ,
59+ }
60+
4761/// Choice of typing rules.
4862#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , Serialize , Deserialize , Encode , Decode ) ]
4963pub struct RuleOptions {
@@ -55,9 +69,10 @@ pub struct RuleOptions {
5569 /// What happens with a `&mut?p` pattern matching on `&mut?&mut?T` where the outer reference is
5670 /// inherited.
5771 pub inherited_ref_on_ref : InheritedRefOnRefBehavior ,
58- /// In the `EatBoth` and `EatInner` cases, if matching against the underlying place fails this
59- /// determines whether we try again in `EatOuter` mode.
60- pub fallback_to_outer : bool ,
72+ /// In `InheritedRefOnRefBehavior::EatBoth` or `EatInner` modes, if a reference pattern fails
73+ /// to match against an underlying place of reference type, and there is an inherited
74+ /// reference, this determines if we try matching against it.
75+ pub fallback_to_outer : FallbackToOuterBehavior ,
6176 /// Whether a `&p` pattern is allowed on `&mut T`. This is RFC3627 rule 5.
6277 pub allow_ref_pat_on_ref_mut : bool ,
6378 /// Whether to simplify some expressions, which removes some borrow errors involving mixes of
@@ -249,15 +264,21 @@ pub const TY_BASED_OPTIONS_DOC: &[OptionsDoc] = &[
249264 case has a mutability mismatch",
250265 values : & [
251266 OptionValue {
252- name : "false " ,
267+ name : "No " ,
253268 doc : "Don't try matching on the outer reference if \
254269 matching on the inner reference caused a mutability mismatch",
255270 } ,
256271 OptionValue {
257- name : "true " ,
272+ name : "EatOuter " ,
258273 doc : "Try matching on the outer reference if \
259274 matching on the inner reference caused a mutability mismatch",
260275 } ,
276+ OptionValue {
277+ name : "EatBoth" ,
278+ doc : "Try matching on the outer reference if \
279+ matching on the inner reference caused a mutability mismatch. \
280+ If this succeeds, consume both references.",
281+ } ,
261282 ] ,
262283 } ,
263284 OptionsDoc {
@@ -370,7 +391,7 @@ impl RuleOptions {
370391 ref_binding_on_inherited : RefBindingOnInheritedBehavior :: ResetBindingMode ,
371392 mut_binding_on_inherited : MutBindingOnInheritedBehavior :: ResetBindingMode ,
372393 inherited_ref_on_ref : InheritedRefOnRefBehavior :: EatBoth ,
373- fallback_to_outer : false ,
394+ fallback_to_outer : FallbackToOuterBehavior :: No ,
374395 allow_ref_pat_on_ref_mut : false ,
375396 simplify_deref_mut : true ,
376397 eat_inherited_ref_alone : false ,
@@ -384,7 +405,7 @@ impl RuleOptions {
384405 ref_binding_on_inherited : RefBindingOnInheritedBehavior :: ResetBindingMode ,
385406 mut_binding_on_inherited : MutBindingOnInheritedBehavior :: Error ,
386407 inherited_ref_on_ref : InheritedRefOnRefBehavior :: EatInner ,
387- fallback_to_outer : true ,
408+ fallback_to_outer : FallbackToOuterBehavior :: EatOuter ,
388409 allow_ref_pat_on_ref_mut : true ,
389410 simplify_deref_mut : true ,
390411 eat_inherited_ref_alone : true ,
@@ -399,7 +420,7 @@ impl RuleOptions {
399420 ref_binding_on_inherited : RefBindingOnInheritedBehavior :: AllocTemporary ,
400421 mut_binding_on_inherited : MutBindingOnInheritedBehavior :: Keep ,
401422 inherited_ref_on_ref : InheritedRefOnRefBehavior :: EatOuter ,
402- fallback_to_outer : false ,
423+ fallback_to_outer : FallbackToOuterBehavior :: No ,
403424 allow_ref_pat_on_ref_mut : true ,
404425 simplify_deref_mut : true ,
405426 eat_inherited_ref_alone : true ,
@@ -434,14 +455,14 @@ impl RuleOptions {
434455 pub const RFC3627_2021 : Self = RuleOptions {
435456 mut_binding_on_inherited : MutBindingOnInheritedBehavior :: ResetBindingMode ,
436457 inherited_ref_on_ref : InheritedRefOnRefBehavior :: EatBoth ,
437- fallback_to_outer : true ,
458+ fallback_to_outer : FallbackToOuterBehavior :: EatOuter ,
438459 ..RuleOptions :: ERGO2024
439460 } ;
440461
441462 pub const ERGO2024_BREAKING_ONLY : Self = RuleOptions {
442463 mut_binding_on_inherited : MutBindingOnInheritedBehavior :: Error ,
443464 inherited_ref_on_ref : InheritedRefOnRefBehavior :: EatInner ,
444- fallback_to_outer : false ,
465+ fallback_to_outer : FallbackToOuterBehavior :: No ,
445466 ..RuleOptions :: STABLE_RUST
446467 } ;
447468
0 commit comments