Skip to content

Commit f1ae02f

Browse files
committed
Don't sort span_suggestions, leave that to caller
1 parent 42aa127 commit f1ae02f

File tree

10 files changed

+31
-29
lines changed

10 files changed

+31
-29
lines changed

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -759,9 +759,6 @@ impl Diagnostic {
759759
suggestions: impl IntoIterator<Item = String>,
760760
applicability: Applicability,
761761
) -> &mut Self {
762-
let mut suggestions: Vec<_> = suggestions.into_iter().collect();
763-
suggestions.sort();
764-
765762
self.span_suggestions_with_style(
766763
sp,
767764
msg,
@@ -771,9 +768,7 @@ impl Diagnostic {
771768
)
772769
}
773770

774-
/// [`Diagnostic::span_suggestions()`] but you can set the [`SuggestionStyle`]. This version
775-
/// *doesn't* sort the suggestions, so the caller has control of the order in which they are
776-
/// presented.
771+
/// [`Diagnostic::span_suggestions()`] but you can set the [`SuggestionStyle`].
777772
pub fn span_suggestions_with_style(
778773
&mut self,
779774
sp: Span,

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
945945
Applicability::MachineApplicable,
946946
);
947947
} else {
948-
match (types, traits) {
948+
let mut types = types.to_vec();
949+
types.sort();
950+
let mut traits = traits.to_vec();
951+
traits.sort();
952+
match (&types[..], &traits[..]) {
949953
([], []) => {
950954
err.span_suggestion_verbose(
951955
span,

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2703,7 +2703,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27032703
self.get_field_candidates_considering_privacy(span, ty, mod_id, id)
27042704
{
27052705
let field_names = found_fields.iter().map(|field| field.name).collect::<Vec<_>>();
2706-
let candidate_fields: Vec<_> = found_fields
2706+
let mut candidate_fields: Vec<_> = found_fields
27072707
.into_iter()
27082708
.filter_map(|candidate_field| {
27092709
self.check_for_nested_field_satisfying(
@@ -2724,6 +2724,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27242724
.collect::<String>()
27252725
})
27262726
.collect::<Vec<_>>();
2727+
candidate_fields.sort();
27272728

27282729
let len = candidate_fields.len();
27292730
if len > 0 {

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14261426
if !suggs.is_empty()
14271427
&& let Some(span) = sugg_span
14281428
{
1429+
suggs.sort();
14291430
err.span_suggestions(
14301431
span.with_hi(item_name.span.lo()),
14311432
"use fully-qualified syntax to disambiguate",
@@ -2000,8 +2001,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20002001
self.tcx.get_diagnostic_item(sym::Borrow),
20012002
self.tcx.get_diagnostic_item(sym::BorrowMut),
20022003
];
2003-
let candidate_fields: Vec<_> = fields
2004-
.iter()
2004+
let mut candidate_fields: Vec<_> = fields
20052005
.filter_map(|candidate_field| {
20062006
self.check_for_nested_field_satisfying(
20072007
span,
@@ -2035,6 +2035,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20352035
.join(".")
20362036
})
20372037
.collect();
2038+
candidate_fields.sort();
20382039

20392040
let len = candidate_fields.len();
20402041
if len > 0 {
@@ -2567,13 +2568,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25672568
self.tcx.item_name(*trait_did),
25682569
)
25692570
});
2571+
let mut sugg: Vec<_> = path_strings.chain(glob_path_strings).collect();
2572+
sugg.sort();
25702573

2571-
err.span_suggestions(
2572-
span,
2573-
msg,
2574-
path_strings.chain(glob_path_strings),
2575-
Applicability::MaybeIncorrect,
2576-
);
2574+
err.span_suggestions(span, msg, sugg, Applicability::MaybeIncorrect);
25772575
}
25782576

25792577
fn suggest_valid_traits(

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,10 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
442442

443443
self.formatting_init.extend(code_init);
444444
Ok(quote! {
445-
let mut code: Vec<_> = #code_field.into_iter().collect();
446-
code.sort();
447445
#diag.span_suggestions_with_style(
448446
#span_field,
449447
crate::fluent_generated::#slug,
450-
code,
448+
#code_field,
451449
#applicability,
452450
#style
453451
);

compiler/rustc_parse/src/validate_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ fn emit_malformed_attribute(
186186
msg.push_str(&format!("`{code}`"));
187187
suggestions.push(code);
188188
}
189+
suggestions.sort();
189190
if should_warn(name) {
190191
sess.buffer_lint(&ILL_FORMED_ATTRIBUTE_INPUT, span, ast::CRATE_NODE_ID, msg);
191192
} else {

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,9 +1639,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
16391639
} else {
16401640
3
16411641
};
1642-
return Some((order, item.name));
1642+
Some((order, item.name))
1643+
} else {
1644+
None
16431645
}
1644-
None
16451646
})
16461647
.collect::<Vec<_>>();
16471648
items.sort_by_key(|(order, _)| *order);
@@ -2147,11 +2148,12 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
21472148
if suggest_only_tuple_variants {
21482149
// Suggest only tuple variants regardless of whether they have fields and do not
21492150
// suggest path with added parentheses.
2150-
let suggestable_variants = variants
2151+
let mut suggestable_variants = variants
21512152
.iter()
21522153
.filter(|(.., kind)| *kind == CtorKind::Fn)
21532154
.map(|(variant, ..)| path_names_to_string(variant))
21542155
.collect::<Vec<_>>();
2156+
suggestable_variants.sort();
21552157

21562158
let non_suggestable_variant_count = variants.len() - suggestable_variants.len();
21572159

@@ -2202,7 +2204,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
22022204
}
22032205
};
22042206

2205-
let suggestable_variants = variants
2207+
let mut suggestable_variants = variants
22062208
.iter()
22072209
.filter(|(_, def_id, kind)| !needs_placeholder(*def_id, *kind))
22082210
.map(|(variant, _, kind)| (path_names_to_string(variant), kind))
@@ -2211,6 +2213,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
22112213
CtorKind::Fn => format!("({variant}())"),
22122214
})
22132215
.collect::<Vec<_>>();
2216+
suggestable_variants.sort();
22142217
let no_suggestable_variant = suggestable_variants.is_empty();
22152218

22162219
if !no_suggestable_variant {
@@ -2228,7 +2231,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
22282231
);
22292232
}
22302233

2231-
let suggestable_variants_with_placeholders = variants
2234+
let mut suggestable_variants_with_placeholders = variants
22322235
.iter()
22332236
.filter(|(_, def_id, kind)| needs_placeholder(*def_id, *kind))
22342237
.map(|(variant, _, kind)| (path_names_to_string(variant), kind))
@@ -2237,6 +2240,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
22372240
_ => None,
22382241
})
22392242
.collect::<Vec<_>>();
2243+
suggestable_variants_with_placeholders.sort();
22402244

