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

Commit 65614b9

Browse files
committed
Auto merge of rust-lang#127172 - compiler-errors:full-can_eq-everywhere, r=<try>
Make `can_eq` process obligations (almost) everywhere r? lcnr
2 parents 6c34855 + c09d9dc commit 65614b9

File tree

25 files changed

+90
-56
lines changed

25 files changed

+90
-56
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: 1 addition & 0 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::{

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: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -767,19 +767,9 @@ impl<'tcx> InferCtxt<'tcx> {
767767
.collect()
768768
}
769769

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

0 commit comments

Comments
 (0)