Skip to content

Commit b9632cd

Browse files
committed
Split trait item resolving into its own method
1 parent 9d018fb commit b9632cd

File tree

1 file changed

+70
-71
lines changed

1 file changed

+70
-71
lines changed

compiler/rustc_resolve/src/late.rs

+70-71
Original file line numberDiff line numberDiff line change
@@ -3097,6 +3097,14 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
30973097
let trait_assoc_items =
30983098
replace(&mut self.diag_metadata.current_trait_assoc_items, Some(trait_items));
30993099

3100+
for item in trait_items {
3101+
self.resolve_trait_item(item);
3102+
}
3103+
3104+
self.diag_metadata.current_trait_assoc_items = trait_assoc_items;
3105+
}
3106+
3107+
fn resolve_trait_item(&mut self, item: &'ast P<Item<AssocItemKind>>) {
31003108
let walk_assoc_item =
31013109
|this: &mut Self, generics: &Generics, kind, item: &'ast AssocItem| {
31023110
this.with_generic_param_rib(
@@ -3106,80 +3114,71 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
31063114
|this| visit::walk_assoc_item(this, item, AssocCtxt::Trait),
31073115
);
31083116
};
3117+
self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
3118+
match &item.kind {
3119+
AssocItemKind::Const(box ast::ConstItem {
3120+
generics, ty, expr, define_opaque, ..
3121+
}) => {
3122+
self.with_generic_param_rib(
3123+
&generics.params,
3124+
RibKind::AssocItem,
3125+
LifetimeRibKind::Generics {
3126+
binder: item.id,
3127+
span: generics.span,
3128+
kind: LifetimeBinderKind::ConstItem,
3129+
},
3130+
|this| {
3131+
this.with_lifetime_rib(
3132+
LifetimeRibKind::StaticIfNoLifetimeInScope {
3133+
lint_id: item.id,
3134+
emit_lint: false,
3135+
},
3136+
|this| {
3137+
this.visit_generics(generics);
3138+
this.visit_ty(ty);
3139+
3140+
// Only impose the restrictions of `ConstRibKind` for an
3141+
// actual constant expression in a provided default.
3142+
if let Some(expr) = expr {
3143+
// We allow arbitrary const expressions inside of associated consts,
3144+
// even if they are potentially not const evaluatable.
3145+
//
3146+
// Type parameters can already be used and as associated consts are
3147+
// not used as part of the type system, this is far less surprising.
3148+
this.resolve_const_body(expr, None);
3149+
}
3150+
},
3151+
)
3152+
},
3153+
);
31093154

3110-
for item in trait_items {
3111-
self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
3112-
match &item.kind {
3113-
AssocItemKind::Const(box ast::ConstItem {
3114-
generics,
3115-
ty,
3116-
expr,
3117-
define_opaque,
3118-
..
3119-
}) => {
3120-
self.with_generic_param_rib(
3121-
&generics.params,
3122-
RibKind::AssocItem,
3123-
LifetimeRibKind::Generics {
3124-
binder: item.id,
3125-
span: generics.span,
3126-
kind: LifetimeBinderKind::ConstItem,
3127-
},
3128-
|this| {
3129-
this.with_lifetime_rib(
3130-
LifetimeRibKind::StaticIfNoLifetimeInScope {
3131-
lint_id: item.id,
3132-
emit_lint: false,
3133-
},
3134-
|this| {
3135-
this.visit_generics(generics);
3136-
this.visit_ty(ty);
3137-
3138-
// Only impose the restrictions of `ConstRibKind` for an
3139-
// actual constant expression in a provided default.
3140-
if let Some(expr) = expr {
3141-
// We allow arbitrary const expressions inside of associated consts,
3142-
// even if they are potentially not const evaluatable.
3143-
//
3144-
// Type parameters can already be used and as associated consts are
3145-
// not used as part of the type system, this is far less surprising.
3146-
this.resolve_const_body(expr, None);
3147-
}
3148-
},
3149-
)
3150-
},
3151-
);
3152-
3153-
self.resolve_define_opaques(define_opaque);
3154-
}
3155-
AssocItemKind::Fn(box Fn { generics, define_opaque, .. }) => {
3156-
walk_assoc_item(self, generics, LifetimeBinderKind::Function, item);
3155+
self.resolve_define_opaques(define_opaque);
3156+
}
3157+
AssocItemKind::Fn(box Fn { generics, define_opaque, .. }) => {
3158+
walk_assoc_item(self, generics, LifetimeBinderKind::Function, item);
31573159

3158-
self.resolve_define_opaques(define_opaque);
3159-
}
3160-
AssocItemKind::Delegation(delegation) => {
3161-
self.with_generic_param_rib(
3162-
&[],
3163-
RibKind::AssocItem,
3164-
LifetimeRibKind::Generics {
3165-
binder: item.id,
3166-
kind: LifetimeBinderKind::Function,
3167-
span: delegation.path.segments.last().unwrap().ident.span,
3168-
},
3169-
|this| this.resolve_delegation(delegation),
3170-
);
3171-
}
3172-
AssocItemKind::Type(box TyAlias { generics, .. }) => self
3173-
.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
3174-
walk_assoc_item(this, generics, LifetimeBinderKind::Item, item)
3175-
}),
3176-
AssocItemKind::MacCall(_) | AssocItemKind::DelegationMac(..) => {
3177-
panic!("unexpanded macro in resolve!")
3178-
}
3179-
};
3160+
self.resolve_define_opaques(define_opaque);
3161+
}
3162+
AssocItemKind::Delegation(delegation) => {
3163+
self.with_generic_param_rib(
3164+
&[],
3165+
RibKind::AssocItem,
3166+
LifetimeRibKind::Generics {
3167+
binder: item.id,
3168+
kind: LifetimeBinderKind::Function,
3169+
span: delegation.path.segments.last().unwrap().ident.span,
3170+
},
3171+
|this| this.resolve_delegation(delegation),
3172+
);
3173+
}
3174+
AssocItemKind::Type(box TyAlias { generics, .. }) => self
3175+
.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
3176+
walk_assoc_item(this, generics, LifetimeBinderKind::Item, item)
3177+
}),
3178+
AssocItemKind::MacCall(_) | AssocItemKind::DelegationMac(..) => {
3179+
panic!("unexpanded macro in resolve!")
3180+
}
31803181
}
3181-
3182-
self.diag_metadata.current_trait_assoc_items = trait_assoc_items;
31833182
}
31843183

31853184
/// This is called to resolve a trait reference from an `impl` (i.e., `impl Trait for Foo`).

0 commit comments

Comments
 (0)