better names and a comment
This commit is contained in:
parent
c7b414adb6
commit
96d8011fa8
7 changed files with 42 additions and 9 deletions
|
@ -441,8 +441,41 @@ fn compare_asyncness<'tcx>(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Given a method def-id in an impl, compare the method signature of the impl
|
||||
/// against the trait that it's implementing. In doing so, infer the hidden types
|
||||
/// that this method's signature provides to satisfy each return-position `impl Trait`
|
||||
/// in the trait signature.
|
||||
///
|
||||
/// The method is also responsible for making sure that the hidden types for each
|
||||
/// RPITIT actually satisfy the bounds of the `impl Trait`, i.e. that if we infer
|
||||
/// `impl Trait = Foo`, that `Foo: Trait` holds.
|
||||
///
|
||||
/// For example, given the sample code:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(return_position_impl_trait_in_trait)]
|
||||
///
|
||||
/// use std::ops::Deref;
|
||||
///
|
||||
/// trait Foo {
|
||||
/// fn bar() -> impl Deref<Target = impl Sized>;
|
||||
/// // ^- RPITIT #1 ^- RPITIT #2
|
||||
/// }
|
||||
///
|
||||
/// impl Foo for () {
|
||||
/// fn bar() -> Box<String> { Box::new(String::new()) }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// The hidden types for the RPITITs in `bar` would be inferred to:
|
||||
/// * `impl Deref` (RPITIT #1) = `Box<String>`
|
||||
/// * `impl Sized` (RPITIT #2) = `String`
|
||||
///
|
||||
/// The relationship between these two types is straightforward in this case, but
|
||||
/// may be more tenuously connected via other `impl`s and normalization rules for
|
||||
/// cases of more complicated nested RPITITs.
|
||||
#[instrument(skip(tcx), level = "debug", ret)]
|
||||
pub(super) fn collect_trait_impl_trait_tys<'tcx>(
|
||||
pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: DefId,
|
||||
) -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed> {
|
||||
|
|
|
@ -94,7 +94,7 @@ use std::num::NonZeroU32;
|
|||
use crate::require_c_abi_if_c_variadic;
|
||||
use crate::util::common::indenter;
|
||||
|
||||
use self::compare_impl_item::collect_trait_impl_trait_tys;
|
||||
use self::compare_impl_item::collect_return_position_impl_trait_in_trait_tys;
|
||||
use self::region::region_scope_tree;
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
|
@ -103,7 +103,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
adt_destructor,
|
||||
check_mod_item_types,
|
||||
region_scope_tree,
|
||||
collect_trait_impl_trait_tys,
|
||||
collect_return_position_impl_trait_in_trait_tys,
|
||||
compare_impl_const: compare_impl_item::compare_impl_const_raw,
|
||||
..*providers
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue