@@ -3763,21 +3763,34 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
37633763 & ' a [ ast:: PathSegment ] ,
37643764 def:: Def ) >
37653765{
3766+
3767+ // Associated constants can't depend on generic types.
3768+ fn have_disallowed_generic_consts < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
3769+ def : def:: Def ,
3770+ ty : Ty < ' tcx > ,
3771+ span : Span ,
3772+ node_id : ast:: NodeId ) -> bool {
3773+ match def {
3774+ def:: DefAssociatedConst ( ..) => {
3775+ if ty:: type_has_params ( ty) || ty:: type_has_self ( ty) {
3776+ fcx. sess ( ) . span_err ( span,
3777+ "Associated consts cannot depend \
3778+ on type parameters or Self.") ;
3779+ fcx. write_error ( node_id) ;
3780+ return true ;
3781+ }
3782+ }
3783+ _ => { }
3784+ }
3785+ false
3786+ }
3787+
37663788 // If fully resolved already, we don't have to do anything.
37673789 if path_res. depth == 0 {
3768- // Associated constants can't depend on generic types.
37693790 if let Some ( ty) = opt_self_ty {
3770- match path_res. full_def ( ) {
3771- def:: DefAssociatedConst ( ..) => {
3772- if ty:: type_has_params ( ty) || ty:: type_has_self ( ty) {
3773- fcx. sess ( ) . span_err ( span,
3774- "Associated consts cannot depend \
3775- on type parameters or Self.") ;
3776- fcx. write_error ( node_id) ;
3777- return None ;
3778- }
3779- }
3780- _ => { }
3791+ if have_disallowed_generic_consts ( fcx, path_res. full_def ( ) , ty,
3792+ span, node_id) {
3793+ return None ;
37813794 }
37823795 }
37833796 Some ( ( opt_self_ty, & path. segments , path_res. base_def ) )
@@ -3795,18 +3808,8 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
37953808 let item_name = item_segment. identifier . name ;
37963809 match method:: resolve_ufcs ( fcx, span, item_name, ty, node_id) {
37973810 Ok ( ( def, lp) ) => {
3798- // Associated constants can't depend on generic types.
3799- match def {
3800- def:: DefAssociatedConst ( ..) => {
3801- if ty:: type_has_params ( ty) || ty:: type_has_self ( ty) {
3802- fcx. sess ( ) . span_err ( span,
3803- "Associated consts cannot depend \
3804- on type parameters or Self.") ;
3805- fcx. write_error ( node_id) ;
3806- return None ;
3807- }
3808- }
3809- _ => { }
3811+ if have_disallowed_generic_consts ( fcx, def, ty, span, node_id) {
3812+ return None ;
38103813 }
38113814 // Write back the new resolution.
38123815 fcx. ccx . tcx . def_map . borrow_mut ( )
0 commit comments