Skip to content

Commit 51d4cc7

Browse files
committed
Arbitrary self types v2: abstract PushCandidate
This commit has no functional changes. It moves the creation of a Candidate struct into push_candidate. In a subsequent change, we'll build the Candidate in a slightly more sophisticated way which it's better to do in one place.
1 parent 9fb1d82 commit 51d4cc7

File tree

1 file changed

+20
-40
lines changed
  • compiler/rustc_hir_typeck/src/method

1 file changed

+20
-40
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+20-40
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
498498
let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
499499

500500
probe_cx.push_candidate(
501-
Candidate {
502-
item,
503-
kind: CandidateKind::TraitCandidate(ty::Binder::dummy(trait_ref)),
504-
import_ids: smallvec![],
505-
},
501+
item,
502+
CandidateKind::TraitCandidate(ty::Binder::dummy(trait_ref)),
503+
smallvec![],
506504
false,
507505
);
508506
}
@@ -700,7 +698,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
700698
///////////////////////////////////////////////////////////////////////////
701699
// CANDIDATE ASSEMBLY
702700

703-
fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) {
701+
fn push_candidate(
702+
&mut self,
703+
item: ty::AssocItem,
704+
kind: CandidateKind<'tcx>,
705+
import_ids: SmallVec<[LocalDefId; 1]>,
706+
is_inherent: bool,
707+
) {
708+
let candidate = Candidate { item, kind, import_ids };
704709
let is_accessible = if let Some(name) = self.method_name {
705710
let item = candidate.item;
706711
let hir_id = self.tcx.local_def_id_to_hir_id(self.body_id);
@@ -818,14 +823,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
818823
self.record_static_candidate(CandidateSource::Impl(impl_def_id));
819824
continue;
820825
}
821-
self.push_candidate(
822-
Candidate {
823-
item,
824-
kind: InherentImplCandidate(impl_def_id),
825-
import_ids: smallvec![],
826-
},
827-
true,
828-
);
826+
self.push_candidate(item, InherentImplCandidate(impl_def_id), smallvec![], true);
829827
}
830828
}
831829

@@ -854,14 +852,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
854852
self.assemble_candidates_for_bounds(
855853
traits::supertraits(self.tcx, trait_ref),
856854
|this, new_trait_ref, item| {
857-
this.push_candidate(
858-
Candidate {
859-
item,
860-
kind: ObjectCandidate(new_trait_ref),
861-
import_ids: smallvec![],
862-
},
863-
true,
864-
);
855+
this.push_candidate(item, ObjectCandidate(new_trait_ref), smallvec![], true);
865856
},
866857
);
867858
}
@@ -890,14 +881,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
890881
});
891882

892883
self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
893-
this.push_candidate(
894-
Candidate {
895-
item,
896-
kind: WhereClauseCandidate(poly_trait_ref),
897-
import_ids: smallvec![],
898-
},
899-
true,
900-
);
884+
this.push_candidate(item, WhereClauseCandidate(poly_trait_ref), smallvec![], true);
901885
});
902886
}
903887

@@ -984,11 +968,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
984968
));
985969
} else {
986970
self.push_candidate(
987-
Candidate {
988-
item,
989-
import_ids: import_ids.clone(),
990-
kind: TraitCandidate(bound_trait_ref),
991-
},
971+
item,
972+
TraitCandidate(bound_trait_ref),
973+
import_ids.clone(),
992974
false,
993975
);
994976
}
@@ -1007,11 +989,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1007989
continue;
1008990
}
1009991
self.push_candidate(
1010-
Candidate {
1011-
item,
1012-
import_ids: import_ids.clone(),
1013-
kind: TraitCandidate(ty::Binder::dummy(trait_ref)),
1014-
},
992+
item,
993+
TraitCandidate(ty::Binder::dummy(trait_ref)),
994+
import_ids.clone(),
1015995
false,
1016996
);
1017997
}

0 commit comments

Comments
 (0)