Skip to content

Commit 7e499d1

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 a773b15 commit 7e499d1

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
@@ -499,11 +499,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
499499
let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
500500

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

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

@@ -855,14 +853,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
855853
self.assemble_candidates_for_bounds(
856854
traits::supertraits(self.tcx, trait_ref),
857855
|this, new_trait_ref, item| {
858-
this.push_candidate(
859-
Candidate {
860-
item,
861-
kind: ObjectCandidate(new_trait_ref),
862-
import_ids: smallvec![],
863-
},
864-
true,
865-
);
856+
this.push_candidate(item, ObjectCandidate(new_trait_ref), smallvec![], true);
866857
},
867858
);
868859
}
@@ -891,14 +882,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
891882
});
892883

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

@@ -985,11 +969,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
985969
));
986970
} else {
987971
self.push_candidate(
988-
Candidate {
989-
item,
990-
import_ids: import_ids.clone(),
991-
kind: TraitCandidate(bound_trait_ref),
992-
},
972+
item,
973+
TraitCandidate(bound_trait_ref),
974+
import_ids.clone(),
993975
false,
994976
);
995977
}
@@ -1008,11 +990,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1008990
continue;
1009991
}
1010992
self.push_candidate(
1011-
Candidate {
1012-
item,
1013-
import_ids: import_ids.clone(),
1014-
kind: TraitCandidate(ty::Binder::dummy(trait_ref)),
1015-
},
993+
item,
994+
TraitCandidate(ty::Binder::dummy(trait_ref)),
995+
import_ids.clone(),
1016996
false,
1017997
);
1018998
}

0 commit comments

Comments
 (0)