@@ -3713,21 +3713,34 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
3713
3713
& ' a [ ast:: PathSegment ] ,
3714
3714
def:: Def ) >
3715
3715
{
3716
+
3717
+ // Associated constants can't depend on generic types.
3718
+ fn have_disallowed_generic_consts < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
3719
+ def : def:: Def ,
3720
+ ty : Ty < ' tcx > ,
3721
+ span : Span ,
3722
+ node_id : ast:: NodeId ) -> bool {
3723
+ match def {
3724
+ def:: DefAssociatedConst ( ..) => {
3725
+ if ty:: type_has_params ( ty) || ty:: type_has_self ( ty) {
3726
+ fcx. sess ( ) . span_err ( span,
3727
+ "Associated consts cannot depend \
3728
+ on type parameters or Self.") ;
3729
+ fcx. write_error ( node_id) ;
3730
+ return true ;
3731
+ }
3732
+ }
3733
+ _ => { }
3734
+ }
3735
+ false
3736
+ }
3737
+
3716
3738
// If fully resolved already, we don't have to do anything.
3717
3739
if path_res. depth == 0 {
3718
- // Associated constants can't depend on generic types.
3719
3740
if let Some ( ty) = opt_self_ty {
3720
- match path_res. full_def ( ) {
3721
- def:: DefAssociatedConst ( ..) => {
3722
- if ty:: type_has_params ( ty) || ty:: type_has_self ( ty) {
3723
- fcx. sess ( ) . span_err ( span,
3724
- "Associated consts cannot depend \
3725
- on type parameters or Self.") ;
3726
- fcx. write_error ( node_id) ;
3727
- return None ;
3728
- }
3729
- }
3730
- _ => { }
3741
+ if have_disallowed_generic_consts ( fcx, path_res. full_def ( ) , ty,
3742
+ span, node_id) {
3743
+ return None ;
3731
3744
}
3732
3745
}
3733
3746
Some ( ( opt_self_ty, & path. segments , path_res. base_def ) )
@@ -3745,18 +3758,8 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
3745
3758
let item_name = item_segment. identifier . name ;
3746
3759
match method:: resolve_ufcs ( fcx, span, item_name, ty, node_id) {
3747
3760
Ok ( ( def, lp) ) => {
3748
- // Associated constants can't depend on generic types.
3749
- match def {
3750
- def:: DefAssociatedConst ( ..) => {
3751
- if ty:: type_has_params ( ty) || ty:: type_has_self ( ty) {
3752
- fcx. sess ( ) . span_err ( span,
3753
- "Associated consts cannot depend \
3754
- on type parameters or Self.") ;
3755
- fcx. write_error ( node_id) ;
3756
- return None ;
3757
- }
3758
- }
3759
- _ => { }
3761
+ if have_disallowed_generic_consts ( fcx, def, ty, span, node_id) {
3762
+ return None ;
3760
3763
}
3761
3764
// Write back the new resolution.
3762
3765
fcx. ccx . tcx . def_map . borrow_mut ( )
0 commit comments