@@ -6,6 +6,7 @@ use rustc::traits::{self, ObligationCauseCode};
6
6
use rustc:: ty:: { self , Lift , Ty , TyCtxt , TyKind , GenericParamDefKind , TypeFoldable , ToPredicate } ;
7
7
use rustc:: ty:: subst:: { Subst , InternalSubsts } ;
8
8
use rustc:: util:: nodemap:: { FxHashSet , FxHashMap } ;
9
+ use rustc:: mir:: interpret:: ConstValue ;
9
10
use rustc:: middle:: lang_items;
10
11
use rustc:: infer:: opaque_types:: may_define_existential_type;
11
12
@@ -436,7 +437,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(
436
437
// struct Foo<T = Vec<[u32]>> { .. }
437
438
// Here the default `Vec<[u32]>` is not WF because `[u32]: Sized` does not hold.
438
439
for param in & generics. params {
439
- if let GenericParamDefKind :: Type { .. } = param. kind {
440
+ if let GenericParamDefKind :: Type { .. } = param. kind {
440
441
if is_our_default ( & param) {
441
442
let ty = fcx. tcx . type_of ( param. def_id ) ;
442
443
// ignore dependent defaults -- that is, where the default of one type
@@ -464,7 +465,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(
464
465
// All regions are identity.
465
466
fcx. tcx . mk_param_from_def ( param)
466
467
}
467
- GenericParamDefKind :: Type { .. } => {
468
+ GenericParamDefKind :: Type { .. } => {
468
469
// If the param has a default,
469
470
if is_our_default ( param) {
470
471
let default_ty = fcx. tcx . type_of ( param. def_id ) ;
@@ -477,6 +478,10 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(
477
478
// Mark unwanted params as err.
478
479
fcx. tcx . types . err . into ( )
479
480
}
481
+ GenericParamDefKind :: Const => {
482
+ // FIXME(const_generics:defaults)
483
+ fcx. tcx . types . err . into ( )
484
+ }
480
485
}
481
486
} ) ;
482
487
// Now we build the substituted predicates.
@@ -497,6 +502,16 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(
497
502
fn visit_region ( & mut self , _: ty:: Region < ' tcx > ) -> bool {
498
503
true
499
504
}
505
+
506
+ fn visit_const ( & mut self , c : & ' tcx ty:: LazyConst < ' tcx > ) -> bool {
507
+ if let ty:: LazyConst :: Evaluated ( ty:: Const {
508
+ val : ConstValue :: Param ( param) ,
509
+ ..
510
+ } ) = c {
511
+ self . params . insert ( param. index ) ;
512
+ }
513
+ c. super_visit_with ( self )
514
+ }
500
515
}
501
516
let mut param_count = CountParams :: default ( ) ;
502
517
let has_region = pred. visit_with ( & mut param_count) ;
@@ -617,11 +632,10 @@ fn check_existential_types<'a, 'fcx, 'gcx, 'tcx>(
617
632
for ( subst, param) in substs. iter ( ) . zip ( & generics. params ) {
618
633
match subst. unpack ( ) {
619
634
ty:: subst:: UnpackedKind :: Type ( ty) => match ty. sty {
620
- ty:: Param ( ..) => { } ,
635
+ ty:: Param ( ..) => { }
621
636
// prevent `fn foo() -> Foo<u32>` from being defining
622
637
_ => {
623
- tcx
624
- . sess
638
+ tcx. sess
625
639
. struct_span_err (
626
640
span,
627
641
"non-defining existential type use \
@@ -636,8 +650,9 @@ fn check_existential_types<'a, 'fcx, 'gcx, 'tcx>(
636
650
) ,
637
651
)
638
652
. emit ( ) ;
639
- } ,
640
- } , // match ty
653
+ }
654
+ }
655
+
641
656
ty:: subst:: UnpackedKind :: Lifetime ( region) => {
642
657
let param_span = tcx. def_span ( param. def_id ) ;
643
658
if let ty:: ReStatic = region {
@@ -658,7 +673,31 @@ fn check_existential_types<'a, 'fcx, 'gcx, 'tcx>(
658
673
} else {
659
674
seen. entry ( region) . or_default ( ) . push ( param_span) ;
660
675
}
661
- } ,
676
+ }
677
+
678
+ ty:: subst:: UnpackedKind :: Const ( ct) => match ct {
679
+ ty:: LazyConst :: Evaluated ( ty:: Const {
680
+ val : ConstValue :: Param ( _) ,
681
+ ..
682
+ } ) => { }
683
+ _ => {
684
+ tcx. sess
685
+ . struct_span_err (
686
+ span,
687
+ "non-defining existential type use \
688
+ in defining scope",
689
+ )
690
+ . span_note (
691
+ tcx. def_span ( param. def_id ) ,
692
+ & format ! (
693
+ "used non-generic const {} for \
694
+ generic parameter",
695
+ ty,
696
+ ) ,
697
+ )
698
+ . emit ( ) ;
699
+ }
700
+ }
662
701
} // match subst
663
702
} // for (subst, param)
664
703
for ( _, spans) in seen {
@@ -942,7 +981,9 @@ fn reject_shadowing_parameters(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) {
942
981
let parent = tcx. generics_of ( generics. parent . unwrap ( ) ) ;
943
982
let impl_params: FxHashMap < _ , _ > = parent. params . iter ( ) . flat_map ( |param| match param. kind {
944
983
GenericParamDefKind :: Lifetime => None ,
945
- GenericParamDefKind :: Type { ..} => Some ( ( param. name , param. def_id ) ) ,
984
+ GenericParamDefKind :: Type { .. } | GenericParamDefKind :: Const => {
985
+ Some ( ( param. name , param. def_id ) )
986
+ }
946
987
} ) . collect ( ) ;
947
988
948
989
for method_param in & generics. params {
0 commit comments