File tree Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -954,7 +954,14 @@ fn iterate_method_candidates_with_autoref(
954954 )
955955 } ;
956956
957- iterate_method_candidates_by_receiver ( receiver_ty, first_adjustment. clone ( ) ) ?;
957+ let mut maybe_reborrowed = first_adjustment. clone ( ) ;
958+ if let Some ( ( _, _, m) ) = receiver_ty. value . as_reference ( ) {
959+ // Prefer reborrow of references to move
960+ maybe_reborrowed. autoref = Some ( m) ;
961+ maybe_reborrowed. autoderefs += 1 ;
962+ }
963+
964+ iterate_method_candidates_by_receiver ( receiver_ty, maybe_reborrowed) ?;
958965
959966 let refed = Canonical {
960967 value : TyKind :: Ref ( Mutability :: Not , static_lifetime ( ) , receiver_ty. value . clone ( ) )
Original file line number Diff line number Diff line change @@ -388,6 +388,24 @@ mod bar_test {
388388 ) ;
389389}
390390
391+ #[ test]
392+ fn infer_trait_method_multiple_mutable_reference ( ) {
393+ check_types (
394+ r#"
395+ trait Trait {
396+ fn method(&mut self) -> i32 { 5 }
397+ }
398+ struct S;
399+ impl Trait for &mut &mut S {}
400+ fn test() {
401+ let s = &mut &mut &mut S;
402+ s.method();
403+ //^^^^^^^^^^ i32
404+ }
405+ "# ,
406+ ) ;
407+ }
408+
391409#[ test]
392410fn infer_trait_method_generic_1 ( ) {
393411 // the trait implementation is intentionally incomplete -- it shouldn't matter
@@ -1722,7 +1740,7 @@ fn test() {
17221740 Foo.foo();
17231741 //^^^ adjustments: Borrow(Ref(Not))
17241742 (&Foo).foo();
1725- // ^^^^ adjustments: ,
1743+ // ^^^^ adjustments: Deref(None), Borrow(Ref(Not))
17261744}
17271745"# ,
17281746 ) ;
Original file line number Diff line number Diff line change @@ -315,13 +315,17 @@ fn main() {
315315 (&Struct).consume();
316316 //^^^^^^^*
317317 (&Struct).by_ref();
318+ //^^^^^^^&
319+ //^^^^^^^*
318320
319321 (&mut Struct).consume();
320322 //^^^^^^^^^^^*
321323 (&mut Struct).by_ref();
322324 //^^^^^^^^^^^&
323325 //^^^^^^^^^^^*
324326 (&mut Struct).by_ref_mut();
327+ //^^^^^^^^^^^&mut $
328+ //^^^^^^^^^^^*
325329
326330 // Check that block-like expressions don't duplicate hints
327331 let _: &mut [u32] = (&mut []);
@@ -414,6 +418,10 @@ fn main() {
414418 //^^^^^^^)
415419 //^^^^^^^.*
416420 (&Struct).by_ref();
421+ //^^^^^^^(
422+ //^^^^^^^)
423+ //^^^^^^^.*
424+ //^^^^^^^.&
417425
418426 (&mut Struct).consume();
419427 //^^^^^^^^^^^(
@@ -425,6 +433,10 @@ fn main() {
425433 //^^^^^^^^^^^.*
426434 //^^^^^^^^^^^.&
427435 (&mut Struct).by_ref_mut();
436+ //^^^^^^^^^^^(
437+ //^^^^^^^^^^^)
438+ //^^^^^^^^^^^.*
439+ //^^^^^^^^^^^.&mut
428440
429441 // Check that block-like expressions don't duplicate hints
430442 let _: &mut [u32] = (&mut []);
You can’t perform that action at this time.
0 commit comments