@@ -13,7 +13,7 @@ use crate::middle::resolve_lifetime as rl;
13
13
use crate :: namespace:: Namespace ;
14
14
use rustc:: lint:: builtin:: AMBIGUOUS_ASSOCIATED_ITEMS ;
15
15
use rustc:: traits;
16
- use rustc:: ty:: { self , DefIdTree , Ty , TyCtxt , ToPredicate , TypeFoldable } ;
16
+ use rustc:: ty:: { self , DefIdTree , Ty , TyCtxt , Const , ToPredicate , TypeFoldable } ;
17
17
use rustc:: ty:: { GenericParamDef , GenericParamDefKind } ;
18
18
use rustc:: ty:: subst:: { Kind , Subst , InternalSubsts , SubstsRef } ;
19
19
use rustc:: ty:: wf:: object_region_bounds;
@@ -61,6 +61,13 @@ pub trait AstConv<'gcx, 'tcx> {
61
61
span : Span ) -> Ty < ' tcx > {
62
62
self . ty_infer ( span)
63
63
}
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 > ;
64
71
65
72
/// Projecting an associated type from a (potentially)
66
73
/// higher-ranked trait reference is more complicated, because of
@@ -280,7 +287,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
280
287
let param_counts = def. own_counts ( ) ;
281
288
let arg_counts = args. own_counts ( ) ;
282
289
let infer_lifetimes = position != GenericArgPosition :: Type && arg_counts. lifetimes == 0 ;
283
- let infer_consts = position != GenericArgPosition :: Type && arg_counts. consts == 0 ;
284
290
285
291
let mut defaults: ty:: GenericParamCount = Default :: default ( ) ;
286
292
for param in & def. params {
@@ -333,7 +339,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
333
339
offset
334
340
) ;
335
341
// 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`.
337
343
// For other kinds (i.e., types), `permitted` may be greater than `required`.
338
344
if required <= provided && provided <= permitted {
339
345
return ( reported_late_bound_region_err. unwrap_or ( false ) , None ) ;
@@ -404,7 +410,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
404
410
) ;
405
411
}
406
412
// FIXME(const_generics:defaults)
407
- if !infer_consts || arg_counts. consts > param_counts. consts {
413
+ if !infer_args || arg_counts. consts > param_counts. consts {
408
414
check_kind_count (
409
415
"const" ,
410
416
param_counts. consts ,
@@ -707,8 +713,14 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
707
713
}
708
714
GenericParamDefKind :: Const => {
709
715
// 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
+ }
712
724
}
713
725
}
714
726
} ,
0 commit comments