@@ -306,8 +306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
306306 span : Span ,
307307 trait_def_id : DefId ,
308308 self_ty : Ty < ' tcx > ,
309- opt_input_type : Option < Ty < ' tcx > > ,
310- opt_input_expr : Option < & ' tcx hir:: Expr < ' tcx > > ,
309+ opt_rhs : Option < ( & ' tcx hir:: Expr < ' tcx > , Ty < ' tcx > ) > ,
311310 expected : Expectation < ' tcx > ,
312311 ) -> ( traits:: Obligation < ' tcx , ty:: Predicate < ' tcx > > , & ' tcx ty:: List < ty:: subst:: GenericArg < ' tcx > > )
313312 {
@@ -318,7 +317,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
318317 GenericParamDefKind :: Type { .. } => {
319318 if param. index == 0 {
320319 return self_ty. into ( ) ;
321- } else if let Some ( input_type) = opt_input_type {
320+ } else if let Some ( ( _ , input_type) ) = opt_rhs {
322321 return input_type. into ( ) ;
323322 }
324323 }
@@ -339,9 +338,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
339338 span,
340339 self . body_id ,
341340 traits:: BinOp {
342- rhs_span : opt_input_expr . map ( |expr| expr. span ) ,
343- is_lit : opt_input_expr
344- . map_or ( false , |expr| matches ! ( expr. kind, hir:: ExprKind :: Lit ( _) ) ) ,
341+ rhs_span : opt_rhs . map ( |( expr, _ ) | expr. span ) ,
342+ is_lit : opt_rhs
343+ . map_or ( false , |( expr, _ ) | matches ! ( expr. kind, hir:: ExprKind :: Lit ( _) ) ) ,
345344 output_ty,
346345 } ,
347346 ) ,
@@ -368,15 +367,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
368367 ) -> Option < InferOk < ' tcx , MethodCallee < ' tcx > > > {
369368 let ( obligation, substs) =
370369 self . obligation_for_method ( span, trait_def_id, self_ty, opt_input_types) ;
371- self . construct_obligation_for_trait (
372- span,
373- m_name,
374- trait_def_id,
375- obligation,
376- substs,
377- None ,
378- false ,
379- )
370+ self . construct_obligation_for_trait ( span, m_name, trait_def_id, obligation, substs)
380371 }
381372
382373 pub ( super ) fn lookup_op_method_in_trait (
@@ -385,27 +376,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
385376 m_name : Ident ,
386377 trait_def_id : DefId ,
387378 self_ty : Ty < ' tcx > ,
388- opt_input_type : Option < Ty < ' tcx > > ,
389- opt_input_expr : Option < & ' tcx hir:: Expr < ' tcx > > ,
379+ opt_rhs : Option < ( & ' tcx hir:: Expr < ' tcx > , Ty < ' tcx > ) > ,
390380 expected : Expectation < ' tcx > ,
391381 ) -> Option < InferOk < ' tcx , MethodCallee < ' tcx > > > {
392- let ( obligation, substs) = self . obligation_for_op_method (
393- span,
394- trait_def_id,
395- self_ty,
396- opt_input_type,
397- opt_input_expr,
398- expected,
399- ) ;
400- self . construct_obligation_for_trait (
401- span,
402- m_name,
403- trait_def_id,
404- obligation,
405- substs,
406- opt_input_expr,
407- true ,
408- )
382+ let ( obligation, substs) =
383+ self . obligation_for_op_method ( span, trait_def_id, self_ty, opt_rhs, expected) ;
384+ self . construct_obligation_for_trait ( span, m_name, trait_def_id, obligation, substs)
409385 }
410386
411387 // FIXME(#18741): it seems likely that we can consolidate some of this
@@ -418,8 +394,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
418394 trait_def_id : DefId ,
419395 obligation : traits:: PredicateObligation < ' tcx > ,
420396 substs : & ' tcx ty:: List < ty:: subst:: GenericArg < ' tcx > > ,
421- opt_input_expr : Option < & ' tcx hir:: Expr < ' tcx > > ,
422- is_op : bool ,
423397 ) -> Option < InferOk < ' tcx , MethodCallee < ' tcx > > > {
424398 debug ! ( ?obligation) ;
425399
@@ -463,22 +437,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
463437 let fn_sig = fn_sig. subst ( self . tcx , substs) ;
464438 let fn_sig = self . replace_bound_vars_with_fresh_vars ( span, infer:: FnCall , fn_sig) ;
465439
466- let cause = if is_op {
467- ObligationCause :: new (
468- span,
469- self . body_id ,
470- traits:: BinOp {
471- rhs_span : opt_input_expr. map ( |expr| expr. span ) ,
472- is_lit : opt_input_expr
473- . map_or ( false , |expr| matches ! ( expr. kind, hir:: ExprKind :: Lit ( _) ) ) ,
474- output_ty : None ,
475- } ,
476- )
477- } else {
478- traits:: ObligationCause :: misc ( span, self . body_id )
479- } ;
480-
481- let InferOk { value, obligations : o } = self . at ( & cause, self . param_env ) . normalize ( fn_sig) ;
440+ let InferOk { value, obligations : o } =
441+ self . at ( & obligation. cause , self . param_env ) . normalize ( fn_sig) ;
482442 let fn_sig = {
483443 obligations. extend ( o) ;
484444 value
@@ -494,15 +454,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
494454 // any late-bound regions appearing in its bounds.
495455 let bounds = self . tcx . predicates_of ( def_id) . instantiate ( self . tcx , substs) ;
496456
497- let InferOk { value, obligations : o } = self . at ( & cause, self . param_env ) . normalize ( bounds) ;
457+ let InferOk { value, obligations : o } =
458+ self . at ( & obligation. cause , self . param_env ) . normalize ( bounds) ;
498459 let bounds = {
499460 obligations. extend ( o) ;
500461 value
501462 } ;
502463
503464 assert ! ( !bounds. has_escaping_bound_vars( ) ) ;
504465
505- let predicates_cause = cause. clone ( ) ;
466+ let predicates_cause = obligation . cause . clone ( ) ;
506467 obligations. extend ( traits:: predicates_for_generics (
507468 move |_, _| predicates_cause. clone ( ) ,
508469 self . param_env ,
@@ -517,7 +478,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
517478 ) ;
518479 obligations. push ( traits:: Obligation :: new (
519480 tcx,
520- cause,
481+ obligation . cause ,
521482 self . param_env ,
522483 ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( method_ty. into ( ) ) ) ,
523484 ) ) ;
0 commit comments