@@ -44,6 +44,20 @@ pub enum InheritedRefOnRefBehavior {
44
44
Error ,
45
45
}
46
46
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
+
47
61
/// Choice of typing rules.
48
62
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , Serialize , Deserialize , Encode , Decode ) ]
49
63
pub struct RuleOptions {
@@ -55,9 +69,10 @@ pub struct RuleOptions {
55
69
/// What happens with a `&mut?p` pattern matching on `&mut?&mut?T` where the outer reference is
56
70
/// inherited.
57
71
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 ,
61
76
/// Whether a `&p` pattern is allowed on `&mut T`. This is RFC3627 rule 5.
62
77
pub allow_ref_pat_on_ref_mut : bool ,
63
78
/// Whether to simplify some expressions, which removes some borrow errors involving mixes of
@@ -249,15 +264,21 @@ pub const TY_BASED_OPTIONS_DOC: &[OptionsDoc] = &[
249
264
case has a mutability mismatch",
250
265
values : & [
251
266
OptionValue {
252
- name : "false " ,
267
+ name : "No " ,
253
268
doc : "Don't try matching on the outer reference if \
254
269
matching on the inner reference caused a mutability mismatch",
255
270
} ,
256
271
OptionValue {
257
- name : "true " ,
272
+ name : "EatOuter " ,
258
273
doc : "Try matching on the outer reference if \
259
274
matching on the inner reference caused a mutability mismatch",
260
275
} ,
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
+ } ,
261
282
] ,
262
283
} ,
263
284
OptionsDoc {
@@ -370,7 +391,7 @@ impl RuleOptions {
370
391
ref_binding_on_inherited : RefBindingOnInheritedBehavior :: ResetBindingMode ,
371
392
mut_binding_on_inherited : MutBindingOnInheritedBehavior :: ResetBindingMode ,
372
393
inherited_ref_on_ref : InheritedRefOnRefBehavior :: EatBoth ,
373
- fallback_to_outer : false ,
394
+ fallback_to_outer : FallbackToOuterBehavior :: No ,
374
395
allow_ref_pat_on_ref_mut : false ,
375
396
simplify_deref_mut : true ,
376
397
eat_inherited_ref_alone : false ,
@@ -384,7 +405,7 @@ impl RuleOptions {
384
405
ref_binding_on_inherited : RefBindingOnInheritedBehavior :: ResetBindingMode ,
385
406
mut_binding_on_inherited : MutBindingOnInheritedBehavior :: Error ,
386
407
inherited_ref_on_ref : InheritedRefOnRefBehavior :: EatInner ,
387
- fallback_to_outer : true ,
408
+ fallback_to_outer : FallbackToOuterBehavior :: EatOuter ,
388
409
allow_ref_pat_on_ref_mut : true ,
389
410
simplify_deref_mut : true ,
390
411
eat_inherited_ref_alone : true ,
@@ -399,7 +420,7 @@ impl RuleOptions {
399
420
ref_binding_on_inherited : RefBindingOnInheritedBehavior :: AllocTemporary ,
400
421
mut_binding_on_inherited : MutBindingOnInheritedBehavior :: Keep ,
401
422
inherited_ref_on_ref : InheritedRefOnRefBehavior :: EatOuter ,
402
- fallback_to_outer : false ,
423
+ fallback_to_outer : FallbackToOuterBehavior :: No ,
403
424
allow_ref_pat_on_ref_mut : true ,
404
425
simplify_deref_mut : true ,
405
426
eat_inherited_ref_alone : true ,
@@ -434,14 +455,14 @@ impl RuleOptions {
434
455
pub const RFC3627_2021 : Self = RuleOptions {
435
456
mut_binding_on_inherited : MutBindingOnInheritedBehavior :: ResetBindingMode ,
436
457
inherited_ref_on_ref : InheritedRefOnRefBehavior :: EatBoth ,
437
- fallback_to_outer : true ,
458
+ fallback_to_outer : FallbackToOuterBehavior :: EatOuter ,
438
459
..RuleOptions :: ERGO2024
439
460
} ;
440
461
441
462
pub const ERGO2024_BREAKING_ONLY : Self = RuleOptions {
442
463
mut_binding_on_inherited : MutBindingOnInheritedBehavior :: Error ,
443
464
inherited_ref_on_ref : InheritedRefOnRefBehavior :: EatInner ,
444
- fallback_to_outer : false ,
465
+ fallback_to_outer : FallbackToOuterBehavior :: No ,
445
466
..RuleOptions :: STABLE_RUST
446
467
} ;
447
468
0 commit comments