Skip to content

Commit 6467f73

Browse files
Assemble method candidates for numerical infer vars
1 parent b01a977 commit 6467f73

File tree

1 file changed

+48
-1
lines changed
  • compiler/rustc_hir_typeck/src/method

1 file changed

+48
-1
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
1818
use rustc_infer::traits::ObligationCauseCode;
1919
use rustc_middle::middle::stability;
2020
use rustc_middle::query::Providers;
21+
use rustc_middle::ty::fast_reject::SimplifiedType;
2122
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
2223
use rustc_middle::ty::AssocItem;
2324
use rustc_middle::ty::AssocItemContainer;
@@ -664,7 +665,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
664665

665666
#[instrument(level = "debug", skip(self))]
666667
fn assemble_probe(&mut self, self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>) {
667-
let raw_self_ty = self_ty.value.value;
668+
let (QueryResponse { value: raw_self_ty, .. }, _) =
669+
self.instantiate_canonical(DUMMY_SP, self_ty);
668670
match *raw_self_ty.kind() {
669671
ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
670672
// Subtle: we can't use `instantiate_query_response` here: using it will
@@ -709,6 +711,47 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
709711
ty::Param(p) => {
710712
self.assemble_inherent_candidates_from_param(p);
711713
}
714+
// which have some integer or float as a self type.
715+
ty::Infer(ty::IntVar(_)) => {
716+
use ty::IntTy::*;
717+
use ty::UintTy::*;
718+
// This causes a compiler error if any new integer kinds are added.
719+
let (I8 | I16 | I32 | I64 | I128 | Isize): ty::IntTy;
720+
let (U8 | U16 | U32 | U64 | U128 | Usize): ty::UintTy;
721+
let possible_integers = [
722+
// signed integers
723+
SimplifiedType::Int(I8),
724+
SimplifiedType::Int(I16),
725+
SimplifiedType::Int(I32),
726+
SimplifiedType::Int(I64),
727+
SimplifiedType::Int(I128),
728+
SimplifiedType::Int(Isize),
729+
// unsigned integers
730+
SimplifiedType::Uint(U8),
731+
SimplifiedType::Uint(U16),
732+
SimplifiedType::Uint(U32),
733+
SimplifiedType::Uint(U64),
734+
SimplifiedType::Uint(U128),
735+
SimplifiedType::Uint(Usize),
736+
];
737+
for simp in possible_integers {
738+
self.assemble_inherent_candidates_for_simplified_type(simp);
739+
}
740+
}
741+
ty::Infer(ty::FloatVar(_)) => {
742+
// This causes a compiler error if any new float kinds are added.
743+
let (ty::FloatTy::F16 | ty::FloatTy::F32 | ty::FloatTy::F64 | ty::FloatTy::F128);
744+
let possible_floats = [
745+
SimplifiedType::Float(ty::FloatTy::F16),
746+
SimplifiedType::Float(ty::FloatTy::F32),
747+
SimplifiedType::Float(ty::FloatTy::F64),
748+
SimplifiedType::Float(ty::FloatTy::F128),
749+
];
750+
751+
for simp in possible_floats {
752+
self.assemble_inherent_candidates_for_simplified_type(simp);
753+
}
754+
}
712755
ty::Bool
713756
| ty::Char
714757
| ty::Int(_)
@@ -729,6 +772,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
729772
let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::AsCandidateKey) else {
730773
bug!("unexpected incoherent type: {:?}", self_ty)
731774
};
775+
self.assemble_inherent_candidates_for_simplified_type(simp);
776+
}
777+
778+
fn assemble_inherent_candidates_for_simplified_type(&mut self, simp: SimplifiedType) {
732779
for &impl_def_id in self.tcx.incoherent_impls(simp).into_iter().flatten() {
733780
self.assemble_inherent_impl_probe(impl_def_id);
734781
}

0 commit comments

Comments
 (0)