diff --git a/compiler/rustc_infer/src/traits/error_reporting/mod.rs b/compiler/rustc_infer/src/traits/error_reporting/mod.rs index f40eeb0686a7c..c4174b31564d7 100644 --- a/compiler/rustc_infer/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/traits/error_reporting/mod.rs @@ -137,7 +137,7 @@ pub fn report_object_safety_error<'tcx>( .iter() .map(|t| { with_no_trimmed_paths!(format!( - "\n - {}", + " {}", tcx.type_of(*t).instantiate_identity(), )) }) @@ -145,9 +145,9 @@ pub fn report_object_safety_error<'tcx>( err.help(format!( "the following types implement the trait, consider defining an enum where each \ variant holds one of these types, implementing `{}` for this new enum and using \ - it instead:{}", + it instead:\n{}", trait_str, - types.join(""), + types.join("\n"), )); } } diff --git a/tests/ui/generic-associated-types/gat-in-trait-path.base.stderr b/tests/ui/generic-associated-types/gat-in-trait-path.base.stderr index f59249f9bd909..9013d42953001 100644 --- a/tests/ui/generic-associated-types/gat-in-trait-path.base.stderr +++ b/tests/ui/generic-associated-types/gat-in-trait-path.base.stderr @@ -13,8 +13,8 @@ LL | type A<'a> where Self: 'a; | ^ ...because it contains the generic associated type `A` = help: consider moving `A` to another trait = 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: - - Fooy - - Fooer + Fooy + Fooer error: aborting due to previous error diff --git a/tests/ui/generic-associated-types/issue-79422.base.stderr b/tests/ui/generic-associated-types/issue-79422.base.stderr index c2ed685503513..bcc6382cf7cd2 100644 --- a/tests/ui/generic-associated-types/issue-79422.base.stderr +++ b/tests/ui/generic-associated-types/issue-79422.base.stderr @@ -29,8 +29,8 @@ LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a; | ^^^^^^^^ ...because it contains the generic associated type `VRefCont` = help: consider moving `VRefCont` to another trait = 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: - - std::collections::BTreeMap - - Source + std::collections::BTreeMap + Source error[E0038]: the trait `MapLike` cannot be made into an object --> $DIR/issue-79422.rs:44:13 @@ -47,8 +47,8 @@ LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a; | ^^^^^^^^ ...because it contains the generic associated type `VRefCont` = help: consider moving `VRefCont` to another trait = 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: - - std::collections::BTreeMap - - Source + std::collections::BTreeMap + Source = note: required for the cast from `Box>` to `Box + 'static)>>` error: aborting due to 3 previous errors diff --git a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr b/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr index a712eaa3d5921..37c96d9bc4e95 100644 --- a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr +++ b/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr @@ -12,8 +12,8 @@ LL | trait NotObjectSafe { LL | fn foo() -> Self; | ^^^ ...because associated function `foo` has no `self` parameter = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `NotObjectSafe` for this new enum and using it instead: - - A - - B + A + B help: consider turning `foo` into a method by giving it a `&self` argument | LL | fn foo(&self) -> Self; @@ -37,8 +37,8 @@ LL | trait NotObjectSafe { LL | fn foo() -> Self; | ^^^ ...because associated function `foo` has no `self` parameter = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `NotObjectSafe` for this new enum and using it instead: - - A - - B + A + B help: consider turning `foo` into a method by giving it a `&self` argument | LL | fn foo(&self) -> Self; diff --git a/tests/ui/traits/test-2.stderr b/tests/ui/traits/test-2.stderr index cb9afbbd98a3c..3972e539776c4 100644 --- a/tests/ui/traits/test-2.stderr +++ b/tests/ui/traits/test-2.stderr @@ -43,8 +43,8 @@ LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } = help: consider moving `dup` to another trait = help: consider moving `blah` to another trait = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `bar` for this new enum and using it instead: - - i32 - - u32 + i32 + u32 error[E0038]: the trait `bar` cannot be made into an object --> $DIR/test-2.rs:13:5 @@ -63,8 +63,8 @@ LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } = help: consider moving `dup` to another trait = help: consider moving `blah` to another trait = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `bar` for this new enum and using it instead: - - i32 - - u32 + i32 + u32 error[E0038]: the trait `bar` cannot be made into an object --> $DIR/test-2.rs:13:6 @@ -83,8 +83,8 @@ LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } = help: consider moving `dup` to another trait = help: consider moving `blah` to another trait = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `bar` for this new enum and using it instead: - - i32 - - u32 + i32 + u32 = note: required for the cast from `Box<{integer}>` to `Box` error: aborting due to 5 previous errors diff --git a/tests/ui/wf/wf-unsafe-trait-obj-match.stderr b/tests/ui/wf/wf-unsafe-trait-obj-match.stderr index 78a4a07a787a1..a0279774abebf 100644 --- a/tests/ui/wf/wf-unsafe-trait-obj-match.stderr +++ b/tests/ui/wf/wf-unsafe-trait-obj-match.stderr @@ -30,8 +30,8 @@ LL | trait Trait: Sized {} | | | this trait cannot be made into an object... = 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: - - S - - R + S + R = note: required for the cast from `&S` to `&dyn Trait` error[E0038]: the trait `Trait` cannot be made into an object @@ -52,8 +52,8 @@ LL | trait Trait: Sized {} | | | this trait cannot be made into an object... = 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: - - S - - R + S + R = note: required for the cast from `&R` to `&dyn Trait` error: aborting due to 3 previous errors