@@ -775,31 +775,33 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
775
775
ref impl_items) => {
776
776
// Create generics from the generics specified in the impl head.
777
777
debug ! ( "convert: ast_generics={:?}" , generics) ;
778
+ let def_id = ccx. tcx . map . local_def_id ( it. id ) ;
778
779
let ty_generics = ty_generics_for_type_or_impl ( ccx, generics) ;
779
- let ty_predicates = ty_generic_predicates_for_type_or_impl ( ccx, generics) ;
780
+ let mut ty_predicates = ty_generic_predicates_for_type_or_impl ( ccx, generics) ;
780
781
781
782
debug ! ( "convert: impl_bounds={:?}" , ty_predicates) ;
782
783
783
784
let selfty = ccx. icx ( & ty_predicates) . to_ty ( & ExplicitRscope , & * * selfty) ;
784
785
write_ty_to_tcx ( tcx, it. id , selfty) ;
785
786
786
- tcx. register_item_type ( ccx . tcx . map . local_def_id ( it . id ) ,
787
+ tcx. register_item_type ( def_id ,
787
788
TypeScheme { generics : ty_generics. clone ( ) ,
788
789
ty : selfty } ) ;
789
- tcx. predicates . borrow_mut ( ) . insert ( ccx. tcx . map . local_def_id ( it. id ) ,
790
- ty_predicates. clone ( ) ) ;
791
790
if let & Some ( ref ast_trait_ref) = opt_trait_ref {
792
791
tcx. impl_trait_refs . borrow_mut ( ) . insert (
793
- ccx . tcx . map . local_def_id ( it . id ) ,
792
+ def_id ,
794
793
Some ( astconv:: instantiate_mono_trait_ref ( & ccx. icx ( & ty_predicates) ,
795
794
& ExplicitRscope ,
796
795
ast_trait_ref,
797
796
Some ( selfty) ) )
798
797
) ;
799
798
} else {
800
- tcx. impl_trait_refs . borrow_mut ( ) . insert ( ccx . tcx . map . local_def_id ( it . id ) , None ) ;
799
+ tcx. impl_trait_refs . borrow_mut ( ) . insert ( def_id , None ) ;
801
800
}
802
801
802
+ enforce_impl_params_are_constrained ( tcx, generics, & mut ty_predicates, def_id) ;
803
+ tcx. predicates . borrow_mut ( ) . insert ( def_id, ty_predicates. clone ( ) ) ;
804
+
803
805
804
806
// If there is a trait reference, treat the methods as always public.
805
807
// This is to work around some incorrect behavior in privacy checking:
@@ -844,7 +846,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
844
846
generics : ty_generics. clone ( ) ,
845
847
ty : ty,
846
848
} ) ;
847
- convert_associated_const ( ccx, ImplContainer ( ccx . tcx . map . local_def_id ( it . id ) ) ,
849
+ convert_associated_const ( ccx, ImplContainer ( def_id ) ,
848
850
impl_item. name , impl_item. id ,
849
851
impl_item. vis . inherit_from ( parent_visibility) ,
850
852
ty, true /* has_value */ ) ;
@@ -861,7 +863,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
861
863
862
864
let typ = ccx. icx ( & ty_predicates) . to_ty ( & ExplicitRscope , ty) ;
863
865
864
- convert_associated_type ( ccx, ImplContainer ( ccx . tcx . map . local_def_id ( it . id ) ) ,
866
+ convert_associated_type ( ccx, ImplContainer ( def_id ) ,
865
867
impl_item. name , impl_item. id , impl_item. vis ,
866
868
Some ( typ) ) ;
867
869
}
@@ -880,7 +882,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
880
882
}
881
883
} ) ;
882
884
convert_methods ( ccx,
883
- ImplContainer ( ccx . tcx . map . local_def_id ( it . id ) ) ,
885
+ ImplContainer ( def_id ) ,
884
886
methods,
885
887
selfty,
886
888
& ty_generics,
@@ -898,10 +900,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
898
900
}
899
901
}
900
902
901
- enforce_impl_params_are_constrained ( tcx,
902
- generics,
903
- ccx. tcx . map . local_def_id ( it. id ) ,
904
- impl_items) ;
903
+ enforce_impl_lifetimes_are_constrained ( tcx, generics, def_id, impl_items) ;
905
904
} ,
906
905
hir:: ItemTrait ( _, _, _, ref trait_items) => {
907
906
let trait_def = trait_def_of_item ( ccx, it) ;
@@ -2377,13 +2376,15 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>(
2377
2376
/// Checks that all the type parameters on an impl
2378
2377
fn enforce_impl_params_are_constrained < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
2379
2378
ast_generics : & hir:: Generics ,
2380
- impl_def_id : DefId ,
2381
- impl_items : & [ P < hir :: ImplItem > ] )
2379
+ impl_predicates : & mut ty :: GenericPredicates < ' tcx > ,
2380
+ impl_def_id : DefId )
2382
2381
{
2383
2382
let impl_scheme = tcx. lookup_item_type ( impl_def_id) ;
2384
- let impl_predicates = tcx. lookup_predicates ( impl_def_id) ;
2385
2383
let impl_trait_ref = tcx. impl_trait_ref ( impl_def_id) ;
2386
2384
2385
+ assert ! ( impl_predicates. predicates. is_empty_in( FnSpace ) ) ;
2386
+ assert ! ( impl_predicates. predicates. is_empty_in( SelfSpace ) ) ;
2387
+
2387
2388
// The trait reference is an input, so find all type parameters
2388
2389
// reachable from there, to start (if this is an inherent impl,
2389
2390
// then just examine the self type).
@@ -2393,10 +2394,10 @@ fn enforce_impl_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
2393
2394
input_parameters. extend ( ctp:: parameters_for_trait_ref ( trait_ref) ) ;
2394
2395
}
2395
2396
2396
- ctp:: identify_constrained_type_params ( tcx,
2397
- impl_predicates. predicates . as_slice ( ) ,
2398
- impl_trait_ref,
2399
- & mut input_parameters) ;
2397
+ ctp:: setup_constraining_predicates ( tcx,
2398
+ impl_predicates. predicates . get_mut_slice ( TypeSpace ) ,
2399
+ impl_trait_ref,
2400
+ & mut input_parameters) ;
2400
2401
2401
2402
for ( index, ty_param) in ast_generics. ty_params . iter ( ) . enumerate ( ) {
2402
2403
let param_ty = ty:: ParamTy { space : TypeSpace ,
@@ -2406,8 +2407,25 @@ fn enforce_impl_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
2406
2407
report_unused_parameter ( tcx, ty_param. span , "type" , & param_ty. to_string ( ) ) ;
2407
2408
}
2408
2409
}
2410
+ }
2409
2411
2412
+ fn enforce_impl_lifetimes_are_constrained < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
2413
+ ast_generics : & hir:: Generics ,
2414
+ impl_def_id : DefId ,
2415
+ impl_items : & [ P < hir:: ImplItem > ] )
2416
+ {
2410
2417
// Every lifetime used in an associated type must be constrained.
2418
+ let impl_scheme = tcx. lookup_item_type ( impl_def_id) ;
2419
+ let impl_predicates = tcx. lookup_predicates ( impl_def_id) ;
2420
+ let impl_trait_ref = tcx. impl_trait_ref ( impl_def_id) ;
2421
+
2422
+ let mut input_parameters: HashSet < _ > =
2423
+ ctp:: parameters_for_type ( impl_scheme. ty ) . into_iter ( ) . collect ( ) ;
2424
+ if let Some ( ref trait_ref) = impl_trait_ref {
2425
+ input_parameters. extend ( ctp:: parameters_for_trait_ref ( trait_ref) ) ;
2426
+ }
2427
+ ctp:: identify_constrained_type_params ( tcx,
2428
+ & impl_predicates. predicates . as_slice ( ) , impl_trait_ref, & mut input_parameters) ;
2411
2429
2412
2430
let lifetimes_in_associated_types: HashSet < _ > =
2413
2431
impl_items. iter ( )
0 commit comments