Skip to content

Commit 881a50c

Browse files
committed
Always sort suggestions before emitting them
1 parent ef212e7 commit 881a50c

File tree

10 files changed

+39
-35
lines changed

10 files changed

+39
-35
lines changed

compiler/rustc_errors/src/diagnostic.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,14 @@ impl Diagnostic {
465465
suggestions: impl Iterator<Item = String>,
466466
applicability: Applicability,
467467
) -> &mut Self {
468+
let mut suggestions: Vec<_> = suggestions.collect();
469+
suggestions.sort();
470+
let substitutions = suggestions
471+
.into_iter()
472+
.map(|snippet| Substitution { parts: vec![SubstitutionPart { snippet, span: sp }] })
473+
.collect();
468474
self.suggestions.push(CodeSuggestion {
469-
substitutions: suggestions
470-
.map(|snippet| Substitution { parts: vec![SubstitutionPart { snippet, span: sp }] })
471-
.collect(),
475+
substitutions,
472476
msg: msg.to_owned(),
473477
style: SuggestionStyle::ShowCode,
474478
applicability,

src/test/ui/deprecation/invalid-literal.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ LL | #[deprecated = b"test"]
66
|
77
help: the following are the possible correct uses
88
|
9-
LL | #[deprecated]
10-
| ~~~~~~~~~~~~~
11-
LL | #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")]
12-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139
LL | #[deprecated = "reason"]
1410
| ~~~~~~~~~~~~~~~~~~~~~~~~
11+
LL | #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")]
12+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13+
LL | #[deprecated]
14+
| ~~~~~~~~~~~~~
1515

1616
error: aborting due to previous error
1717

src/test/ui/did_you_mean/issue-42764.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | this_function_expects_a_double_option(n);
88
found type `usize`
99
help: try using a variant of the expected enum
1010
|
11-
LL | this_function_expects_a_double_option(DoubleOption::FirstSome(n));
12-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
1311
LL | this_function_expects_a_double_option(DoubleOption::AlternativeSome(n));
1412
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13+
LL | this_function_expects_a_double_option(DoubleOption::FirstSome(n));
14+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
1515

1616
error[E0308]: mismatched types
1717
--> $DIR/issue-42764.rs:27:33

src/test/ui/feature-gates/issue-43106-gating-of-macro_use.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ LL | #[macro_use = "2700"] struct S;
2424
|
2525
help: the following are the possible correct uses
2626
|
27-
LL | #[macro_use] struct S;
28-
| ~~~~~~~~~~~~
2927
LL | #[macro_use(name1, name2, ...)] struct S;
3028
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29+
LL | #[macro_use] struct S;
30+
| ~~~~~~~~~~~~
3131

3232
error: aborting due to 4 previous errors
3333

src/test/ui/impl-trait/no-method-suggested-traits.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ help: the following traits are implemented but not in scope; perhaps add a `use`
99
|
1010
LL | use foo::Bar;
1111
|
12+
LL | use no_method_suggested_traits::Reexported;
13+
|
1214
LL | use no_method_suggested_traits::foo::PubPub;
1315
|
1416
LL | use no_method_suggested_traits::qux::PrivPub;
1517
|
16-
LL | use no_method_suggested_traits::Reexported;
17-
|
1818

1919
error[E0599]: no method named `method` found for struct `Rc<&mut Box<&u32>>` in the current scope
2020
--> $DIR/no-method-suggested-traits.rs:26:44
@@ -27,12 +27,12 @@ help: the following traits are implemented but not in scope; perhaps add a `use`
2727
|
2828
LL | use foo::Bar;
2929
|
30+
LL | use no_method_suggested_traits::Reexported;
31+
|
3032
LL | use no_method_suggested_traits::foo::PubPub;
3133
|
3234
LL | use no_method_suggested_traits::qux::PrivPub;
3335
|
34-
LL | use no_method_suggested_traits::Reexported;
35-
|
3636

3737
error[E0599]: no method named `method` found for type `char` in the current scope
3838
--> $DIR/no-method-suggested-traits.rs:30:9

src/test/ui/issues/issue-73427.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ LL | | }
120120
| |_^
121121
help: try to construct one of the enum's variants
122122
|
123-
LL | let x = A::TupleWithFields(3);
124-
| ~~~~~~~~~~~~~~~~~~
125123
LL | let x = A::Tuple(3);
126124
| ~~~~~~~~
125+
LL | let x = A::TupleWithFields(3);
126+
| ~~~~~~~~~~~~~~~~~~
127127

128128
error[E0532]: expected tuple struct or tuple variant, found enum `A`
129129
--> $DIR/issue-73427.rs:42:12
@@ -145,10 +145,10 @@ LL | | }
145145
| |_^
146146
help: try to match against one of the enum's variants
147147
|
148-
LL | if let A::TupleWithFields(3) = x { }
149-
| ~~~~~~~~~~~~~~~~~~
150148
LL | if let A::Tuple(3) = x { }
151149
| ~~~~~~~~
150+
LL | if let A::TupleWithFields(3) = x { }
151+
| ~~~~~~~~~~~~~~~~~~
152152

153153
error: aborting due to 6 previous errors
154154

src/test/ui/on-unimplemented/bad-annotation.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | #[rustc_on_unimplemented]
66
|
77
help: the following are the possible correct uses
88
|
9-
LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")]
10-
|
119
LL | #[rustc_on_unimplemented = "message"]
1210
|
11+
LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")]
12+
|
1313

1414
error[E0230]: there is no parameter `C` on trait `BadAnnotation2`
1515
--> $DIR/bad-annotation.rs:22:1

src/test/ui/suggestions/core-std-import-order-issue-83564.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | let _x = NonZeroU32::new(5).unwrap();
66
|
77
help: consider importing one of these items
88
|
9-
LL | use std::num::NonZeroU32;
10-
|
119
LL | use core::num::NonZeroU32;
1210
|
11+
LL | use std::num::NonZeroU32;
12+
|
1313

1414
error: aborting due to previous error
1515

src/test/ui/traits/issue-77982.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ LL | opts.get(<String as AsRef<OsStr>>::as_ref(opt));
3131
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3232
LL | opts.get(<String as AsRef<Path>>::as_ref(opt));
3333
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34-
LL | opts.get(<String as AsRef<str>>::as_ref(opt));
35-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3634
LL | opts.get(<String as AsRef<[u8]>>::as_ref(opt));
3735
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36+
LL | opts.get(<String as AsRef<str>>::as_ref(opt));
37+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3838

3939
error[E0283]: type annotations needed
4040
--> $DIR/issue-77982.rs:13:44

src/tools/clippy/tests/ui/nonminimal_bool.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ LL | let _ = a == b && c == 5 && a == b;
5050
|
5151
help: try
5252
|
53-
LL | let _ = a == b && c == 5;
54-
| ~~~~~~~~~~~~~~~~
5553
LL | let _ = !(a != b || c != 5);
5654
| ~~~~~~~~~~~~~~~~~~~
55+
LL | let _ = a == b && c == 5;
56+
| ~~~~~~~~~~~~~~~~
5757

5858
error: this boolean expression can be simplified
5959
--> $DIR/nonminimal_bool.rs:28:13
@@ -63,10 +63,10 @@ LL | let _ = a == b || c == 5 || a == b;
6363
|
6464
help: try
6565
|
66-
LL | let _ = a == b || c == 5;
67-
| ~~~~~~~~~~~~~~~~
6866
LL | let _ = !(a != b && c != 5);
6967
| ~~~~~~~~~~~~~~~~~~~
68+
LL | let _ = a == b || c == 5;
69+
| ~~~~~~~~~~~~~~~~
7070

7171
error: this boolean expression can be simplified
7272
--> $DIR/nonminimal_bool.rs:29:13
@@ -76,10 +76,10 @@ LL | let _ = a == b && c == 5 && b == a;
7676
|
7777
help: try
7878
|
79-
LL | let _ = a == b && c == 5;
80-
| ~~~~~~~~~~~~~~~~
8179
LL | let _ = !(a != b || c != 5);
8280
| ~~~~~~~~~~~~~~~~~~~
81+
LL | let _ = a == b && c == 5;
82+
| ~~~~~~~~~~~~~~~~
8383

8484
error: this boolean expression can be simplified
8585
--> $DIR/nonminimal_bool.rs:30:13
@@ -89,10 +89,10 @@ LL | let _ = a != b || !(a != b || c == d);
8989
|
9090
help: try
9191
|
92-
LL | let _ = a != b || c != d;
93-
| ~~~~~~~~~~~~~~~~
9492
LL | let _ = !(a == b && c == d);
9593
| ~~~~~~~~~~~~~~~~~~~
94+
LL | let _ = a != b || c != d;
95+
| ~~~~~~~~~~~~~~~~
9696

9797
error: this boolean expression can be simplified
9898
--> $DIR/nonminimal_bool.rs:31:13
@@ -102,10 +102,10 @@ LL | let _ = a != b && !(a != b && c == d);
102102
|
103103
help: try
104104
|
105-
LL | let _ = a != b && c != d;
106-
| ~~~~~~~~~~~~~~~~
107105
LL | let _ = !(a == b || c == d);
108106
| ~~~~~~~~~~~~~~~~~~~
107+
LL | let _ = a != b && c != d;
108+
| ~~~~~~~~~~~~~~~~
109109

110110
error: aborting due to 12 previous errors
111111

0 commit comments

Comments
 (0)