Always sort suggestions before emitting them

This commit is contained in:
Esteban Kuber 2021-10-01 18:09:31 +00:00
parent ef212e7fb3
commit 881a50c0b7
10 changed files with 39 additions and 35 deletions

View File

@ -465,10 +465,14 @@ impl Diagnostic {
suggestions: impl Iterator<Item = String>,
applicability: Applicability,
) -> &mut Self {
let mut suggestions: Vec<_> = suggestions.collect();
suggestions.sort();
let substitutions = suggestions
.into_iter()
.map(|snippet| Substitution { parts: vec![SubstitutionPart { snippet, span: sp }] })
.collect();
self.suggestions.push(CodeSuggestion {
substitutions: suggestions
.map(|snippet| Substitution { parts: vec![SubstitutionPart { snippet, span: sp }] })
.collect(),
substitutions,
msg: msg.to_owned(),
style: SuggestionStyle::ShowCode,
applicability,

View File

@ -6,12 +6,12 @@ LL | #[deprecated = b"test"]
|
help: the following are the possible correct uses
|
LL | #[deprecated]
| ~~~~~~~~~~~~~
LL | #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")]
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | #[deprecated = "reason"]
| ~~~~~~~~~~~~~~~~~~~~~~~~
LL | #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")]
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | #[deprecated]
| ~~~~~~~~~~~~~
error: aborting due to previous error

View File

@ -8,10 +8,10 @@ LL | this_function_expects_a_double_option(n);
found type `usize`
help: try using a variant of the expected enum
|
LL | this_function_expects_a_double_option(DoubleOption::FirstSome(n));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | this_function_expects_a_double_option(DoubleOption::AlternativeSome(n));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | this_function_expects_a_double_option(DoubleOption::FirstSome(n));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0308]: mismatched types
--> $DIR/issue-42764.rs:27:33

View File

@ -24,10 +24,10 @@ LL | #[macro_use = "2700"] struct S;
|
help: the following are the possible correct uses
|
LL | #[macro_use] struct S;
| ~~~~~~~~~~~~
LL | #[macro_use(name1, name2, ...)] struct S;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | #[macro_use] struct S;
| ~~~~~~~~~~~~
error: aborting due to 4 previous errors

View File

@ -9,12 +9,12 @@ help: the following traits are implemented but not in scope; perhaps add a `use`
|
LL | use foo::Bar;
|
LL | use no_method_suggested_traits::Reexported;
|
LL | use no_method_suggested_traits::foo::PubPub;
|
LL | use no_method_suggested_traits::qux::PrivPub;
|
LL | use no_method_suggested_traits::Reexported;
|
error[E0599]: no method named `method` found for struct `Rc<&mut Box<&u32>>` in the current scope
--> $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`
|
LL | use foo::Bar;
|
LL | use no_method_suggested_traits::Reexported;
|
LL | use no_method_suggested_traits::foo::PubPub;
|
LL | use no_method_suggested_traits::qux::PrivPub;
|
LL | use no_method_suggested_traits::Reexported;
|
error[E0599]: no method named `method` found for type `char` in the current scope
--> $DIR/no-method-suggested-traits.rs:30:9

View File

@ -120,10 +120,10 @@ LL | | }
| |_^
help: try to construct one of the enum's variants
|
LL | let x = A::TupleWithFields(3);
| ~~~~~~~~~~~~~~~~~~
LL | let x = A::Tuple(3);
| ~~~~~~~~
LL | let x = A::TupleWithFields(3);
| ~~~~~~~~~~~~~~~~~~
error[E0532]: expected tuple struct or tuple variant, found enum `A`
--> $DIR/issue-73427.rs:42:12
@ -145,10 +145,10 @@ LL | | }
| |_^
help: try to match against one of the enum's variants
|
LL | if let A::TupleWithFields(3) = x { }
| ~~~~~~~~~~~~~~~~~~
LL | if let A::Tuple(3) = x { }
| ~~~~~~~~
LL | if let A::TupleWithFields(3) = x { }
| ~~~~~~~~~~~~~~~~~~
error: aborting due to 6 previous errors

View File

@ -6,10 +6,10 @@ LL | #[rustc_on_unimplemented]
|
help: the following are the possible correct uses
|
LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")]
|
LL | #[rustc_on_unimplemented = "message"]
|
LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")]
|
error[E0230]: there is no parameter `C` on trait `BadAnnotation2`
--> $DIR/bad-annotation.rs:22:1

View File

@ -6,10 +6,10 @@ LL | let _x = NonZeroU32::new(5).unwrap();
|
help: consider importing one of these items
|
LL | use std::num::NonZeroU32;
|
LL | use core::num::NonZeroU32;
|
LL | use std::num::NonZeroU32;
|
error: aborting due to previous error

View File

@ -31,10 +31,10 @@ 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<str>>::as_ref(opt));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | opts.get(<String as AsRef<[u8]>>::as_ref(opt));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | opts.get(<String as AsRef<str>>::as_ref(opt));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0283]: type annotations needed
--> $DIR/issue-77982.rs:13:44

View File

@ -50,10 +50,10 @@ LL | let _ = a == b && c == 5 && a == b;
|
help: try
|
LL | let _ = a == b && c == 5;
| ~~~~~~~~~~~~~~~~
LL | let _ = !(a != b || c != 5);
| ~~~~~~~~~~~~~~~~~~~
LL | let _ = a == b && c == 5;
| ~~~~~~~~~~~~~~~~
error: this boolean expression can be simplified
--> $DIR/nonminimal_bool.rs:28:13
@ -63,10 +63,10 @@ LL | let _ = a == b || c == 5 || a == b;
|
help: try
|
LL | let _ = a == b || c == 5;
| ~~~~~~~~~~~~~~~~
LL | let _ = !(a != b && c != 5);
| ~~~~~~~~~~~~~~~~~~~
LL | let _ = a == b || c == 5;
| ~~~~~~~~~~~~~~~~
error: this boolean expression can be simplified
--> $DIR/nonminimal_bool.rs:29:13
@ -76,10 +76,10 @@ LL | let _ = a == b && c == 5 && b == a;
|
help: try
|
LL | let _ = a == b && c == 5;
| ~~~~~~~~~~~~~~~~
LL | let _ = !(a != b || c != 5);
| ~~~~~~~~~~~~~~~~~~~
LL | let _ = a == b && c == 5;
| ~~~~~~~~~~~~~~~~
error: this boolean expression can be simplified
--> $DIR/nonminimal_bool.rs:30:13
@ -89,10 +89,10 @@ LL | let _ = a != b || !(a != b || c == d);
|
help: try
|
LL | let _ = a != b || c != d;
| ~~~~~~~~~~~~~~~~
LL | let _ = !(a == b && c == d);
| ~~~~~~~~~~~~~~~~~~~
LL | let _ = a != b || c != d;
| ~~~~~~~~~~~~~~~~
error: this boolean expression can be simplified
--> $DIR/nonminimal_bool.rs:31:13
@ -102,10 +102,10 @@ LL | let _ = a != b && !(a != b && c == d);
|
help: try
|
LL | let _ = a != b && c != d;
| ~~~~~~~~~~~~~~~~
LL | let _ = !(a == b || c == d);
| ~~~~~~~~~~~~~~~~~~~
LL | let _ = a != b && c != d;
| ~~~~~~~~~~~~~~~~
error: aborting due to 12 previous errors