@@ -63,8 +63,23 @@ struct ConstToPat<'a, 'tcx> {
63
63
include_lint_checks : bool ,
64
64
}
65
65
66
- #[ derive( Debug ) ]
67
- struct FallbackToConstRef ;
66
+ mod fallback_to_const_ref {
67
+ #[ derive( Debug ) ]
68
+ /// This error type signals that we encountered a non-struct-eq situation behind a reference.
69
+ /// We bubble this up in order to get back to the reference destructuring and make that emit
70
+ /// a const pattern instead of a deref pattern. This allows us to simply call `PartialEq::eq`
71
+ /// on such patterns (since that function takes a reference) and not have to jump through any
72
+ /// hoops to get a reference to the value.
73
+ pub ( super ) struct FallbackToConstRef ( ( ) ) ;
74
+
75
+ pub ( super ) fn fallback_to_const_ref < ' a , ' tcx > (
76
+ c2p : & super :: ConstToPat < ' a , ' tcx > ,
77
+ ) -> FallbackToConstRef {
78
+ assert ! ( c2p. behind_reference. get( ) ) ;
79
+ FallbackToConstRef ( ( ) )
80
+ }
81
+ }
82
+ use fallback_to_const_ref:: { fallback_to_const_ref, FallbackToConstRef } ;
68
83
69
84
impl < ' a , ' tcx > ConstToPat < ' a , ' tcx > {
70
85
fn new (
@@ -314,7 +329,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
314
329
// Since we are behind a reference, we can just bubble the error up so we get a
315
330
// constant at reference type, making it easy to let the fallback call
316
331
// `PartialEq::eq` on it.
317
- return Err ( FallbackToConstRef ) ;
332
+ return Err ( fallback_to_const_ref ( self ) ) ;
318
333
}
319
334
ty:: Adt ( adt_def, _) if !self . type_marked_structural ( cv. ty ) => {
320
335
debug ! ( "adt_def {:?} has !type_marked_structural for cv.ty: {:?}" , adt_def, cv. ty) ;
@@ -447,7 +462,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
447
462
// very hard to invoke `PartialEq::eq` on it as a fallback.
448
463
let val = match self . recur ( tcx. deref_const ( self . param_env . and ( cv) ) , false ) {
449
464
Ok ( subpattern) => PatKind :: Deref { subpattern } ,
450
- Err ( FallbackToConstRef ) => PatKind :: Constant { value : cv } ,
465
+ Err ( _ ) => PatKind :: Constant { value : cv } ,
451
466
} ;
452
467
self . behind_reference . set ( old) ;
453
468
val
0 commit comments