Skip to content

Commit f202abd

Browse files
Inline construct_obligation_for_trait
1 parent c50bc62 commit f202abd

File tree

1 file changed

+5
-29
lines changed
  • compiler/rustc_hir_typeck/src/method

1 file changed

+5
-29
lines changed

Diff for: compiler/rustc_hir_typeck/src/method/mod.rs

+5-29
Original file line numberDiff line numberDiff line change
@@ -356,20 +356,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
356356

357357
let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, args);
358358
let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, trait_ref);
359-
self.construct_obligation_for_trait(m_name, trait_def_id, obligation, args)
360-
}
361-
362-
// FIXME(#18741): it seems likely that we can consolidate some of this
363-
// code with the other method-lookup code. In particular, the second half
364-
// of this method is basically the same as confirmation.
365-
fn construct_obligation_for_trait(
366-
&self,
367-
m_name: Ident,
368-
trait_def_id: DefId,
369-
obligation: traits::PredicateObligation<'tcx>,
370-
args: ty::GenericArgsRef<'tcx>,
371-
) -> Option<InferOk<'tcx, MethodCallee<'tcx>>> {
372-
debug!(?obligation);
373359

374360
// Now we want to know if this can be matched
375361
if !self.predicate_may_hold(&obligation) {
@@ -393,8 +379,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
393379
debug!("lookup_in_trait_adjusted: method_item={:?}", method_item);
394380
let mut obligations = PredicateObligations::new();
395381

396-
// FIXME(effects): revisit when binops get `#[const_trait]`
397-
398382
// Instantiate late-bound regions and instantiate the trait
399383
// parameters into the method type to get the actual method type.
400384
//
@@ -405,12 +389,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
405389
let fn_sig =
406390
self.instantiate_binder_with_fresh_vars(obligation.cause.span, infer::FnCall, fn_sig);
407391

408-
let InferOk { value, obligations: o } =
392+
let InferOk { value: fn_sig, obligations: o } =
409393
self.at(&obligation.cause, self.param_env).normalize(fn_sig);
410-
let fn_sig = {
411-
obligations.extend(o);
412-
value
413-
};
394+
obligations.extend(o);
414395

415396
// Register obligations for the parameters. This will include the
416397
// `Self` parameter, which in turn has a bound of the main trait,
@@ -422,13 +403,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
422403
// any late-bound regions appearing in its bounds.
423404
let bounds = self.tcx.predicates_of(def_id).instantiate(self.tcx, args);
424405

425-
let InferOk { value, obligations: o } =
406+
let InferOk { value: bounds, obligations: o } =
426407
self.at(&obligation.cause, self.param_env).normalize(bounds);
427-
let bounds = {
428-
obligations.extend(o);
429-
value
430-
};
431-
408+
obligations.extend(o);
432409
assert!(!bounds.has_escaping_bound_vars());
433410

434411
let predicates_cause = obligation.cause.clone();
@@ -441,7 +418,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
441418
// Also add an obligation for the method type being well-formed.
442419
let method_ty = Ty::new_fn_ptr(tcx, ty::Binder::dummy(fn_sig));
443420
debug!(
444-
"lookup_in_trait_adjusted: matched method method_ty={:?} obligation={:?}",
421+
"lookup_method_in_trait: matched method method_ty={:?} obligation={:?}",
445422
method_ty, obligation
446423
);
447424
obligations.push(traits::Obligation::new(
@@ -454,7 +431,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
454431
));
455432

456433
let callee = MethodCallee { def_id, args, sig: fn_sig };
457-
458434
debug!("callee = {:?}", callee);
459435

460436
Some(InferOk { obligations, value: callee })

0 commit comments

Comments
 (0)