Provide consistent output order for suggestions

This commit is contained in:
Esteban Küber 2022-04-23 17:54:11 -07:00
parent 1e1f33f584
commit a721383261
2 changed files with 12 additions and 11 deletions

View File

@ -738,7 +738,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
{
let mut eraser = TypeParamEraser(self.tcx);
let candidate_len = impl_candidates.len();
let suggestions = impl_candidates.iter().map(|candidate| {
let mut suggestions: Vec<_> = impl_candidates.iter().map(|candidate| {
let candidate = candidate.super_fold_with(&mut eraser);
vec![
(expr.span.shrink_to_lo(), format!("{}::{}(", candidate, segment.ident)),
@ -748,13 +748,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
(expr.span.shrink_to_hi().with_hi(exprs[1].span.lo()), ", ".to_string())
},
]
});
}).collect();
suggestions.sort_by(|a, b| a[0].1.cmp(&b[0].1));
err.multipart_suggestions(
&format!(
"use the fully qualified path for the potential candidate{}",
pluralize!(candidate_len),
),
suggestions,
suggestions.into_iter(),
Applicability::MaybeIncorrect,
);
}

View File

@ -36,14 +36,14 @@ LL | opts.get(opt.as_ref());
- impl AsRef<str> for String;
help: use the fully qualified path for the potential candidates
|
LL | opts.get(<str as AsRef<Path>>::as_ref(opt));
| +++++++++++++++++++++++++++++ ~
LL | opts.get(<str as AsRef<OsStr>>::as_ref(opt));
| ++++++++++++++++++++++++++++++ ~
LL | opts.get(<str as AsRef<str>>::as_ref(opt));
| ++++++++++++++++++++++++++++ ~
LL | opts.get(<str as AsRef<[u8]>>::as_ref(opt));
| +++++++++++++++++++++++++++++ ~
LL | opts.get(<String as AsRef<OsStr>>::as_ref(opt));
| +++++++++++++++++++++++++++++++++ ~
LL | opts.get(<String as AsRef<Path>>::as_ref(opt));
| ++++++++++++++++++++++++++++++++ ~
LL | opts.get(<String as AsRef<[u8]>>::as_ref(opt));
| ++++++++++++++++++++++++++++++++ ~
LL | opts.get(<String as AsRef<str>>::as_ref(opt));
| +++++++++++++++++++++++++++++++ ~
and 4 other candidates
error[E0283]: type annotations needed