Skip to content

Commit 874ee58

Browse files
committed
Simplify unstable methods list
This PR is not intended to make any functional difference, but it replaces a reference with an owned Vec for a slight code simplification. This will become more useful in subsequent work towards arbitrary self types.
1 parent 5367673 commit 874ee58

File tree

1 file changed

+25
-32
lines changed
  • compiler/rustc_hir_typeck/src/method

1 file changed

+25
-32
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,12 +1045,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10451045

10461046
fn pick_core(&self) -> Option<PickResult<'tcx>> {
10471047
// Pick stable methods only first, and consider unstable candidates if not found.
1048-
self.pick_all_method(Some(&mut vec![])).or_else(|| self.pick_all_method(None))
1048+
self.pick_all_method(Some(vec![])).or_else(|| self.pick_all_method(None))
10491049
}
10501050

10511051
fn pick_all_method(
10521052
&self,
1053-
mut unstable_candidates: Option<&mut Vec<(Candidate<'tcx>, Symbol)>>,
1053+
mut unstable_candidates: Option<Vec<(Candidate<'tcx>, Symbol)>>,
10541054
) -> Option<PickResult<'tcx>> {
10551055
self.steps
10561056
.iter()
@@ -1071,30 +1071,23 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10711071
.unwrap_or_else(|_| {
10721072
span_bug!(self.span, "{:?} was applicable but now isn't?", step.self_ty)
10731073
});
1074-
self.pick_by_value_method(step, self_ty, unstable_candidates.as_deref_mut())
1074+
self.pick_by_value_method(step, self_ty, &mut unstable_candidates).or_else(|| {
1075+
self.pick_autorefd_method(
1076+
step,
1077+
self_ty,
1078+
hir::Mutability::Not,
1079+
&mut unstable_candidates,
1080+
)
10751081
.or_else(|| {
10761082
self.pick_autorefd_method(
10771083
step,
10781084
self_ty,
1079-
hir::Mutability::Not,
1080-
unstable_candidates.as_deref_mut(),
1085+
hir::Mutability::Mut,
1086+
&mut unstable_candidates,
10811087
)
1082-
.or_else(|| {
1083-
self.pick_autorefd_method(
1084-
step,
1085-
self_ty,
1086-
hir::Mutability::Mut,
1087-
unstable_candidates.as_deref_mut(),
1088-
)
1089-
})
1090-
.or_else(|| {
1091-
self.pick_const_ptr_method(
1092-
step,
1093-
self_ty,
1094-
unstable_candidates.as_deref_mut(),
1095-
)
1096-
})
10971088
})
1089+
.or_else(|| self.pick_const_ptr_method(step, self_ty, &mut unstable_candidates))
1090+
})
10981091
})
10991092
}
11001093

@@ -1108,7 +1101,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11081101
&self,
11091102
step: &CandidateStep<'tcx>,
11101103
self_ty: Ty<'tcx>,
1111-
unstable_candidates: Option<&mut Vec<(Candidate<'tcx>, Symbol)>>,
1104+
unstable_candidates: &mut Option<Vec<(Candidate<'tcx>, Symbol)>>,
11121105
) -> Option<PickResult<'tcx>> {
11131106
if step.unsize {
11141107
return None;
@@ -1137,7 +1130,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11371130
step: &CandidateStep<'tcx>,
11381131
self_ty: Ty<'tcx>,
11391132
mutbl: hir::Mutability,
1140-
unstable_candidates: Option<&mut Vec<(Candidate<'tcx>, Symbol)>>,
1133+
unstable_candidates: &mut Option<Vec<(Candidate<'tcx>, Symbol)>>,
11411134
) -> Option<PickResult<'tcx>> {
11421135
let tcx = self.tcx;
11431136

@@ -1162,7 +1155,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11621155
&self,
11631156
step: &CandidateStep<'tcx>,
11641157
self_ty: Ty<'tcx>,
1165-
unstable_candidates: Option<&mut Vec<(Candidate<'tcx>, Symbol)>>,
1158+
unstable_candidates: &mut Option<Vec<(Candidate<'tcx>, Symbol)>>,
11661159
) -> Option<PickResult<'tcx>> {
11671160
// Don't convert an unsized reference to ptr
11681161
if step.unsize {
@@ -1186,7 +1179,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11861179
fn pick_method(
11871180
&self,
11881181
self_ty: Ty<'tcx>,
1189-
mut unstable_candidates: Option<&mut Vec<(Candidate<'tcx>, Symbol)>>,
1182+
unstable_candidates: &mut Option<Vec<(Candidate<'tcx>, Symbol)>>,
11901183
) -> Option<PickResult<'tcx>> {
11911184
debug!("pick_method(self_ty={})", self.ty_to_string(self_ty));
11921185

@@ -1200,7 +1193,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12001193
self_ty,
12011194
candidates,
12021195
&mut possibly_unsatisfied_predicates,
1203-
unstable_candidates.as_deref_mut(),
1196+
unstable_candidates,
12041197
);
12051198
if let Some(pick) = res {
12061199
return Some(pick);
@@ -1209,7 +1202,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12091202

12101203
if self.private_candidate.get().is_none() {
12111204
if let Some(Ok(pick)) =
1212-
self.consider_candidates(self_ty, &self.private_candidates, &mut vec![], None)
1205+
self.consider_candidates(self_ty, &self.private_candidates, &mut vec![], &mut None)
12131206
{
12141207
self.private_candidate.set(Some((pick.item.kind.as_def_kind(), pick.item.def_id)));
12151208
}
@@ -1232,7 +1225,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12321225
Option<ty::Predicate<'tcx>>,
12331226
Option<ObligationCause<'tcx>>,
12341227
)>,
1235-
mut unstable_candidates: Option<&mut Vec<(Candidate<'tcx>, Symbol)>>,
1228+
unstable_candidates: &mut Option<Vec<(Candidate<'tcx>, Symbol)>>,
12361229
) -> Option<PickResult<'tcx>> {
12371230
let mut applicable_candidates: Vec<_> = candidates
12381231
.iter()
@@ -1252,7 +1245,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12521245
}
12531246
}
12541247

1255-
if let Some(uc) = &mut unstable_candidates {
1248+
if let Some(uc) = unstable_candidates {
12561249
applicable_candidates.retain(|&(candidate, _)| {
12571250
if let stability::EvalResult::Deny { feature, .. } =
12581251
self.tcx.eval_stability(candidate.item.def_id, None, self.span, None)
@@ -1270,10 +1263,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12701263
}
12711264

12721265
applicable_candidates.pop().map(|(probe, status)| match status {
1273-
ProbeResult::Match => {
1274-
Ok(probe
1275-
.to_unadjusted_pick(self_ty, unstable_candidates.cloned().unwrap_or_default()))
1276-
}
1266+
ProbeResult::Match => Ok(probe.to_unadjusted_pick(
1267+
self_ty,
1268+
unstable_candidates.as_ref().cloned().unwrap_or_default(),
1269+
)),
12771270
ProbeResult::NoMatch | ProbeResult::BadReturnType => Err(MethodError::BadReturnType),
12781271
})
12791272
}

0 commit comments

Comments
 (0)