Skip to content

Commit 540be28

Browse files
sort suggestions for object diagnostic
1 parent 9322882 commit 540be28

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

compiler/rustc_infer/src/traits/error_reporting/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,13 @@ pub fn report_object_safety_error<'tcx>(
178178
)));
179179
}
180180
impls => {
181-
let types = impls
181+
let mut types = impls
182182
.iter()
183183
.map(|t| {
184184
with_no_trimmed_paths!(format!(" {}", tcx.type_of(*t).instantiate_identity(),))
185185
})
186186
.collect::<Vec<_>>();
187+
types.sort();
187188
err.help(format!(
188189
"the following types implement the trait, consider defining an enum where each \
189190
variant holds one of these types, implementing `{}` for this new enum and using \

tests/ui/generic-associated-types/gat-in-trait-path.base.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ LL | type A<'a> where Self: 'a;
1313
| ^ ...because it contains the generic associated type `A`
1414
= help: consider moving `A` to another trait
1515
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `Foo` for this new enum and using it instead:
16-
Fooy
1716
Fooer<T>
17+
Fooy
1818

1919
error: aborting due to 1 previous error
2020

tests/ui/generic-associated-types/issue-79422.base.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a;
2929
| ^^^^^^^^ ...because it contains the generic associated type `VRefCont`
3030
= help: consider moving `VRefCont` to another trait
3131
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `MapLike` for this new enum and using it instead:
32-
std::collections::BTreeMap<K, V>
3332
Source
33+
std::collections::BTreeMap<K, V>
3434

3535
error[E0038]: the trait `MapLike` cannot be made into an object
3636
--> $DIR/issue-79422.rs:44:13
@@ -47,8 +47,8 @@ LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a;
4747
| ^^^^^^^^ ...because it contains the generic associated type `VRefCont`
4848
= help: consider moving `VRefCont` to another trait
4949
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `MapLike` for this new enum and using it instead:
50-
std::collections::BTreeMap<K, V>
5150
Source
51+
std::collections::BTreeMap<K, V>
5252
= note: required for the cast from `Box<BTreeMap<u8, u8>>` to `Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>`
5353

5454
error: aborting due to 3 previous errors

tests/ui/wf/wf-unsafe-trait-obj-match.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ LL | trait Trait: Sized {}
3030
| |
3131
| this trait cannot be made into an object...
3232
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `Trait` for this new enum and using it instead:
33-
S
3433
R
34+
S
3535
= note: required for the cast from `&S` to `&dyn Trait`
3636

3737
error[E0038]: the trait `Trait` cannot be made into an object
@@ -52,8 +52,8 @@ LL | trait Trait: Sized {}
5252
| |
5353
| this trait cannot be made into an object...
5454
= help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `Trait` for this new enum and using it instead:
55-
S
5655
R
56+
S
5757
= note: required for the cast from `&R` to `&dyn Trait`
5858

5959
error: aborting due to 3 previous errors

0 commit comments

Comments
 (0)