22412245
if !suggestable_variants_with_placeholders.is_empty() {
22422246
let msg =

src/tools/clippy/clippy_lints/src/booleans.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,9 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
424424
improvements.push(suggestion);
425425
}
426426
}
427-
let nonminimal_bool_lint = |suggestions: Vec<_>| {
427+
let nonminimal_bool_lint = |mut suggestions: Vec<_>| {
428428
if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).0 != Level::Allow {
429+
suggestions.sort();
429430
span_lint_hir_and_then(
430431
self.cx,
431432
NONMINIMAL_BOOL,

tests/ui/parser/bad-pointer-type.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | fn foo(_: *()) {
66
|
77
help: add `mut` or `const` here
88
|
9-
LL | fn foo(_: *const ()) {
10-
| +++++
119
LL | fn foo(_: *mut ()) {
1210
| +++
11+
LL | fn foo(_: *const ()) {
12+
| +++++
1313

1414
error: aborting due to previous error
1515

tests/ui/parser/double-pointer.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | let dptr: **const i32 = &ptr;
66
|
77
help: add `mut` or `const` here
88
|
9-
LL | let dptr: *const *const i32 = &ptr;
10-
| +++++
119
LL | let dptr: *mut *const i32 = &ptr;
1210
| +++
11+
LL | let dptr: *const *const i32 = &ptr;
12+
| +++++
1313

1414
error: aborting due to previous error
1515

0 commit comments

Comments
 (0)