Skip to content

Commit 669a126

Browse files
committed
Use string sorting exclusively
1 parent 0d90b59 commit 669a126

File tree

5 files changed

+28
-42
lines changed

5 files changed

+28
-42
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::autoderef::Autoderef;
77
use crate::infer::{InferCtxt, InferOk};
88
use crate::traits::{self, normalize_projection_type};
99

10-
use rustc_data_structures::fx::FxHashMap;
10+
use rustc_data_structures::fx::FxHashSet;
1111
use rustc_data_structures::stack::ensure_sufficient_stack;
1212
use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder, Style};
1313
use rustc_hir as hir;
@@ -335,7 +335,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
335335
data: ty::TraitPredicate<'tcx>,
336336
self_ty: Ty<'tcx>,
337337
) -> Vec<String> {
338-
let mut turbofish_suggestions = FxHashMap::default();
338+
let mut turbofish_suggestions = FxHashSet::default();
339339
self.tcx.for_each_relevant_impl(data.trait_ref.def_id, self_ty, |impl_def_id| {
340340
self.probe(|_| {
341341
let impl_substs = self.fresh_substs_for_item(DUMMY_SP, impl_def_id);
@@ -395,24 +395,19 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
395395
)
396396
&& !matches!(trait_ref.self_ty().kind(), ty::Infer(_))
397397
{
398-
turbofish_suggestions.insert(trait_ref.self_ty(), eval_result);
398+
turbofish_suggestions.insert(trait_ref.self_ty());
399399
}
400400
};
401401
}
402402
})
403403
});
404404
// Sort types by always suggesting `Vec<_>` and `String` first, as they are the
405-
// most likely desired types. Otherwise sort first by `EvaluationResult` and then by their
406-
// string representation.
405+
// most likely desired types.
407406
let mut turbofish_suggestions = turbofish_suggestions.into_iter().collect::<Vec<_>>();
408407
turbofish_suggestions.sort_by(|left, right| {
409408
let vec_type = self.tcx.get_diagnostic_item(sym::vec_type);
410409
let string_type = self.tcx.get_diagnostic_item(sym::string_type);
411-
match (&left.0.kind(), &right.0.kind()) {
412-
(
413-
ty::Adt(ty::AdtDef { did: left, .. }, _),
414-
ty::Adt(ty::AdtDef { did: right, .. }, _),
415-
) if left == right => Ordering::Equal,
410+
match (&left.kind(), &right.kind()) {
416411
(
417412
ty::Adt(ty::AdtDef { did: left, .. }, _),
418413
ty::Adt(ty::AdtDef { did: right, .. }, _),
@@ -431,19 +426,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
431426
{
432427
Ordering::Greater
433428
}
434-
_ => {
435-
// We give preferential place in the suggestion list to types that will apply
436-
// without doubt, to push types with abiguities (may or may not apply depending
437-
// on other obligations we don't have access to here) later in the sugg list.
438-
if left.1 == right.1 {
439-
left.0.to_string().cmp(&right.0.to_string())
440-
} else {
441-
left.1.cmp(&right.1)
442-
}
443-
}
429+
_ => left.to_string().cmp(&right.to_string()),
444430
}
445431
});
446-
turbofish_suggestions.into_iter().map(|(ty, _)| ty.to_string()).collect()
432+
turbofish_suggestions.into_iter().map(|ty| ty.to_string()).collect()
447433
}
448434

449435
fn suggest_restricting_param_bound(

src/test/ui/async-await/unresolved_type_param.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ async fn foo() {
1010
//~^ ERROR type inside `async fn` body must be known in this context
1111
//~| ERROR type inside `async fn` body must be known in this context
1212
//~| ERROR type inside `async fn` body must be known in this context
13-
//~| NOTE function `bar` has a type parameter `T` we couldn't infer
14-
//~| NOTE function `bar` has a type parameter `T` we couldn't infer
15-
//~| NOTE function `bar` has a type parameter `T` we couldn't infer
13+
//~| NOTE cannot infer type for type parameter `T` declared on the function `bar
14+
//~| NOTE cannot infer type for type parameter `T` declared on the function `bar
15+
//~| NOTE cannot infer type for type parameter `T` declared on the function `bar
1616
//~| NOTE the type is part of the `async fn` body because of this `await`
1717
//~| NOTE the type is part of the `async fn` body because of this `await`
1818
//~| NOTE the type is part of the `async fn` body because of this `await`

src/test/ui/question-mark-type-infer.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ LL | l.iter().map(f).collect::<ControlFlow<_, _>>()?
1212
| ^^^^^^^^^^^^^^^^^^^^^
1313
LL | l.iter().map(f).collect::<Option<_>>()?
1414
| ^^^^^^^^^^^^^
15-
LL | l.iter().map(f).collect::<Poll<std::result::Result<_, _>>>()?
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1715
LL | l.iter().map(f).collect::<Poll<Option<std::result::Result<_, _>>>>()?
1816
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
LL | l.iter().map(f).collect::<Poll<std::result::Result<_, _>>>()?
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1919
and 1 other candidate
2020

2121
error: aborting due to previous error

src/test/ui/suggestions/appropriate-type-param-turbofish.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ LL | vec!["a", "b", "c"].into_iter().collect::<Vec<_>>();
3030
| ^^^^^^^^^^
3131
LL | vec!["a", "b", "c"].into_iter().collect::<String>();
3232
| ^^^^^^^^^^
33-
LL | vec!["a", "b", "c"].into_iter().collect::<Cow<'_, [_]>>();
34-
| ^^^^^^^^^^^^^^^^
35-
LL | vec!["a", "b", "c"].into_iter().collect::<Cow<'_, str>>();
36-
| ^^^^^^^^^^^^^^^^
33+
LL | vec!["a", "b", "c"].into_iter().collect::<Arc<[_]>>();
34+
| ^^^^^^^^^^^^
35+
LL | vec!["a", "b", "c"].into_iter().collect::<BTreeSet<_>>();
36+
| ^^^^^^^^^^^^^^^
3737
and 10 other candidates
3838

3939
error[E0283]: type annotations needed
@@ -49,10 +49,10 @@ LL | vec!['a', 'b', 'c'].into_iter().collect::<Vec<_>>();
4949
| ^^^^^^^^^^
5050
LL | vec!['a', 'b', 'c'].into_iter().collect::<String>();
5151
| ^^^^^^^^^^
52-
LL | vec!['a', 'b', 'c'].into_iter().collect::<BinaryHeap<_>>();
53-
| ^^^^^^^^^^^^^^^^^
54-
LL | vec!['a', 'b', 'c'].into_iter().collect::<Cow<'_, [_]>>();
55-
| ^^^^^^^^^^^^^^^^
52+
LL | vec!['a', 'b', 'c'].into_iter().collect::<Arc<[_]>>();
53+
| ^^^^^^^^^^^^
54+
LL | vec!['a', 'b', 'c'].into_iter().collect::<BTreeSet<_>>();
55+
| ^^^^^^^^^^^^^^^
5656
and 10 other candidates
5757

5858
error[E0283]: type annotations needed
@@ -87,10 +87,10 @@ LL | let _: Vec<_> = vec!["a", "b", "c"].into_iter().collect();
8787
| ^^^^^^^^
8888
LL | let _: String = vec!["a", "b", "c"].into_iter().collect();
8989
| ^^^^^^^^
90-
LL | let _: BinaryHeap<_> = vec!["a", "b", "c"].into_iter().collect();
91-
| ^^^^^^^^^^^^^^^
92-
LL | let _: Cow<'_, [_]> = vec!["a", "b", "c"].into_iter().collect();
93-
| ^^^^^^^^^^^^^^
90+
LL | let _: Arc<[_]> = vec!["a", "b", "c"].into_iter().collect();
91+
| ^^^^^^^^^^
92+
LL | let _: BTreeSet<_> = vec!["a", "b", "c"].into_iter().collect();
93+
| ^^^^^^^^^^^^^
9494
and 10 other candidates
9595

9696
error[E0283]: type annotations needed
@@ -106,10 +106,10 @@ LL | let _: Vec<_> = vec!['a', 'b', 'c'].into_iter().collect();
106106
| ^^^^^^^^
107107
LL | let _: String = vec!['a', 'b', 'c'].into_iter().collect();
108108
| ^^^^^^^^
109-
LL | let _: BinaryHeap<_> = vec!['a', 'b', 'c'].into_iter().collect();
110-
| ^^^^^^^^^^^^^^^
111-
LL | let _: Box<[_]> = vec!['a', 'b', 'c'].into_iter().collect();
109+
LL | let _: Arc<[_]> = vec!['a', 'b', 'c'].into_iter().collect();
112110
| ^^^^^^^^^^
111+
LL | let _: BTreeSet<_> = vec!['a', 'b', 'c'].into_iter().collect();
112+
| ^^^^^^^^^^^^^
113113
and 10 other candidates
114114

115115
error[E0283]: type annotations needed

src/test/ui/type/type-annotation-needed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ fn foo<T: Into<String>>(x: i32) {}
44
fn main() {
55
foo(42);
66
//~^ ERROR type annotations needed
7-
//~| NOTE function `foo` has a type parameter `T` we couldn't infer
7+
//~| NOTE cannot infer type for type parameter `T` declared on the function `foo`
88
//~| NOTE cannot satisfy
99
}

0 commit comments

Comments
 (0)