@@ -13,7 +13,7 @@ use crate::middle::resolve_lifetime as rl;
1313use crate :: namespace:: Namespace ;
1414use rustc:: lint:: builtin:: AMBIGUOUS_ASSOCIATED_ITEMS ;
1515use rustc:: traits;
16- use rustc:: ty:: { self , DefIdTree , Ty , TyCtxt , ToPredicate , TypeFoldable } ;
16+ use rustc:: ty:: { self , DefIdTree , Ty , TyCtxt , Const , ToPredicate , TypeFoldable } ;
1717use rustc:: ty:: { GenericParamDef , GenericParamDefKind } ;
1818use rustc:: ty:: subst:: { Kind , Subst , InternalSubsts , SubstsRef } ;
1919use rustc:: ty:: wf:: object_region_bounds;
@@ -61,6 +61,13 @@ pub trait AstConv<'gcx, 'tcx> {
6161 span : Span ) -> Ty < ' tcx > {
6262 self . ty_infer ( span)
6363 }
64+ /// What const should we use when a const is omitted?
65+ fn ct_infer (
66+ & self ,
67+ ty : Ty < ' tcx > ,
68+ param : Option < & ty:: GenericParamDef > ,
69+ span : Span ,
70+ ) -> & ' tcx Const < ' tcx > ;
6471
6572 /// Projecting an associated type from a (potentially)
6673 /// higher-ranked trait reference is more complicated, because of
@@ -280,7 +287,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
280287 let param_counts = def. own_counts ( ) ;
281288 let arg_counts = args. own_counts ( ) ;
282289 let infer_lifetimes = position != GenericArgPosition :: Type && arg_counts. lifetimes == 0 ;
283- let infer_consts = position != GenericArgPosition :: Type && arg_counts. consts == 0 ;
284290
285291 let mut defaults: ty:: GenericParamCount = Default :: default ( ) ;
286292 for param in & def. params {
@@ -333,7 +339,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
333339 offset
334340 ) ;
335341 // We enforce the following: `required` <= `provided` <= `permitted`.
336- // For kinds without defaults (i.e ., lifetimes), `required == permitted`.
342+ // For kinds without defaults (e.g. ., lifetimes), `required == permitted`.
337343 // For other kinds (i.e., types), `permitted` may be greater than `required`.
338344 if required <= provided && provided <= permitted {
339345 return ( reported_late_bound_region_err. unwrap_or ( false ) , None ) ;
@@ -404,7 +410,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
404410 ) ;
405411 }
406412 // FIXME(const_generics:defaults)
407- if !infer_consts || arg_counts. consts > param_counts. consts {
413+ if !infer_args || arg_counts. consts > param_counts. consts {
408414 check_kind_count (
409415 "const" ,
410416 param_counts. consts ,
@@ -707,8 +713,14 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
707713 }
708714 GenericParamDefKind :: Const => {
709715 // FIXME(const_generics:defaults)
710- // We've already errored above about the mismatch.
711- tcx. consts . err . into ( )
716+ if infer_args {
717+ // No const parameters were provided, we can infer all.
718+ let ty = tcx. at ( span) . type_of ( param. def_id ) ;
719+ self . ct_infer ( ty, Some ( param) , span) . into ( )
720+ } else {
721+ // We've already errored above about the mismatch.
722+ tcx. consts . err . into ( )
723+ }
712724 }
713725 }
714726 } ,
0 commit comments