Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/method_resolution/probe.rs')
-rw-r--r--crates/hir-ty/src/method_resolution/probe.rs31
1 files changed, 22 insertions, 9 deletions
diff --git a/crates/hir-ty/src/method_resolution/probe.rs b/crates/hir-ty/src/method_resolution/probe.rs
index 4a7c7d9353..fc2bd87ee4 100644
--- a/crates/hir-ty/src/method_resolution/probe.rs
+++ b/crates/hir-ty/src/method_resolution/probe.rs
@@ -285,11 +285,15 @@ impl<'a, 'db> MethodResolutionContext<'a, 'db> {
let infcx = self.infcx;
let (self_ty, var_values) = infcx.instantiate_canonical(&query_input);
debug!(?self_ty, ?query_input, "probe_op: Mode::Path");
+ let prev_opaque_entries =
+ self.infcx.inner.borrow_mut().opaque_types().num_entries();
MethodAutoderefStepsResult {
steps: smallvec![CandidateStep {
- self_ty: self
- .infcx
- .make_query_response_ignoring_pending_obligations(var_values, self_ty),
+ self_ty: self.infcx.make_query_response_ignoring_pending_obligations(
+ var_values,
+ self_ty,
+ prev_opaque_entries
+ ),
self_ty_is_opaque: false,
autoderefs: 0,
from_unsafe_deref: false,
@@ -376,6 +380,8 @@ impl<'a, 'db> MethodResolutionContext<'a, 'db> {
// infer var is not an opaque.
let infcx = self.infcx;
let (self_ty, inference_vars) = infcx.instantiate_canonical(self_ty);
+ let prev_opaque_entries = infcx.inner.borrow_mut().opaque_types().num_entries();
+
let self_ty_is_opaque = |ty: Ty<'_>| {
if let TyKind::Infer(InferTy::TyVar(vid)) = ty.kind() {
infcx.has_opaques_with_sub_unified_hidden_type(vid)
@@ -414,6 +420,7 @@ impl<'a, 'db> MethodResolutionContext<'a, 'db> {
self_ty: infcx.make_query_response_ignoring_pending_obligations(
inference_vars,
ty,
+ prev_opaque_entries,
),
self_ty_is_opaque: self_ty_is_opaque(ty),
autoderefs: d,
@@ -437,6 +444,7 @@ impl<'a, 'db> MethodResolutionContext<'a, 'db> {
self_ty: infcx.make_query_response_ignoring_pending_obligations(
inference_vars,
ty,
+ prev_opaque_entries,
),
self_ty_is_opaque: self_ty_is_opaque(ty),
autoderefs: d,
@@ -461,13 +469,17 @@ impl<'a, 'db> MethodResolutionContext<'a, 'db> {
ty: infcx.make_query_response_ignoring_pending_obligations(
inference_vars,
final_ty,
+ prev_opaque_entries,
),
})
}
TyKind::Error(_) => Some(MethodAutoderefBadTy {
reached_raw_pointer,
- ty: infcx
- .make_query_response_ignoring_pending_obligations(inference_vars, final_ty),
+ ty: infcx.make_query_response_ignoring_pending_obligations(
+ inference_vars,
+ final_ty,
+ prev_opaque_entries,
+ ),
}),
TyKind::Array(elem_ty, _) => {
let autoderefs = steps.iter().filter(|s| s.reachable_via_deref).count() - 1;
@@ -475,6 +487,7 @@ impl<'a, 'db> MethodResolutionContext<'a, 'db> {
self_ty: infcx.make_query_response_ignoring_pending_obligations(
inference_vars,
Ty::new_slice(infcx.interner, elem_ty),
+ prev_opaque_entries,
),
self_ty_is_opaque: false,
autoderefs,
@@ -1246,9 +1259,9 @@ impl<'a, 'db, Choice: ProbeChoice<'db>> ProbeContext<'a, 'db, Choice> {
.filter(|step| step.reachable_via_deref)
.filter(|step| {
debug!("pick_all_method: step={:?}", step);
- // skip types that are from a type error or that would require dereferencing
- // a raw pointer
- !step.self_ty.value.value.references_non_lt_error() && !step.from_unsafe_deref
+ // Skip types with type errors (but not const/lifetime errors, which are
+ // often spurious due to incomplete const evaluation) and raw pointer derefs.
+ !step.self_ty.value.value.references_only_ty_error() && !step.from_unsafe_deref
})
.try_for_each(|step| {
let InferOk { value: self_ty, obligations: instantiate_self_ty_obligations } = self
@@ -1740,7 +1753,7 @@ impl<'a, 'db, Choice: ProbeChoice<'db>> ProbeContext<'a, 'db, Choice> {
/// We want to only accept trait methods if they were hold even if the
/// opaque types were rigid. To handle this, we both check that for trait
/// candidates the goal were to hold even when treating opaques as rigid,
- /// see [OpaqueTypesJank](rustc_trait_selection::solve::OpaqueTypesJank).
+ /// see `rustc_trait_selection::solve::OpaqueTypesJank`.
///
/// We also check that all opaque types encountered as self types in the
/// autoderef chain don't get constrained when applying the candidate.