From ae938b03fcb2756a71790eef3d0e4c07d3300666 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 8 Jul 2024 10:57:56 -0400 Subject: [PATCH 1/3] w --- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 30ff272ce129b..8314b1c1f42a8 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1713,15 +1713,6 @@ 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`. @@ -1729,8 +1720,6 @@ fn receiver_is_valid<'tcx>( 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!( @@ -1752,6 +1741,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, From 865b9ab6384b1cf6484de1308ca8dd00affb6af6 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 8 Jul 2024 15:51:21 -0400 Subject: [PATCH 2/3] w --- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 8314b1c1f42a8..283803916b3c6 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1752,14 +1752,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, - ); } } From c2630bcb8928c88fb5818c952e068c39beae806b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 16 Jul 2024 11:54:52 -0400 Subject: [PATCH 3/3] Add it back --- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 283803916b3c6..8314b1c1f42a8 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1752,6 +1752,14 @@ 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, + ); } }