@@ -2579,16 +2579,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25792579
25802580 /// As `instantiate_type_scheme`, but for the bounds found in a
25812581 /// generic type scheme.
2582- fn instantiate_bounds ( & self , span : Span , def_id : DefId , substs : SubstsRef < ' tcx > )
2583- -> ty:: InstantiatedPredicates < ' tcx > {
2582+ fn instantiate_bounds (
2583+ & self ,
2584+ span : Span ,
2585+ def_id : DefId ,
2586+ substs : SubstsRef < ' tcx > ,
2587+ ) -> ( ty:: InstantiatedPredicates < ' tcx > , Vec < Span > ) {
25842588 let bounds = self . tcx . predicates_of ( def_id) ;
2589+ let spans: Vec < Span > = bounds. predicates . iter ( ) . map ( |( _, span) | * span) . collect ( ) ;
25852590 let result = bounds. instantiate ( self . tcx , substs) ;
25862591 let result = self . normalize_associated_types_in ( span, & result) ;
2587- debug ! ( "instantiate_bounds(bounds={:?}, substs={:?}) = {:?}" ,
2592+ debug ! (
2593+ "instantiate_bounds(bounds={:?}, substs={:?}) = {:?}, {:?}" ,
25882594 bounds,
25892595 substs,
2590- result) ;
2591- result
2596+ result,
2597+ spans,
2598+ ) ;
2599+ ( result, spans)
25922600 }
25932601
25942602 /// Replaces the opaque types from the given value with type variables,
@@ -3151,8 +3159,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31513159
31523160 // All the input types from the fn signature must outlive the call
31533161 // so as to validate implied bounds.
3154- for & fn_input_ty in fn_inputs {
3155- self . register_wf_obligation ( fn_input_ty, sp , traits:: MiscObligation ) ;
3162+ for ( fn_input_ty, arg_expr ) in fn_inputs. iter ( ) . zip ( args . iter ( ) ) {
3163+ self . register_wf_obligation ( fn_input_ty, arg_expr . span , traits:: MiscObligation ) ;
31563164 }
31573165
31583166 let expected_arg_count = fn_inputs. len ( ) ;
@@ -3513,7 +3521,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
35133521 self . write_user_type_annotation_from_substs ( hir_id, did, substs, None ) ;
35143522
35153523 // Check bounds on type arguments used in the path.
3516- let bounds = self . instantiate_bounds ( path_span, did, substs) ;
3524+ let ( bounds, _ ) = self . instantiate_bounds ( path_span, did, substs) ;
35173525 let cause = traits:: ObligationCause :: new ( path_span, self . body_id ,
35183526 traits:: ItemObligation ( did) ) ;
35193527 self . add_obligations_for_parameters ( cause, & bounds) ;
@@ -4634,12 +4642,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
46344642 // First, store the "user substs" for later.
46354643 self . write_user_type_annotation_from_substs ( hir_id, def_id, substs, user_self_ty) ;
46364644
4637- // Add all the obligations that are required, substituting and
4638- // normalized appropriately.
4639- let bounds = self . instantiate_bounds ( span, def_id, & substs) ;
4640- self . add_obligations_for_parameters (
4641- traits:: ObligationCause :: new ( span, self . body_id , traits:: ItemObligation ( def_id) ) ,
4642- & bounds) ;
4645+ self . add_required_obligations ( span, def_id, & substs) ;
46434646
46444647 // Substitute the values for the type parameters into the type of
46454648 // the referenced item.
@@ -4676,6 +4679,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
46764679 ( ty_substituted, res)
46774680 }
46784681
4682+ /// Add all the obligations that are required, substituting and normalized appropriately.
4683+ fn add_required_obligations ( & self , span : Span , def_id : DefId , substs : & SubstsRef < ' tcx > ) {
4684+ let ( bounds, spans) = self . instantiate_bounds ( span, def_id, & substs) ;
4685+
4686+ for ( i, mut obligation) in traits:: predicates_for_generics (
4687+ traits:: ObligationCause :: new (
4688+ span,
4689+ self . body_id ,
4690+ traits:: ItemObligation ( def_id) ,
4691+ ) ,
4692+ self . param_env ,
4693+ & bounds,
4694+ ) . into_iter ( ) . enumerate ( ) {
4695+ // This makes the error point at the bound, but we want to point at the argument
4696+ if let Some ( span) = spans. get ( i) {
4697+ obligation. cause . code = traits:: BindingObligation ( def_id, * span) ;
4698+ }
4699+ self . register_predicate ( obligation) ;
4700+ }
4701+ }
4702+
46794703 fn check_rustc_args_require_const ( & self ,
46804704 def_id : DefId ,
46814705 hir_id : hir:: HirId ,
0 commit comments