@@ -775,31 +775,33 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
775775 ref impl_items) => {
776776 // Create generics from the generics specified in the impl head.
777777 debug ! ( "convert: ast_generics={:?}" , generics) ;
778+ let def_id = ccx. tcx . map . local_def_id ( it. id ) ;
778779 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) ;
780781
781782 debug ! ( "convert: impl_bounds={:?}" , ty_predicates) ;
782783
783784 let selfty = ccx. icx ( & ty_predicates) . to_ty ( & ExplicitRscope , & * * selfty) ;
784785 write_ty_to_tcx ( tcx, it. id , selfty) ;
785786
786- tcx. register_item_type ( ccx . tcx . map . local_def_id ( it . id ) ,
787+ tcx. register_item_type ( def_id ,
787788 TypeScheme { generics : ty_generics. clone ( ) ,
788789 ty : selfty } ) ;
789- tcx. predicates . borrow_mut ( ) . insert ( ccx. tcx . map . local_def_id ( it. id ) ,
790- ty_predicates. clone ( ) ) ;
791790 if let & Some ( ref ast_trait_ref) = opt_trait_ref {
792791 tcx. impl_trait_refs . borrow_mut ( ) . insert (
793- ccx . tcx . map . local_def_id ( it . id ) ,
792+ def_id ,
794793 Some ( astconv:: instantiate_mono_trait_ref ( & ccx. icx ( & ty_predicates) ,
795794 & ExplicitRscope ,
796795 ast_trait_ref,
797796 Some ( selfty) ) )
798797 ) ;
799798 } 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 ) ;
801800 }
802801
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+
803805
804806 // If there is a trait reference, treat the methods as always public.
805807 // This is to work around some incorrect behavior in privacy checking:
@@ -844,7 +846,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
844846 generics : ty_generics. clone ( ) ,
845847 ty : ty,
846848 } ) ;
847- convert_associated_const ( ccx, ImplContainer ( ccx . tcx . map . local_def_id ( it . id ) ) ,
849+ convert_associated_const ( ccx, ImplContainer ( def_id ) ,
848850 impl_item. name , impl_item. id ,
849851 impl_item. vis . inherit_from ( parent_visibility) ,
850852 ty, true /* has_value */ ) ;
@@ -861,7 +863,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
861863
862864 let typ = ccx. icx ( & ty_predicates) . to_ty ( & ExplicitRscope , ty) ;
863865
864- convert_associated_type ( ccx, ImplContainer ( ccx . tcx . map . local_def_id ( it . id ) ) ,
866+ convert_associated_type ( ccx, ImplContainer ( def_id ) ,
865867 impl_item. name , impl_item. id , impl_item. vis ,
866868 Some ( typ) ) ;
867869 }
@@ -880,7 +882,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
880882 }
881883 } ) ;
882884 convert_methods ( ccx,
883- ImplContainer ( ccx . tcx . map . local_def_id ( it . id ) ) ,
885+ ImplContainer ( def_id ) ,
884886 methods,
885887 selfty,
886888 & ty_generics,
@@ -898,10 +900,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
898900 }
899901 }
900902
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) ;
905904 } ,
906905 hir:: ItemTrait ( _, _, _, ref trait_items) => {
907906 let trait_def = trait_def_of_item ( ccx, it) ;
@@ -2377,13 +2376,15 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>(
23772376/// Checks that all the type parameters on an impl
23782377fn enforce_impl_params_are_constrained < ' tcx > ( tcx : & ty:: ctxt < ' tcx > ,
23792378 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 )
23822381{
23832382 let impl_scheme = tcx. lookup_item_type ( impl_def_id) ;
2384- let impl_predicates = tcx. lookup_predicates ( impl_def_id) ;
23852383 let impl_trait_ref = tcx. impl_trait_ref ( impl_def_id) ;
23862384
2385+ assert ! ( impl_predicates. predicates. is_empty_in( FnSpace ) ) ;
2386+ assert ! ( impl_predicates. predicates. is_empty_in( SelfSpace ) ) ;
2387+
23872388 // The trait reference is an input, so find all type parameters
23882389 // reachable from there, to start (if this is an inherent impl,
23892390 // then just examine the self type).
@@ -2393,10 +2394,10 @@ fn enforce_impl_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
23932394 input_parameters. extend ( ctp:: parameters_for_trait_ref ( trait_ref) ) ;
23942395 }
23952396
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) ;
24002401
24012402 for ( index, ty_param) in ast_generics. ty_params . iter ( ) . enumerate ( ) {
24022403 let param_ty = ty:: ParamTy { space : TypeSpace ,
@@ -2406,8 +2407,25 @@ fn enforce_impl_params_are_constrained<'tcx>(tcx: &ty::ctxt<'tcx>,
24062407 report_unused_parameter ( tcx, ty_param. span , "type" , & param_ty. to_string ( ) ) ;
24072408 }
24082409 }
2410+ }
24092411
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+ {
24102417 // 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) ;
24112429
24122430 let lifetimes_in_associated_types: HashSet < _ > =
24132431 impl_items. iter ( )
0 commit comments