Skip to content

Commit

Permalink
Always sort suggestions before emitting them
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 24, 2021
1 parent ef212e7 commit 881a50c
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 35 deletions.
10 changes: 7 additions & 3 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/deprecation/invalid-literal.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions src/test/ui/did_you_mean/issue-42764.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

8 changes: 4 additions & 4 deletions src/test/ui/impl-trait/no-method-suggested-traits.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/issues/issue-73427.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/on-unimplemented/bad-annotation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/traits/issue-77982.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/tools/clippy/tests/ui/nonminimal_bool.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 881a50c

Please sign in to comment.