File tree 3 files changed +39
-2
lines changed
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(
954
954
)
955
955
} ;
956
956
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) ?;
958
965
959
966
let refed = Canonical {
960
967
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 {
388
388
) ;
389
389
}
390
390
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
+
391
409
#[ test]
392
410
fn infer_trait_method_generic_1 ( ) {
393
411
// the trait implementation is intentionally incomplete -- it shouldn't matter
@@ -1722,7 +1740,7 @@ fn test() {
1722
1740
Foo.foo();
1723
1741
//^^^ adjustments: Borrow(Ref(Not))
1724
1742
(&Foo).foo();
1725
- // ^^^^ adjustments: ,
1743
+ // ^^^^ adjustments: Deref(None), Borrow(Ref(Not))
1726
1744
}
1727
1745
"# ,
1728
1746
) ;
Original file line number Diff line number Diff line change @@ -315,13 +315,17 @@ fn main() {
315
315
(&Struct).consume();
316
316
//^^^^^^^*
317
317
(&Struct).by_ref();
318
+ //^^^^^^^&
319
+ //^^^^^^^*
318
320
319
321
(&mut Struct).consume();
320
322
//^^^^^^^^^^^*
321
323
(&mut Struct).by_ref();
322
324
//^^^^^^^^^^^&
323
325
//^^^^^^^^^^^*
324
326
(&mut Struct).by_ref_mut();
327
+ //^^^^^^^^^^^&mut $
328
+ //^^^^^^^^^^^*
325
329
326
330
// Check that block-like expressions don't duplicate hints
327
331
let _: &mut [u32] = (&mut []);
@@ -414,6 +418,10 @@ fn main() {
414
418
//^^^^^^^)
415
419
//^^^^^^^.*
416
420
(&Struct).by_ref();
421
+ //^^^^^^^(
422
+ //^^^^^^^)
423
+ //^^^^^^^.*
424
+ //^^^^^^^.&
417
425
418
426
(&mut Struct).consume();
419
427
//^^^^^^^^^^^(
@@ -425,6 +433,10 @@ fn main() {
425
433
//^^^^^^^^^^^.*
426
434
//^^^^^^^^^^^.&
427
435
(&mut Struct).by_ref_mut();
436
+ //^^^^^^^^^^^(
437
+ //^^^^^^^^^^^)
438
+ //^^^^^^^^^^^.*
439
+ //^^^^^^^^^^^.&mut
428
440
429
441
// Check that block-like expressions don't duplicate hints
430
442
let _: &mut [u32] = (&mut []);
You can’t perform that action at this time.
0 commit comments