Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c09d9dc

Browse files
Actually just make can_eq process obligations (almost) everywhere
1 parent e671c4a commit c09d9dc

File tree

24 files changed

+66
-67
lines changed

24 files changed

+66
-67
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_middle::ty::{
2121
use rustc_middle::ty::{GenericParamDefKind, TyCtxt};
2222
use rustc_middle::{bug, span_bug};
2323
use rustc_span::Span;
24+
use rustc_trait_selection::infer::InferCtxtExt;
2425
use rustc_trait_selection::regions::InferCtxtRegionExt;
2526
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
2627
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc_session::parse::feature_err;
2929
use rustc_span::symbol::{sym, Ident};
3030
use rustc_span::{Span, DUMMY_SP};
3131
use rustc_target::spec::abi::Abi;
32+
use rustc_trait_selection::infer::InferCtxtExt;
3233
use rustc_trait_selection::regions::InferCtxtRegionExt;
3334
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
3435
use rustc_trait_selection::traits::misc::{
@@ -1712,15 +1713,7 @@ fn receiver_is_valid<'tcx>(
17121713
let cause =
17131714
ObligationCause::new(span, wfcx.body_def_id, traits::ObligationCauseCode::MethodReceiver);
17141715

1715-
let can_eq_self = |ty| {
1716-
wfcx.infcx.probe(|_| {
1717-
let ocx = ObligationCtxt::new(wfcx.infcx);
1718-
let Ok(()) = ocx.eq(&ObligationCause::dummy(), wfcx.param_env, self_ty, ty) else {
1719-
return false;
1720-
};
1721-
ocx.select_where_possible().is_empty()
1722-
})
1723-
};
1716+
let can_eq_self = |ty| infcx.can_eq(wfcx.param_env, self_ty, ty);
17241717

17251718
// `self: Self` is always valid.
17261719
if can_eq_self(receiver_ty) {

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
4949
use rustc_span::symbol::{kw, Ident, Symbol};
5050
use rustc_span::{sym, Span, DUMMY_SP};
5151
use rustc_target::spec::abi;
52+
use rustc_trait_selection::infer::InferCtxtExt;
5253
use rustc_trait_selection::traits::wf::object_region_bounds;
5354
use rustc_trait_selection::traits::{self, ObligationCtxt};
5455

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1313
use rustc_middle::ty::{self, AssocItem, Ty, TypeFoldable, TypeVisitableExt};
1414
use rustc_span::symbol::sym;
1515
use rustc_span::{Span, DUMMY_SP};
16+
use rustc_trait_selection::infer::InferCtxtExt;
1617
use rustc_trait_selection::traits::ObligationCause;
1718

1819
use super::method::probe;

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use rustc_middle::{bug, span_bug};
4040
use rustc_session::Session;
4141
use rustc_span::symbol::{kw, Ident};
4242
use rustc_span::{sym, BytePos, Span, DUMMY_SP};
43+
use rustc_trait_selection::infer::InferCtxtExt;
4344
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};
4445

4546
use std::iter;

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2582,7 +2582,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25822582
}
25832583
}
25842584
(hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr), _, &ty::Ref(_, checked, _))
2585-
if self.can_sub(self.param_env, checked, expected) =>
2585+
if self.can_eq(self.param_env, checked, expected) =>
25862586
{
25872587
let make_sugg = |start: Span, end: BytePos| {
25882588
// skip `(` for tuples such as `(c) = (&123)`.

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use rustc_span::edit_distance::{
3333
};
3434
use rustc_span::symbol::sym;
3535
use rustc_span::{symbol::Ident, Span, Symbol, DUMMY_SP};
36+
use rustc_trait_selection::infer::InferCtxtExt as _;
3637
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
3738
use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy;
3839
use rustc_trait_selection::traits::query::method_autoderef::{
@@ -857,7 +858,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
857858
let args = self.fresh_args_for_item(self.span, method.def_id);
858859
let fty = self.tcx.fn_sig(method.def_id).instantiate(self.tcx, args);
859860
let fty = self.instantiate_binder_with_fresh_vars(self.span, infer::FnCall, fty);
860-
self.can_sub(self.param_env, fty.output(), expected)
861+
self.can_eq(self.param_env, fty.output(), expected)
861862
}),
862863
_ => false,
863864
}

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_span::source_map::Spanned;
1919
use rustc_span::symbol::{kw, sym, Ident};
2020
use rustc_span::{BytePos, Span, DUMMY_SP};
2121
use rustc_target::abi::FieldIdx;
22+
use rustc_trait_selection::infer::InferCtxtExt;
2223
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
2324
use ty::VariantDef;
2425

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ fn foo(&self) -> Self::T { String::new() }
820820
tcx.defaultness(item.id.owner_id)
821821
{
822822
let assoc_ty = tcx.type_of(item.id.owner_id).instantiate_identity();
823-
if self.infcx.can_eq(param_env, assoc_ty, found) {
823+
if self.infcx.can_eq_shallow(param_env, assoc_ty, found) {
824824
diag.span_label(
825825
item.span,
826826
"associated type defaults can't be assumed inside the \
@@ -843,7 +843,7 @@ fn foo(&self) -> Self::T { String::new() }
843843
let assoc_ty = tcx.type_of(item.id.owner_id).instantiate_identity();
844844
if let hir::Defaultness::Default { has_value: true } =
845845
tcx.defaultness(item.id.owner_id)
846-
&& self.infcx.can_eq(param_env, assoc_ty, found)
846+
&& self.infcx.can_eq_shallow(param_env, assoc_ty, found)
847847
{
848848
diag.span_label(
849849
item.span,

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -769,21 +769,7 @@ impl<'tcx> InferCtxt<'tcx> {
769769

770770
// FIXME(-Znext-solver): Get rid of this method, it's never correct. Either that,
771771
// or we need to process the obligations.
772-
pub fn can_sub<T>(&self, param_env: ty::ParamEnv<'tcx>, expected: T, actual: T) -> bool
773-
where
774-
T: at::ToTrace<'tcx>,
775-
{
776-
let origin = &ObligationCause::dummy();
777-
self.probe(|_| {
778-
// We're only answering whether there could be a subtyping relation, and with
779-
// opaque types, "there could be one", via registering a hidden type.
780-
self.at(origin, param_env).sub(DefineOpaqueTypes::Yes, expected, actual).is_ok()
781-
})
782-
}
783-
784-
// FIXME(-Znext-solver): Get rid of this method, it's never correct. Either that,
785-
// or we need to process the obligations.
786-
pub fn can_eq<T>(&self, param_env: ty::ParamEnv<'tcx>, a: T, b: T) -> bool
772+
pub fn can_eq_shallow<T>(&self, param_env: ty::ParamEnv<'tcx>, a: T, b: T) -> bool
787773
where
788774
T: at::ToTrace<'tcx>,
789775
{

0 commit comments

Comments
 (0)