Skip to content

Commit 25fe474

Browse files
Note concrete type being coerced into object
1 parent c06d8f9 commit 25fe474

28 files changed

+50
-49
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,9 +2217,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
22172217
err.span_note(tcx.def_span(item_def_id), &descr);
22182218
}
22192219
}
2220-
ObligationCauseCode::ObjectCastObligation(_, object_ty) => {
2220+
ObligationCauseCode::ObjectCastObligation(concrete_ty, object_ty) => {
22212221
err.note(&format!(
2222-
"required for the cast to the object type `{}`",
2222+
"required for the cast from `{}` to the object type `{}`",
2223+
self.ty_to_string(concrete_ty),
22232224
self.ty_to_string(object_ty)
22242225
));
22252226
}

src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0277]: the trait bound `String: Copy` is not satisfied
44
LL | Box::new(AssocNoCopy)
55
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
66
|
7-
= note: required for the cast to the object type `dyn Bar<Assoc = <AssocNoCopy as Thing>::Out::{opaque#0}>`
7+
= note: required for the cast from `AssocNoCopy` to the object type `dyn Bar<Assoc = <AssocNoCopy as Thing>::Out::{opaque#0}>`
88

99
error: aborting due to previous error
1010

src/test/ui/associated-types/associated-types-eq-3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ note: expected this to be `Bar`
4141
|
4242
LL | type A = usize;
4343
| ^^^^^
44-
= note: required for the cast to the object type `dyn Foo<A = Bar>`
44+
= note: required for the cast from `isize` to the object type `dyn Foo<A = Bar>`
4545

4646
error: aborting due to 3 previous errors
4747

src/test/ui/associated-types/associated-types-overridden-binding-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0271]: type mismatch resolving `<std::vec::IntoIter<u32> as Iterator>::It
44
LL | let _: &dyn I32Iterator<Item = u32> = &vec![42].into_iter();
55
| ^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
66
|
7-
= note: required for the cast to the object type `dyn Iterator<Item = u32, Item = i32>`
7+
= note: required for the cast from `std::vec::IntoIter<u32>` to the object type `dyn Iterator<Item = u32, Item = i32>`
88

99
error: aborting due to previous error
1010

src/test/ui/associated-types/issue-65774-1.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ note: required because of the requirements on the impl of `MyDisplay` for `&mut
2323
|
2424
LL | impl<'a, T: MyDisplay> MyDisplay for &'a mut T { }
2525
| ^^^^^^^^^ ^^^^^^^^^
26-
= note: required for the cast to the object type `dyn MyDisplay`
26+
= note: required for the cast from `&mut T` to the object type `dyn MyDisplay`
2727

2828
error: aborting due to 2 previous errors
2929

src/test/ui/associated-types/issue-65774-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | writer.my_write(valref)
1818
| ^^^^^^ the trait `MyDisplay` is not implemented for `T`
1919
|
2020
= help: the trait `MyDisplay` is implemented for `&'a mut T`
21-
= note: required for the cast to the object type `dyn MyDisplay`
21+
= note: required for the cast from `T` to the object type `dyn MyDisplay`
2222

2323
error: aborting due to 2 previous errors
2424

src/test/ui/async-await/async-block-control-flow-static-semantics.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ error[E0271]: type mismatch resolving `<impl Future<Output = u8> as Future>::Out
3737
LL | let _: &dyn Future<Output = ()> = &block;
3838
| ^^^^^^ expected `()`, found `u8`
3939
|
40-
= note: required for the cast to the object type `dyn Future<Output = ()>`
40+
= note: required for the cast from `impl Future<Output = u8>` to the object type `dyn Future<Output = ()>`
4141

4242
error[E0308]: mismatched types
4343
--> $DIR/async-block-control-flow-static-semantics.rs:12:43
@@ -53,7 +53,7 @@ error[E0271]: type mismatch resolving `<impl Future<Output = u8> as Future>::Out
5353
LL | let _: &dyn Future<Output = ()> = &block;
5454
| ^^^^^^ expected `()`, found `u8`
5555
|
56-
= note: required for the cast to the object type `dyn Future<Output = ()>`
56+
= note: required for the cast from `impl Future<Output = u8>` to the object type `dyn Future<Output = ()>`
5757

5858
error[E0308]: mismatched types
5959
--> $DIR/async-block-control-flow-static-semantics.rs:47:44

src/test/ui/async-await/issue-86507.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ note: captured value is not `Send` because `&` references cannot be sent unless
1313
|
1414
LL | let x = x;
1515
| ^ has type `&T` which is not `Send`, because `T` is not `Sync`
16-
= note: required for the cast to the object type `dyn Future<Output = ()> + Send`
16+
= note: required for the cast from `impl Future<Output = ()>` to the object type `dyn Future<Output = ()> + Send`
1717
help: consider further restricting this bound
1818
|
1919
LL | fn bar<'me, 'async_trait, T: Send + std::marker::Sync>(x: &'me T)

src/test/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ error[E0277]: the trait bound `(): std::error::Error` is not satisfied
44
LL | /* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x)
55
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
66
|
7-
= note: required for the cast to the object type `dyn std::error::Error`
7+
= note: required for the cast from `()` to the object type `dyn std::error::Error`
88

99
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
1010
--> $DIR/coerce-issue-49593-box-never.rs:23:49
1111
|
1212
LL | /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x)
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
1414
|
15-
= note: required for the cast to the object type `(dyn std::error::Error + 'static)`
15+
= note: required for the cast from `()` to the object type `(dyn std::error::Error + 'static)`
1616

1717
error: aborting due to 2 previous errors
1818

src/test/ui/const-generics/defaults/trait_objects_fail.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | foo(&10_u32);
77
| required by a bound introduced by this call
88
|
99
= help: the trait `Trait<2_u8>` is implemented for `u32`
10-
= note: required for the cast to the object type `dyn Trait`
10+
= note: required for the cast from `u32` to the object type `dyn Trait`
1111

1212
error[E0277]: the trait bound `bool: Traitor<{_: u8}>` is not satisfied
1313
--> $DIR/trait_objects_fail.rs:28:9
@@ -18,7 +18,7 @@ LL | bar(&true);
1818
| required by a bound introduced by this call
1919
|
2020
= help: the trait `Traitor<2_u8, 3_u8>` is implemented for `bool`
21-
= note: required for the cast to the object type `dyn Traitor<{_: u8}>`
21+
= note: required for the cast from `bool` to the object type `dyn Traitor<{_: u8}>`
2222

2323
error: aborting due to 2 previous errors
2424

0 commit comments

Comments
 (0)