Skip to content

Commit

Permalink
Auto merge of rust-lang#127473 - compiler-errors:perf-revert-receiver…
Browse files Browse the repository at this point in the history
…, r=<try>

Revert "Rework receiver_is_valid"

This reverts commit 465e7d5.

Testing perf: rust-lang#127172 (comment)

r? `@ghost`
  • Loading branch information
bors committed Jul 8, 2024
2 parents a06e9c8 + 865b9ab commit 6c0f300
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1712,24 +1712,13 @@ fn receiver_is_valid<'tcx>(
let cause =
ObligationCause::new(span, wfcx.body_def_id, traits::ObligationCauseCode::MethodReceiver);

// Special case `receiver == self_ty`, which doesn't necessarily require the `Receiver` lang item.
if let Ok(()) = wfcx.infcx.commit_if_ok(|_| {
let ocx = ObligationCtxt::new(wfcx.infcx);
ocx.eq(&cause, wfcx.param_env, self_ty, receiver_ty)?;
if ocx.select_all_or_error().is_empty() { Ok(()) } else { Err(NoSolution) }
}) {
return true;
}

let mut autoderef = Autoderef::new(infcx, wfcx.param_env, wfcx.body_def_id, span, receiver_ty);

// The `arbitrary_self_types` feature allows raw pointer receivers like `self: *const Self`.
if arbitrary_self_types_enabled {
autoderef = autoderef.include_raw_pointers();
}

let receiver_trait_def_id = tcx.require_lang_item(LangItem::Receiver, Some(span));

// Keep dereferencing `receiver_ty` until we get to `self_ty`.
while let Some((potential_self_ty, _)) = autoderef.next() {
debug!(
Expand All @@ -1751,6 +1740,8 @@ fn receiver_is_valid<'tcx>(
// Without `feature(arbitrary_self_types)`, we require that each step in the
// deref chain implement `receiver`.
if !arbitrary_self_types_enabled {
let receiver_trait_def_id = tcx.require_lang_item(LangItem::Receiver, Some(span));

if !receiver_is_implemented(
wfcx,
receiver_trait_def_id,
Expand All @@ -1760,14 +1751,6 @@ fn receiver_is_valid<'tcx>(
// We cannot proceed.
break;
}

// Register the bound, in case it has any region side-effects.
wfcx.register_bound(
cause.clone(),
wfcx.param_env,
potential_self_ty,
receiver_trait_def_id,
);
}
}

Expand Down

0 comments on commit 6c0f300

Please sign in to comment.