Skip to content

Commit 4fc13d4

Browse files
committed
Don't sort span_suggestions, leave that to caller
1 parent 3a00daf commit 4fc13d4

File tree

10 files changed

+31
-28
lines changed

10 files changed

+31
-28
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
@@ -2720,7 +2720,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27202720
if let Some((fields, args)) =
27212721
self.get_field_candidates_considering_privacy(span, expr_t, mod_id)
27222722
{
2723-
let candidate_fields: Vec<_> = fields
2723+
let mut candidate_fields: Vec<_> = fields
27242724
.filter_map(|candidate_field| {
27252725
self.check_for_nested_field_satisfying(
27262726
span,
@@ -2740,6 +2740,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27402740
.join(".")
27412741
})
27422742
.collect::<Vec<_>>();
2743+
candidate_fields.sort();
27432744

27442745
let len = candidate_fields.len();
27452746
if len > 0 {

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13781378
}
13791379
}
13801380
if !suggs.is_empty() && let Some(span) = sugg_span {
1381+
suggs.sort();
13811382
err.span_suggestions(
13821383
span.with_hi(item_name.span.lo()),
13831384
"use fully-qualified syntax to disambiguate",
@@ -1952,7 +1953,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19521953
self.tcx.get_diagnostic_item(sym::Borrow),
19531954
self.tcx.get_diagnostic_item(sym::BorrowMut),
19541955
];
1955-
let candidate_fields: Vec<_> = fields
1956+
let mut candidate_fields: Vec<_> = fields
19561957
.filter_map(|candidate_field| {
19571958
self.check_for_nested_field_satisfying(
19581959
span,
@@ -1985,6 +1986,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19851986
.join(".")
19861987
})
19871988
.collect();
1989+
candidate_fields.sort();
19881990

19891991
let len = candidate_fields.len();
19901992
if len > 0 {
@@ -2516,13 +2518,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25162518
self.tcx.item_name(*trait_did),
25172519
)
25182520
});
2521+
let mut sugg: Vec<_> = path_strings.chain(glob_path_strings).collect();
2522+
sugg.sort();
25192523

2520-
err.span_suggestions(
2521-
span,
2522-
msg,
2523-
path_strings.chain(glob_path_strings),
2524-
Applicability::MaybeIncorrect,
2525-
);
2524+
err.span_suggestions(span, msg, sugg, Applicability::MaybeIncorrect);
25262525
}
25272526

25282527
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
@@ -441,12 +441,10 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
441441

442442
self.formatting_init.extend(code_init);
443443
Ok(quote! {
444-
let mut code: Vec<_> = #code_field.into_iter().collect();
445-
code.sort();
446444
#diag.span_suggestions_with_style(
447445
#span_field,
448446
crate::fluent_generated::#slug,
449-
code,
447+
#code_field,
450448
#applicability,
451449
#style
452450
);

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
@@ -1612,9 +1612,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
16121612
} else {
16131613
3
16141614
};
1615-
return Some((order, item.name));
1615+
Some((order, item.name))
1616+
} else {
1617+
None
16161618
}
1617-
None
16181619
})
16191620
.collect::<Vec<_>>();
16201621
items.sort_by_key(|(order, _)| *order);
@@ -2120,11 +2121,12 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
21202121
if suggest_only_tuple_variants {
21212122
// Suggest only tuple variants regardless of whether they have fields and do not
21222123
// suggest path with added parentheses.
2123-
let suggestable_variants = variants
2124+
let mut suggestable_variants = variants
21242125
.iter()
21252126
.filter(|(.., kind)| *kind == CtorKind::Fn)
21262127
.map(|(variant, ..)| path_names_to_string(variant))
21272128
.collect::<Vec<_>>();
2129+
suggestable_variants.sort();
21282130

21292131
let non_suggestable_variant_count = variants.len() - suggestable_variants.len();
21302132

@@ -2175,7 +2177,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
21752177
}
21762178
};
21772179

2178-
let suggestable_variants = variants
2180+
let mut suggestable_variants = variants
21792181
.iter()
21802182
.filter(|(_, def_id, kind)| !needs_placeholder(*def_id, *kind))
21812183
.map(|(variant, _, kind)| (path_names_to_string(variant), kind))
@@ -2184,6 +2186,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
21842186
CtorKind::Fn => format!("({variant}())"),
21852187
})
21862188
.collect::<Vec<_>>();
2189+
suggestable_variants.sort();
21872190
let no_suggestable_variant = suggestable_variants.is_empty();
21882191

21892192
if !no_suggestable_variant {
@@ -2201,7 +2204,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
22012204
);
22022205
}
22032206

2204-
let suggestable_variants_with_placeholders = variants
2207+
let mut suggestable_variants_with_placeholders = variants
22052208
.iter()
22062209
.filter(|(_, def_id, kind)| needs_placeholder(*def_id, *kind))
22072210
.map(|(variant, _, kind)| (path_names_to_string(variant), kind))
@@ -2210,6 +2213,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
22102213
_ => None,
22112214
})
22122215
.collect::<Vec<_>>();
2216+
suggestable_variants_with_placeholders.sort();
22132217

22142218
if !suggestable_variants_with_placeholders.is_empty() {
22152219
let msg =

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,9 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
427427
improvements.push(suggestion);
428428
}
429429
}
430-
let nonminimal_bool_lint = |suggestions: Vec<_>| {
430+
let nonminimal_bool_lint = |mut suggestions: Vec<_>| {
431431
if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).0 != Level::Allow {
432+
suggestions.sort();
432433
span_lint_hir_and_then(
433434
self.cx,
434435
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)