@@ -441,8 +441,41 @@ fn compare_asyncness<'tcx>(
441
441
Ok ( ( ) )
442
442
}
443
443
444
+ /// Given a method def-id in an impl, compare the method signature of the impl
445
+ /// against the trait that it's implementing. In doing so, infer the hidden types
446
+ /// that this method's signature provides to satisfy each return-position `impl Trait`
447
+ /// in the trait signature.
448
+ ///
449
+ /// The method is also responsible for making sure that the hidden types for each
450
+ /// RPITIT actually satisfy the bounds of the `impl Trait`, i.e. that if we infer
451
+ /// `impl Trait = Foo`, that `Foo: Trait` holds.
452
+ ///
453
+ /// For example, given the sample code:
454
+ ///
455
+ /// ```
456
+ /// #![feature(return_position_impl_trait_in_trait)]
457
+ ///
458
+ /// use std::ops::Deref;
459
+ ///
460
+ /// trait Foo {
461
+ /// fn bar() -> impl Deref<Target = impl Sized>;
462
+ /// // ^- RPITIT #1 ^- RPITIT #2
463
+ /// }
464
+ ///
465
+ /// impl Foo for () {
466
+ /// fn bar() -> Box<String> { Box::new(String::new()) }
467
+ /// }
468
+ /// ```
469
+ ///
470
+ /// The hidden types for the RPITITs in `bar` would be inferred to:
471
+ /// * `impl Deref` (RPITIT #1) = `Box<String>`
472
+ /// * `impl Sized` (RPITIT #2) = `String`
473
+ ///
474
+ /// The relationship between these two types is straightforward in this case, but
475
+ /// may be more tenuously connected via other `impl`s and normalization rules for
476
+ /// cases of more complicated nested RPITITs.
444
477
#[ instrument( skip( tcx) , level = "debug" , ret) ]
445
- pub ( super ) fn collect_trait_impl_trait_tys < ' tcx > (
478
+ pub ( super ) fn collect_return_position_impl_trait_in_trait_tys < ' tcx > (
446
479
tcx : TyCtxt < ' tcx > ,
447
480
def_id : DefId ,
448
481
) -> Result < & ' tcx FxHashMap < DefId , Ty < ' tcx > > , ErrorGuaranteed > {
0 commit comments