@@ -108,11 +108,7 @@ fn coerce_mutbls<'tcx>(
108
108
from_mutbl : hir:: Mutability ,
109
109
to_mutbl : hir:: Mutability ,
110
110
) -> RelateResult < ' tcx , ( ) > {
111
- match ( from_mutbl, to_mutbl) {
112
- ( hir:: Mutability :: Mut , hir:: Mutability :: Mut | hir:: Mutability :: Not )
113
- | ( hir:: Mutability :: Not , hir:: Mutability :: Not ) => Ok ( ( ) ) ,
114
- ( hir:: Mutability :: Not , hir:: Mutability :: Mut ) => Err ( TypeError :: Mutability ) ,
115
- }
111
+ if from_mutbl >= to_mutbl { Ok ( ( ) ) } else { Err ( TypeError :: Mutability ) }
116
112
}
117
113
118
114
/// Do not require any adjustments, i.e. coerce `x -> x`.
@@ -456,7 +452,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
456
452
return Err ( err) ;
457
453
} ;
458
454
459
- if ty == a && mt_a. mutbl == hir :: Mutability :: Not && autoderef. step_count ( ) == 1 {
455
+ if ty == a && mt_a. mutbl . is_not ( ) && autoderef. step_count ( ) == 1 {
460
456
// As a special case, if we would produce `&'a *x`, that's
461
457
// a total no-op. We end up with the type `&'a T` just as
462
458
// we started with. In that case, just skip it
@@ -468,7 +464,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
468
464
// `self.x` both have `&mut `type would be a move of
469
465
// `self.x`, but we auto-coerce it to `foo(&mut *self.x)`,
470
466
// which is a borrow.
471
- assert_eq ! ( mutbl_b, hir :: Mutability :: Not ) ; // can only coerce &T -> &U
467
+ assert ! ( mutbl_b. is_not ( ) ) ; // can only coerce &T -> &U
472
468
return success ( vec ! [ ] , ty, obligations) ;
473
469
}
474
470
@@ -482,12 +478,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
482
478
let ty:: Ref ( r_borrow, _, _) = ty. kind ( ) else {
483
479
span_bug ! ( span, "expected a ref type, got {:?}" , ty) ;
484
480
} ;
485
- let mutbl = match mutbl_b {
486
- hir:: Mutability :: Not => AutoBorrowMutability :: Not ,
487
- hir:: Mutability :: Mut => {
488
- AutoBorrowMutability :: Mut { allow_two_phase_borrow : self . allow_two_phase }
489
- }
490
- } ;
481
+ let mutbl = AutoBorrowMutability :: new ( mutbl_b, self . allow_two_phase ) ;
491
482
adjustments. push ( Adjustment {
492
483
kind : Adjust :: Borrow ( AutoBorrow :: Ref ( * r_borrow, mutbl) ) ,
493
484
target : ty,
@@ -556,15 +547,12 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
556
547
557
548
let coercion = Coercion ( self . cause . span ) ;
558
549
let r_borrow = self . next_region_var ( coercion) ;
559
- let mutbl = match mutbl_b {
560
- hir:: Mutability :: Not => AutoBorrowMutability :: Not ,
561
- hir:: Mutability :: Mut => AutoBorrowMutability :: Mut {
562
- // We don't allow two-phase borrows here, at least for initial
563
- // implementation. If it happens that this coercion is a function argument,
564
- // the reborrow in coerce_borrowed_ptr will pick it up.
565
- allow_two_phase_borrow : AllowTwoPhase :: No ,
566
- } ,
567
- } ;
550
+
551
+ // We don't allow two-phase borrows here, at least for initial
552
+ // implementation. If it happens that this coercion is a function argument,
553
+ // the reborrow in coerce_borrowed_ptr will pick it up.
554
+ let mutbl = AutoBorrowMutability :: new ( mutbl_b, AllowTwoPhase :: No ) ;
555
+
568
556
Some ( (
569
557
Adjustment { kind : Adjust :: Deref ( None ) , target : ty_a } ,
570
558
Adjustment {
0 commit comments