@@ -306,8 +306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
306
306
span : Span ,
307
307
trait_def_id : DefId ,
308
308
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 > ) > ,
311
310
expected : Expectation < ' tcx > ,
312
311
) -> ( traits:: Obligation < ' tcx , ty:: Predicate < ' tcx > > , & ' tcx ty:: List < ty:: subst:: GenericArg < ' tcx > > )
313
312
{
@@ -318,7 +317,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
318
317
GenericParamDefKind :: Type { .. } => {
319
318
if param. index == 0 {
320
319
return self_ty. into ( ) ;
321
- } else if let Some ( input_type) = opt_input_type {
320
+ } else if let Some ( ( _ , input_type) ) = opt_rhs {
322
321
return input_type. into ( ) ;
323
322
}
324
323
}
@@ -339,9 +338,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
339
338
span,
340
339
self . body_id ,
341
340
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 ( _) ) ) ,
345
344
output_ty,
346
345
} ,
347
346
) ,
@@ -368,15 +367,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
368
367
) -> Option < InferOk < ' tcx , MethodCallee < ' tcx > > > {
369
368
let ( obligation, substs) =
370
369
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)
380
371
}
381
372
382
373
pub ( super ) fn lookup_op_method_in_trait (
@@ -385,27 +376,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
385
376
m_name : Ident ,
386
377
trait_def_id : DefId ,
387
378
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 > ) > ,
390
380
expected : Expectation < ' tcx > ,
391
381
) -> 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)
409
385
}
410
386
411
387
// FIXME(#18741): it seems likely that we can consolidate some of this
@@ -418,8 +394,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
418
394
trait_def_id : DefId ,
419
395
obligation : traits:: PredicateObligation < ' tcx > ,
420
396
substs : & ' tcx ty:: List < ty:: subst:: GenericArg < ' tcx > > ,
421
- opt_input_expr : Option < & ' tcx hir:: Expr < ' tcx > > ,
422
- is_op : bool ,
423
397
) -> Option < InferOk < ' tcx , MethodCallee < ' tcx > > > {
424
398
debug ! ( ?obligation) ;
425
399
@@ -463,22 +437,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
463
437
let fn_sig = fn_sig. subst ( self . tcx , substs) ;
464
438
let fn_sig = self . replace_bound_vars_with_fresh_vars ( span, infer:: FnCall , fn_sig) ;
465
439
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) ;
482
442
let fn_sig = {
483
443
obligations. extend ( o) ;
484
444
value
@@ -494,15 +454,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
494
454
// any late-bound regions appearing in its bounds.
495
455
let bounds = self . tcx . predicates_of ( def_id) . instantiate ( self . tcx , substs) ;
496
456
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) ;
498
459
let bounds = {
499
460
obligations. extend ( o) ;
500
461
value
501
462
} ;
502
463
503
464
assert ! ( !bounds. has_escaping_bound_vars( ) ) ;
504
465
505
- let predicates_cause = cause. clone ( ) ;
466
+ let predicates_cause = obligation . cause . clone ( ) ;
506
467
obligations. extend ( traits:: predicates_for_generics (
507
468
move |_, _| predicates_cause. clone ( ) ,
508
469
self . param_env ,
@@ -517,7 +478,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
517
478
) ;
518
479
obligations. push ( traits:: Obligation :: new (
519
480
tcx,
520
- cause,
481
+ obligation . cause ,
521
482
self . param_env ,
522
483
ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( method_ty. into ( ) ) ) ,
523
484
) ) ;
0 commit comments