1
Fork 0

Rustfmt resolve_implementation.

This commit is contained in:
Camille GILLOT 2022-06-05 17:31:49 +02:00
parent 228def7e20
commit 80c6a1f275

View file

@ -2112,50 +2112,68 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
) { ) {
debug!("resolve_implementation"); debug!("resolve_implementation");
// If applicable, create a rib for the type parameters. // If applicable, create a rib for the type parameters.
self.with_generic_param_rib(&generics.params, ItemRibKind(HasGenericParams::Yes), LifetimeRibKind::Generics { span: generics.span, binder: item_id, kind: LifetimeBinderKind::ImplBlock }, |this| { self.with_generic_param_rib(
// Dummy self type for better errors if `Self` is used in the trait path. &generics.params,
this.with_self_rib(Res::SelfTy { trait_: None, alias_to: None }, |this| { ItemRibKind(HasGenericParams::Yes),
this.with_lifetime_rib(LifetimeRibKind::AnonymousCreateParameter(item_id), |this| { LifetimeRibKind::Generics {
// Resolve the trait reference, if necessary. span: generics.span,
this.with_optional_trait_ref(opt_trait_reference.as_ref(), self_type, |this, trait_id| { binder: item_id,
let item_def_id = this.r.local_def_id(item_id); kind: LifetimeBinderKind::ImplBlock
},
|this| {
// Dummy self type for better errors if `Self` is used in the trait path.
this.with_self_rib(Res::SelfTy { trait_: None, alias_to: None }, |this| {
this.with_lifetime_rib(
LifetimeRibKind::AnonymousCreateParameter(item_id),
|this| {
// Resolve the trait reference, if necessary.
this.with_optional_trait_ref(
opt_trait_reference.as_ref(),
self_type,
|this, trait_id| {
let item_def_id = this.r.local_def_id(item_id);
// Register the trait definitions from here. // Register the trait definitions from here.
if let Some(trait_id) = trait_id { if let Some(trait_id) = trait_id {
this.r.trait_impls.entry(trait_id).or_default().push(item_def_id); this.r.trait_impls.entry(trait_id).or_default().push(item_def_id);
} }
let item_def_id = item_def_id.to_def_id(); let item_def_id = item_def_id.to_def_id();
let res = let res = Res::SelfTy {
Res::SelfTy { trait_: trait_id, alias_to: Some((item_def_id, false)) }; trait_: trait_id,
this.with_self_rib(res, |this| { alias_to: Some((item_def_id, false)),
if let Some(trait_ref) = opt_trait_reference.as_ref() { };
// Resolve type arguments in the trait path. this.with_self_rib(res, |this| {
visit::walk_trait_ref(this, trait_ref); if let Some(trait_ref) = opt_trait_reference.as_ref() {
} // Resolve type arguments in the trait path.
// Resolve the self type. visit::walk_trait_ref(this, trait_ref);
this.visit_ty(self_type); }
// Resolve the generic parameters. // Resolve the self type.
this.visit_generics(generics); this.visit_ty(self_type);
// Resolve the generic parameters.
this.visit_generics(generics);
// Resolve the items within the impl. // Resolve the items within the impl.
this.with_lifetime_rib(LifetimeRibKind::AnonymousPassThrough(item_id,false), this.with_lifetime_rib(LifetimeRibKind::AnonymousPassThrough(item_id,false),
|this| { |this| {
this.with_current_self_type(self_type, |this| { this.with_current_self_type(self_type, |this| {
this.with_self_rib_ns(ValueNS, Res::SelfCtor(item_def_id), |this| { this.with_self_rib_ns(ValueNS, Res::SelfCtor(item_def_id), |this| {
debug!("resolve_implementation with_self_rib_ns(ValueNS, ...)"); debug!("resolve_implementation with_self_rib_ns(ValueNS, ...)");
for item in impl_items { for item in impl_items {
this.resolve_impl_item(&**item); this.resolve_impl_item(&**item);
} }
}); });
});
},
);
}); });
}, },
); );
}); },
}); );
}); });
}); },
}); );
} }
fn resolve_impl_item(&mut self, item: &'ast AssocItem) { fn resolve_impl_item(&mut self, item: &'ast AssocItem) {