mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-21 17:52:12 +03:00
Split trait item resolving into its own method
This commit is contained in:
@@ -3321,6 +3321,14 @@ fn resolve_trait_items(&mut self, trait_items: &'ast [Box<AssocItem>]) {
|
||||
let trait_assoc_items =
|
||||
replace(&mut self.diag_metadata.current_trait_assoc_items, Some(trait_items));
|
||||
|
||||
for item in trait_items {
|
||||
self.resolve_trait_item(item);
|
||||
}
|
||||
|
||||
self.diag_metadata.current_trait_assoc_items = trait_assoc_items;
|
||||
}
|
||||
|
||||
fn resolve_trait_item(&mut self, item: &'ast Item<AssocItemKind>) {
|
||||
let walk_assoc_item =
|
||||
|this: &mut Self, generics: &Generics, kind, item: &'ast AssocItem| {
|
||||
this.with_generic_param_rib(
|
||||
@@ -3333,87 +3341,79 @@ fn resolve_trait_items(&mut self, trait_items: &'ast [Box<AssocItem>]) {
|
||||
);
|
||||
};
|
||||
|
||||
for item in trait_items {
|
||||
self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
|
||||
match &item.kind {
|
||||
AssocItemKind::Const(ast::ConstItem {
|
||||
generics,
|
||||
ty,
|
||||
rhs_kind,
|
||||
define_opaque,
|
||||
..
|
||||
}) => {
|
||||
self.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::AssocItem,
|
||||
item.id,
|
||||
LifetimeBinderKind::ConstItem,
|
||||
generics.span,
|
||||
|this| {
|
||||
this.with_lifetime_rib(
|
||||
LifetimeRibKind::StaticIfNoLifetimeInScope {
|
||||
lint_id: item.id,
|
||||
emit_lint: false,
|
||||
},
|
||||
|this| {
|
||||
this.visit_generics(generics);
|
||||
if rhs_kind.is_type_const()
|
||||
&& !this.r.tcx.features().generic_const_parameter_types()
|
||||
{
|
||||
this.with_rib(TypeNS, RibKind::ConstParamTy, |this| {
|
||||
this.with_rib(ValueNS, RibKind::ConstParamTy, |this| {
|
||||
this.with_lifetime_rib(
|
||||
LifetimeRibKind::ConstParamTy,
|
||||
|this| this.visit_ty(ty),
|
||||
)
|
||||
})
|
||||
});
|
||||
} else {
|
||||
this.visit_ty(ty);
|
||||
}
|
||||
self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
|
||||
match &item.kind {
|
||||
AssocItemKind::Const(ast::ConstItem {
|
||||
generics, ty, rhs_kind, define_opaque, ..
|
||||
}) => {
|
||||
self.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::AssocItem,
|
||||
item.id,
|
||||
LifetimeBinderKind::ConstItem,
|
||||
generics.span,
|
||||
|this| {
|
||||
this.with_lifetime_rib(
|
||||
LifetimeRibKind::StaticIfNoLifetimeInScope {
|
||||
lint_id: item.id,
|
||||
emit_lint: false,
|
||||
},
|
||||
|this| {
|
||||
this.visit_generics(generics);
|
||||
if rhs_kind.is_type_const()
|
||||
&& !this.r.tcx.features().generic_const_parameter_types()
|
||||
{
|
||||
this.with_rib(TypeNS, RibKind::ConstParamTy, |this| {
|
||||
this.with_rib(ValueNS, RibKind::ConstParamTy, |this| {
|
||||
this.with_lifetime_rib(
|
||||
LifetimeRibKind::ConstParamTy,
|
||||
|this| this.visit_ty(ty),
|
||||
)
|
||||
})
|
||||
});
|
||||
} else {
|
||||
this.visit_ty(ty);
|
||||
}
|
||||
|
||||
// Only impose the restrictions of `ConstRibKind` for an
|
||||
// actual constant expression in a provided default.
|
||||
//
|
||||
// We allow arbitrary const expressions inside of associated consts,
|
||||
// even if they are potentially not const evaluatable.
|
||||
//
|
||||
// Type parameters can already be used and as associated consts are
|
||||
// not used as part of the type system, this is far less surprising.
|
||||
this.resolve_const_item_rhs(rhs_kind, None);
|
||||
},
|
||||
)
|
||||
},
|
||||
);
|
||||
// Only impose the restrictions of `ConstRibKind` for an
|
||||
// actual constant expression in a provided default.
|
||||
//
|
||||
// We allow arbitrary const expressions inside of associated consts,
|
||||
// even if they are potentially not const evaluatable.
|
||||
//
|
||||
// Type parameters can already be used and as associated consts are
|
||||
// not used as part of the type system, this is far less surprising.
|
||||
this.resolve_const_item_rhs(rhs_kind, None);
|
||||
},
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
self.resolve_define_opaques(define_opaque);
|
||||
}
|
||||
AssocItemKind::Fn(Fn { generics, define_opaque, .. }) => {
|
||||
walk_assoc_item(self, generics, LifetimeBinderKind::Function, item);
|
||||
self.resolve_define_opaques(define_opaque);
|
||||
}
|
||||
AssocItemKind::Fn(Fn { generics, define_opaque, .. }) => {
|
||||
walk_assoc_item(self, generics, LifetimeBinderKind::Function, item);
|
||||
|
||||
self.resolve_define_opaques(define_opaque);
|
||||
}
|
||||
AssocItemKind::Delegation(delegation) => {
|
||||
self.with_generic_param_rib(
|
||||
&[],
|
||||
RibKind::AssocItem,
|
||||
item.id,
|
||||
LifetimeBinderKind::Function,
|
||||
delegation.path.segments.last().unwrap().ident.span,
|
||||
|this| this.resolve_delegation(delegation, item.id, false),
|
||||
);
|
||||
}
|
||||
AssocItemKind::Type(TyAlias { generics, .. }) => self
|
||||
.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
|
||||
walk_assoc_item(this, generics, LifetimeBinderKind::Item, item)
|
||||
}),
|
||||
AssocItemKind::MacCall(_) | AssocItemKind::DelegationMac(..) => {
|
||||
panic!("unexpanded macro in resolve!")
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
self.diag_metadata.current_trait_assoc_items = trait_assoc_items;
|
||||
self.resolve_define_opaques(define_opaque);
|
||||
}
|
||||
AssocItemKind::Delegation(delegation) => {
|
||||
self.with_generic_param_rib(
|
||||
&[],
|
||||
RibKind::AssocItem,
|
||||
item.id,
|
||||
LifetimeBinderKind::Function,
|
||||
delegation.path.segments.last().unwrap().ident.span,
|
||||
|this| this.resolve_delegation(delegation, item.id, false),
|
||||
);
|
||||
}
|
||||
AssocItemKind::Type(TyAlias { generics, .. }) => self
|
||||
.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
|
||||
walk_assoc_item(this, generics, LifetimeBinderKind::Item, item)
|
||||
}),
|
||||
AssocItemKind::MacCall(_) | AssocItemKind::DelegationMac(..) => {
|
||||
panic!("unexpanded macro in resolve!")
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// This is called to resolve a trait reference from an `impl` (i.e., `impl Trait for Foo`).
|
||||
|
||||
Reference in New Issue
Block a user