@@ -495,7 +495,7 @@ impl LenOutput {
495495fn expected_is_empty_sig ( len_output : LenOutput , len_self_kind : ImplicitSelfKind ) -> String {
496496 let self_ref = match len_self_kind {
497497 ImplicitSelfKind :: RefImm => "&" ,
498- ImplicitSelfKind :: RefMut => "&mut " ,
498+ ImplicitSelfKind :: RefMut => "&( mut) " ,
499499 _ => "" ,
500500 } ;
501501 match len_output {
@@ -520,8 +520,12 @@ fn check_is_empty_sig<'tcx>(
520520 && len_output. matches_is_empty_output ( cx, * is_empty_output)
521521 {
522522 match ( is_empty_self_arg. kind ( ) , len_self_kind) {
523+ // if `len` takes `&self`, `is_empty` should do so as well
523524 ( ty:: Ref ( _, _, Mutability :: Not ) , ImplicitSelfKind :: RefImm )
524- | ( ty:: Ref ( _, _, Mutability :: Mut ) , ImplicitSelfKind :: RefMut ) => true ,
525+ // if `len` takes `&mut self`, `is_empty` may take that _or_ `&self` (#16190)
526+ | ( ty:: Ref ( _, _, Mutability :: Mut | Mutability :: Not ) , ImplicitSelfKind :: RefMut ) => true ,
527+ // if len takes `self`, `is_empty` should do so as well
528+ // XXX: we might want to relax this to allow `&self` and `&mut self`
525529 ( _, ImplicitSelfKind :: Imm | ImplicitSelfKind :: Mut ) if !is_empty_self_arg. is_ref ( ) => true ,
526530 _ => false ,
527531 }
0 commit comments