Skip to content

Commit a8d6070

Browse files
committed
Refactor candidate selection
1 parent 25e4389 commit a8d6070

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/librustc/middle/traits/error_reporting.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,23 +240,24 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
240240
let mut impl_candidates = Vec::new();
241241
let trait_def = infcx.tcx.lookup_trait_def(trait_ref.def_id());
242242

243-
trait_def.for_each_impl(infcx.tcx, |def_id| {
244-
let imp = infcx.tcx.impl_trait_ref(def_id).unwrap();
245-
if let Some(simp) = simp {
243+
match simp {
244+
Some(simp) => trait_def.for_each_impl(infcx.tcx, |def_id| {
245+
let imp = infcx.tcx.impl_trait_ref(def_id).unwrap();
246246
let imp_simp = fast_reject::simplify_type(infcx.tcx,
247247
imp.self_ty(),
248248
true);
249249
if let Some(imp_simp) = imp_simp {
250-
if simp == imp_simp {
251-
impl_candidates.push(imp);
250+
if simp != imp_simp {
251+
return;
252252
}
253-
} else {
254-
impl_candidates.push(imp);
255253
}
256-
} else {
257254
impl_candidates.push(imp);
258-
}
259-
});
255+
}),
256+
None => trait_def.for_each_impl(infcx.tcx, |def_id| {
257+
impl_candidates.push(
258+
infcx.tcx.impl_trait_ref(def_id).unwrap());
259+
})
260+
};
260261

261262
if impl_candidates.len() > 0 {
262263
err.fileline_help(
@@ -266,7 +267,7 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
266267
let end = cmp::min(4, impl_candidates.len());
267268
for candidate in &impl_candidates[0..end] {
268269
err.fileline_help(obligation.cause.span,
269-
candidate);
270+
&format!(" {:?}", candidate));
270271
}
271272
if impl_candidates.len() > 4 {
272273
err.fileline_help(obligation.cause.span,

0 commit comments

Comments
 (0)