From 3ea2c8c538ac0afe1c4522a9c60b98005f270da3 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 5 Jul 2022 09:59:12 -0700 Subject: [PATCH 1/2] Revert "Note concrete type being coerced into object" This reverts commit 862873d20bb40c9f9331b36fc05c53288960d3aa. --- .../src/traits/error_reporting/suggestions.rs | 5 ++--- .../assoc-type-eq-with-dyn-atb-fail.stderr | 7 +++++++ .../ui/associated-types/associated-types-eq-3.stderr | 2 +- .../associated-types-overridden-binding-2.stderr | 2 +- src/test/ui/associated-types/issue-65774-1.stderr | 2 +- src/test/ui/associated-types/issue-65774-2.stderr | 2 +- .../async-block-control-flow-static-semantics.stderr | 4 ++-- src/test/ui/async-await/issue-86507.stderr | 2 +- ...e-issue-49593-box-never-windows.nofallback.stderr | 4 ++-- .../coerce-issue-49593-box-never.nofallback.stderr | 4 ++-- .../defaults/trait_objects_fail.stderr | 4 ++-- src/test/ui/custom_test_frameworks/mismatch.stderr | 2 +- src/test/ui/dst/dst-bad-coerce1.stderr | 4 ++-- src/test/ui/dst/dst-object-from-unsized-type.stderr | 8 ++++---- .../issue-79422.extended.stderr | 2 +- src/test/ui/issues/issue-14366.stderr | 2 +- src/test/ui/issues/issue-22034.stderr | 2 +- src/test/ui/issues/issue-22872.stderr | 2 +- src/test/ui/issues/issue-7013.stderr | 2 +- src/test/ui/kindck/kindck-impl-type-params.stderr | 12 ++++++------ src/test/ui/mismatched_types/cast-rfc0401.stderr | 4 ++-- .../never_type/fallback-closure-wrap.fallback.stderr | 2 +- .../suggestions/derive-macro-missing-bounds.stderr | 8 ++++---- .../suggestions/suggest-borrow-to-dyn-object.stderr | 2 +- src/test/ui/traits/coercion-generic-bad.stderr | 2 +- src/test/ui/traits/map-types.stderr | 2 +- .../trait-upcasting/type-checking-test-1.stderr | 2 +- .../trait-upcasting/type-checking-test-2.stderr | 4 ++-- src/test/ui/unsized/unsized-fn-param.stderr | 8 ++++---- src/tools/cargo | 2 +- src/tools/miri | 2 +- src/tools/rls | 2 +- 32 files changed, 60 insertions(+), 54 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index a8be6f74c99a0..83e12153bf2ea 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2216,10 +2216,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err.span_note(tcx.def_span(item_def_id), &descr); } } - ObligationCauseCode::ObjectCastObligation(concrete_ty, object_ty) => { + ObligationCauseCode::ObjectCastObligation(_, object_ty) => { err.note(&format!( - "required for the cast from `{}` to the object type `{}`", - self.ty_to_string(concrete_ty), + "required for the cast to the object type `{}`", self.ty_to_string(object_ty) )); } diff --git a/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr b/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr index a32ab453152a0..f00715a9e3510 100644 --- a/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr +++ b/src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr @@ -1,8 +1,15 @@ error[E0277]: the trait bound `String: Copy` is not satisfied --> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:32:18 | +<<<<<<< HEAD LL | fn func() -> Self::Out { | ^^^^^^^^^ the trait `Copy` is not implemented for `String` +======= +LL | Box::new(AssocNoCopy) + | ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` + | + = note: required for the cast to the object type `dyn Bar::Out::{opaque#0}>` +>>>>>>> parent of 862873d20bb (Note concrete type being coerced into object) error: aborting due to previous error diff --git a/src/test/ui/associated-types/associated-types-eq-3.stderr b/src/test/ui/associated-types/associated-types-eq-3.stderr index bed63a5e6df03..521907a60445c 100644 --- a/src/test/ui/associated-types/associated-types-eq-3.stderr +++ b/src/test/ui/associated-types/associated-types-eq-3.stderr @@ -41,7 +41,7 @@ note: expected this to be `Bar` | LL | type A = usize; | ^^^^^ - = note: required for the cast from `isize` to the object type `dyn Foo` + = note: required for the cast to the object type `dyn Foo` error: aborting due to 3 previous errors diff --git a/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr b/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr index dbd9a44ed9774..9f1abf2a6c4b6 100644 --- a/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr +++ b/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr @@ -4,7 +4,7 @@ error[E0271]: type mismatch resolving ` as Iterator>::It LL | let _: &dyn I32Iterator = &vec![42].into_iter(); | ^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32` | - = note: required for the cast from `std::vec::IntoIter` to the object type `dyn Iterator` + = note: required for the cast to the object type `dyn Iterator` error: aborting due to previous error diff --git a/src/test/ui/associated-types/issue-65774-1.stderr b/src/test/ui/associated-types/issue-65774-1.stderr index 419de689c52da..e468a1b3ba484 100644 --- a/src/test/ui/associated-types/issue-65774-1.stderr +++ b/src/test/ui/associated-types/issue-65774-1.stderr @@ -23,7 +23,7 @@ note: required because of the requirements on the impl of `MyDisplay` for `&mut | LL | impl<'a, T: MyDisplay> MyDisplay for &'a mut T { } | ^^^^^^^^^ ^^^^^^^^^ - = note: required for the cast from `&mut T` to the object type `dyn MyDisplay` + = note: required for the cast to the object type `dyn MyDisplay` error: aborting due to 2 previous errors diff --git a/src/test/ui/associated-types/issue-65774-2.stderr b/src/test/ui/associated-types/issue-65774-2.stderr index c22302cdc2626..4cef4db4698a7 100644 --- a/src/test/ui/associated-types/issue-65774-2.stderr +++ b/src/test/ui/associated-types/issue-65774-2.stderr @@ -18,7 +18,7 @@ LL | writer.my_write(valref) | ^^^^^^ the trait `MyDisplay` is not implemented for `T` | = help: the trait `MyDisplay` is implemented for `&'a mut T` - = note: required for the cast from `T` to the object type `dyn MyDisplay` + = note: required for the cast to the object type `dyn MyDisplay` error: aborting due to 2 previous errors diff --git a/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr b/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr index e5887689690e7..e0818337d2039 100644 --- a/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr +++ b/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr @@ -37,7 +37,7 @@ error[E0271]: type mismatch resolving ` as Future>::Out LL | let _: &dyn Future = █ | ^^^^^^ expected `()`, found `u8` | - = note: required for the cast from `impl Future` to the object type `dyn Future` + = note: required for the cast to the object type `dyn Future` error[E0308]: mismatched types --> $DIR/async-block-control-flow-static-semantics.rs:12:43 @@ -53,7 +53,7 @@ error[E0271]: type mismatch resolving ` as Future>::Out LL | let _: &dyn Future = █ | ^^^^^^ expected `()`, found `u8` | - = note: required for the cast from `impl Future` to the object type `dyn Future` + = note: required for the cast to the object type `dyn Future` error[E0308]: mismatched types --> $DIR/async-block-control-flow-static-semantics.rs:47:44 diff --git a/src/test/ui/async-await/issue-86507.stderr b/src/test/ui/async-await/issue-86507.stderr index 0e21dba980deb..5bbc20359c64a 100644 --- a/src/test/ui/async-await/issue-86507.stderr +++ b/src/test/ui/async-await/issue-86507.stderr @@ -13,7 +13,7 @@ note: captured value is not `Send` because `&` references cannot be sent unless | LL | let x = x; | ^ has type `&T` which is not `Send`, because `T` is not `Sync` - = note: required for the cast from `impl Future` to the object type `dyn Future + Send` + = note: required for the cast to the object type `dyn Future + Send` help: consider further restricting this bound | LL | fn bar<'me, 'async_trait, T: Send + std::marker::Sync>(x: &'me T) diff --git a/src/test/ui/coercion/coerce-issue-49593-box-never-windows.nofallback.stderr b/src/test/ui/coercion/coerce-issue-49593-box-never-windows.nofallback.stderr index 980da53603432..3350d1efb5318 100644 --- a/src/test/ui/coercion/coerce-issue-49593-box-never-windows.nofallback.stderr +++ b/src/test/ui/coercion/coerce-issue-49593-box-never-windows.nofallback.stderr @@ -4,7 +4,7 @@ error[E0277]: the trait bound `(): std::error::Error` is not satisfied LL | /* *mut $0 is coerced to Box here */ Box::<_ /* ! */>::new(x) | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()` | - = note: required for the cast from `()` to the object type `dyn std::error::Error` + = note: required for the cast to the object type `dyn std::error::Error` error[E0277]: the trait bound `(): std::error::Error` is not satisfied --> $DIR/coerce-issue-49593-box-never-windows.rs:23:49 @@ -12,7 +12,7 @@ error[E0277]: the trait bound `(): std::error::Error` is not satisfied LL | /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()` | - = note: required for the cast from `()` to the object type `(dyn std::error::Error + 'static)` + = note: required for the cast to the object type `(dyn std::error::Error + 'static)` error: aborting due to 2 previous errors diff --git a/src/test/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr b/src/test/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr index 322681b97bccb..fcd2d7f78ff75 100644 --- a/src/test/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr +++ b/src/test/ui/coercion/coerce-issue-49593-box-never.nofallback.stderr @@ -4,7 +4,7 @@ error[E0277]: the trait bound `(): std::error::Error` is not satisfied LL | /* *mut $0 is coerced to Box here */ Box::<_ /* ! */>::new(x) | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()` | - = note: required for the cast from `()` to the object type `dyn std::error::Error` + = note: required for the cast to the object type `dyn std::error::Error` error[E0277]: the trait bound `(): std::error::Error` is not satisfied --> $DIR/coerce-issue-49593-box-never.rs:23:49 @@ -12,7 +12,7 @@ error[E0277]: the trait bound `(): std::error::Error` is not satisfied LL | /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()` | - = note: required for the cast from `()` to the object type `(dyn std::error::Error + 'static)` + = note: required for the cast to the object type `(dyn std::error::Error + 'static)` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/defaults/trait_objects_fail.stderr b/src/test/ui/const-generics/defaults/trait_objects_fail.stderr index da85b2059f0a3..60dc96f675a8b 100644 --- a/src/test/ui/const-generics/defaults/trait_objects_fail.stderr +++ b/src/test/ui/const-generics/defaults/trait_objects_fail.stderr @@ -7,7 +7,7 @@ LL | foo(&10_u32); | required by a bound introduced by this call | = help: the trait `Trait<2_u8>` is implemented for `u32` - = note: required for the cast from `u32` to the object type `dyn Trait` + = note: required for the cast to the object type `dyn Trait` error[E0277]: the trait bound `bool: Traitor<{_: u8}>` is not satisfied --> $DIR/trait_objects_fail.rs:28:9 @@ -18,7 +18,7 @@ LL | bar(&true); | required by a bound introduced by this call | = help: the trait `Traitor<2_u8, 3_u8>` is implemented for `bool` - = note: required for the cast from `bool` to the object type `dyn Traitor<{_: u8}>` + = note: required for the cast to the object type `dyn Traitor<{_: u8}>` error: aborting due to 2 previous errors diff --git a/src/test/ui/custom_test_frameworks/mismatch.stderr b/src/test/ui/custom_test_frameworks/mismatch.stderr index 61061ae529d12..e848ddc55b7df 100644 --- a/src/test/ui/custom_test_frameworks/mismatch.stderr +++ b/src/test/ui/custom_test_frameworks/mismatch.stderr @@ -6,7 +6,7 @@ LL | #[test] LL | fn wrong_kind(){} | ^^^^^^^^^^^^^^^^^ the trait `Testable` is not implemented for `TestDescAndFn` | - = note: required for the cast from `TestDescAndFn` to the object type `dyn Testable` + = note: required for the cast to the object type `dyn Testable` = note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/dst/dst-bad-coerce1.stderr b/src/test/ui/dst/dst-bad-coerce1.stderr index 594acff853a0e..121c76a01a5de 100644 --- a/src/test/ui/dst/dst-bad-coerce1.stderr +++ b/src/test/ui/dst/dst-bad-coerce1.stderr @@ -15,7 +15,7 @@ error[E0277]: the trait bound `Foo: Bar` is not satisfied LL | let f3: &Fat = f2; | ^^ the trait `Bar` is not implemented for `Foo` | - = note: required for the cast from `Foo` to the object type `dyn Bar` + = note: required for the cast to the object type `dyn Bar` error[E0308]: mismatched types --> $DIR/dst-bad-coerce1.rs:28:27 @@ -34,7 +34,7 @@ error[E0277]: the trait bound `Foo: Bar` is not satisfied LL | let f3: &(dyn Bar,) = f2; | ^^ the trait `Bar` is not implemented for `Foo` | - = note: required for the cast from `Foo` to the object type `dyn Bar` + = note: required for the cast to the object type `dyn Bar` error: aborting due to 4 previous errors diff --git a/src/test/ui/dst/dst-object-from-unsized-type.stderr b/src/test/ui/dst/dst-object-from-unsized-type.stderr index e24c96ebed633..5bd47736626da 100644 --- a/src/test/ui/dst/dst-object-from-unsized-type.stderr +++ b/src/test/ui/dst/dst-object-from-unsized-type.stderr @@ -6,7 +6,7 @@ LL | fn test1(t: &T) { LL | let u: &dyn Foo = t; | ^ doesn't have a size known at compile-time | - = note: required for the cast from `T` to the object type `dyn Foo` + = note: required for the cast to the object type `dyn Foo` help: consider removing the `?Sized` bound to make the type parameter `Sized` | LL - fn test1(t: &T) { @@ -21,7 +21,7 @@ LL | fn test2(t: &T) { LL | let v: &dyn Foo = t as &dyn Foo; | ^ doesn't have a size known at compile-time | - = note: required for the cast from `T` to the object type `dyn Foo` + = note: required for the cast to the object type `dyn Foo` help: consider removing the `?Sized` bound to make the type parameter `Sized` | LL - fn test2(t: &T) { @@ -35,7 +35,7 @@ LL | let _: &[&dyn Foo] = &["hi"]; | ^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` - = note: required for the cast from `str` to the object type `dyn Foo` + = note: required for the cast to the object type `dyn Foo` error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/dst-object-from-unsized-type.rs:23:23 @@ -44,7 +44,7 @@ LL | let _: &dyn Foo = x as &dyn Foo; | ^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` - = note: required for the cast from `[u8]` to the object type `dyn Foo` + = note: required for the cast to the object type `dyn Foo` error: aborting due to 4 previous errors diff --git a/src/test/ui/generic-associated-types/issue-79422.extended.stderr b/src/test/ui/generic-associated-types/issue-79422.extended.stderr index 9bcbd74716845..9478fc8979211 100644 --- a/src/test/ui/generic-associated-types/issue-79422.extended.stderr +++ b/src/test/ui/generic-associated-types/issue-79422.extended.stderr @@ -27,7 +27,7 @@ LL | type VRefCont<'a> = &'a V where Self: 'a; | ^^^^^ = note: expected trait object `(dyn RefCont<'_, u8> + 'static)` found reference `&u8` - = note: required for the cast from `BTreeMap` to the object type `dyn MapLike + 'static)>` + = note: required for the cast to the object type `dyn MapLike + 'static)>` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-14366.stderr b/src/test/ui/issues/issue-14366.stderr index 10a73b245ac57..b96b07c91a1fe 100644 --- a/src/test/ui/issues/issue-14366.stderr +++ b/src/test/ui/issues/issue-14366.stderr @@ -5,7 +5,7 @@ LL | let _x = "test" as &dyn (::std::any::Any); | ^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` - = note: required for the cast from `str` to the object type `dyn Any` + = note: required for the cast to the object type `dyn Any` help: consider borrowing the value, since `&str` can be coerced into `dyn Any` | LL | let _x = &"test" as &dyn (::std::any::Any); diff --git a/src/test/ui/issues/issue-22034.stderr b/src/test/ui/issues/issue-22034.stderr index b32de5b24b924..edcd21ebd6b9b 100644 --- a/src/test/ui/issues/issue-22034.stderr +++ b/src/test/ui/issues/issue-22034.stderr @@ -6,7 +6,7 @@ LL | &mut *(ptr as *mut dyn Fn()) | = help: the trait `Fn<()>` is not implemented for `()` = note: wrap the `()` in a closure with no arguments: `|| { /* code */ }` - = note: required for the cast from `()` to the object type `dyn Fn()` + = note: required for the cast to the object type `dyn Fn()` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-22872.stderr b/src/test/ui/issues/issue-22872.stderr index a84cb7d8c5922..cd96646d751f2 100644 --- a/src/test/ui/issues/issue-22872.stderr +++ b/src/test/ui/issues/issue-22872.stderr @@ -10,7 +10,7 @@ note: required because of the requirements on the impl of `for<'b> Wrap<'b>` for | LL | impl<'b, P> Wrap<'b> for Wrapper

| ^^^^^^^^ ^^^^^^^^^^ - = note: required for the cast from `Wrapper

` to the object type `dyn for<'b> Wrap<'b>` + = note: required for the cast to the object type `dyn for<'b> Wrap<'b>` help: consider further restricting the associated type | LL | fn push_process

(process: P) where P: Process<'static>,

>::Item: Iterator { diff --git a/src/test/ui/issues/issue-7013.stderr b/src/test/ui/issues/issue-7013.stderr index f6cb1cbdc11c6..98ed67507b1d8 100644 --- a/src/test/ui/issues/issue-7013.stderr +++ b/src/test/ui/issues/issue-7013.stderr @@ -11,7 +11,7 @@ note: required because it appears within the type `B` | LL | struct B { | ^ - = note: required for the cast from `B` to the object type `dyn Foo + Send` + = note: required for the cast to the object type `dyn Foo + Send` error: aborting due to previous error diff --git a/src/test/ui/kindck/kindck-impl-type-params.stderr b/src/test/ui/kindck/kindck-impl-type-params.stderr index 902349135c549..32759d2fa0ebd 100644 --- a/src/test/ui/kindck/kindck-impl-type-params.stderr +++ b/src/test/ui/kindck/kindck-impl-type-params.stderr @@ -9,7 +9,7 @@ note: required because of the requirements on the impl of `Gettable` for `S Gettable for S {} | ^^^^^^^^^^^ ^^^^ - = note: required for the cast from `S` to the object type `dyn Gettable` + = note: required for the cast to the object type `dyn Gettable` help: consider restricting type parameter `T` | LL | fn f(val: T) { @@ -26,7 +26,7 @@ note: required because of the requirements on the impl of `Gettable` for `S Gettable for S {} | ^^^^^^^^^^^ ^^^^ - = note: required for the cast from `S` to the object type `dyn Gettable` + = note: required for the cast to the object type `dyn Gettable` help: consider restricting type parameter `T` | LL | fn f(val: T) { @@ -43,7 +43,7 @@ note: required because of the requirements on the impl of `Gettable` for `S Gettable for S {} | ^^^^^^^^^^^ ^^^^ - = note: required for the cast from `S` to the object type `dyn Gettable` + = note: required for the cast to the object type `dyn Gettable` help: consider restricting type parameter `T` | LL | fn g(val: T) { @@ -60,7 +60,7 @@ note: required because of the requirements on the impl of `Gettable` for `S Gettable for S {} | ^^^^^^^^^^^ ^^^^ - = note: required for the cast from `S` to the object type `dyn Gettable` + = note: required for the cast to the object type `dyn Gettable` help: consider restricting type parameter `T` | LL | fn g(val: T) { @@ -78,7 +78,7 @@ note: required because of the requirements on the impl of `Gettable` for | LL | impl Gettable for S {} | ^^^^^^^^^^^ ^^^^ - = note: required for the cast from `S` to the object type `dyn Gettable` + = note: required for the cast to the object type `dyn Gettable` error[E0277]: the trait bound `Foo: Copy` is not satisfied --> $DIR/kindck-impl-type-params.rs:43:37 @@ -92,7 +92,7 @@ note: required because of the requirements on the impl of `Gettable` for `S | LL | impl Gettable for S {} | ^^^^^^^^^^^ ^^^^ - = note: required for the cast from `S` to the object type `dyn Gettable` + = note: required for the cast to the object type `dyn Gettable` help: consider annotating `Foo` with `#[derive(Copy)]` | LL | #[derive(Copy)] diff --git a/src/test/ui/mismatched_types/cast-rfc0401.stderr b/src/test/ui/mismatched_types/cast-rfc0401.stderr index eab8e8e80c424..e63ca6e11de59 100644 --- a/src/test/ui/mismatched_types/cast-rfc0401.stderr +++ b/src/test/ui/mismatched_types/cast-rfc0401.stderr @@ -220,7 +220,7 @@ LL | let _ = fat_v as *const dyn Foo; | ^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` - = note: required for the cast from `[u8]` to the object type `dyn Foo` + = note: required for the cast to the object type `dyn Foo` help: consider borrowing the value, since `&[u8]` can be coerced into `dyn Foo` | LL | let _ = &fat_v as *const dyn Foo; @@ -233,7 +233,7 @@ LL | let _ = a as *const dyn Foo; | ^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` - = note: required for the cast from `str` to the object type `dyn Foo` + = note: required for the cast to the object type `dyn Foo` help: consider borrowing the value, since `&str` can be coerced into `dyn Foo` | LL | let _ = &a as *const dyn Foo; diff --git a/src/test/ui/never_type/fallback-closure-wrap.fallback.stderr b/src/test/ui/never_type/fallback-closure-wrap.fallback.stderr index 6b9635d4a60bc..78d1a3caf4a30 100644 --- a/src/test/ui/never_type/fallback-closure-wrap.fallback.stderr +++ b/src/test/ui/never_type/fallback-closure-wrap.fallback.stderr @@ -10,7 +10,7 @@ LL | | }) as Box); | = note: expected unit type `()` found type `!` - = note: required for the cast from `[closure@$DIR/fallback-closure-wrap.rs:18:40: 21:6]` to the object type `dyn FnMut()` + = note: required for the cast to the object type `dyn FnMut()` error: aborting due to previous error diff --git a/src/test/ui/suggestions/derive-macro-missing-bounds.stderr b/src/test/ui/suggestions/derive-macro-missing-bounds.stderr index 4186dc7cb35ae..501d083e2bc60 100644 --- a/src/test/ui/suggestions/derive-macro-missing-bounds.stderr +++ b/src/test/ui/suggestions/derive-macro-missing-bounds.stderr @@ -33,7 +33,7 @@ LL | impl Debug for Inner { | ^^^^^ ^^^^^^^^ = note: 1 redundant requirement hidden = note: required because of the requirements on the impl of `Debug` for `&c::Inner` - = note: required for the cast from `&c::Inner` to the object type `dyn Debug` + = note: required for the cast to the object type `dyn Debug` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` | @@ -55,7 +55,7 @@ LL | impl Debug for Inner where T: Debug, T: Trait { | ^^^^^ ^^^^^^^^ = note: 1 redundant requirement hidden = note: required because of the requirements on the impl of `Debug` for `&d::Inner` - = note: required for the cast from `&d::Inner` to the object type `dyn Debug` + = note: required for the cast to the object type `dyn Debug` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` | @@ -77,7 +77,7 @@ LL | impl Debug for Inner where T: Debug + Trait { | ^^^^^ ^^^^^^^^ = note: 1 redundant requirement hidden = note: required because of the requirements on the impl of `Debug` for `&e::Inner` - = note: required for the cast from `&e::Inner` to the object type `dyn Debug` + = note: required for the cast to the object type `dyn Debug` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` | @@ -99,7 +99,7 @@ LL | impl Debug for Inner where T: Trait { | ^^^^^ ^^^^^^^^ = note: 1 redundant requirement hidden = note: required because of the requirements on the impl of `Debug` for `&f::Inner` - = note: required for the cast from `&f::Inner` to the object type `dyn Debug` + = note: required for the cast to the object type `dyn Debug` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` | diff --git a/src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr b/src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr index 6b6e406130ec2..8961f4275a283 100644 --- a/src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr +++ b/src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr @@ -8,7 +8,7 @@ LL | check(s); | = help: within `OsStr`, the trait `Sized` is not implemented for `[u8]` = note: required because it appears within the type `OsStr` - = note: required for the cast from `OsStr` to the object type `dyn AsRef` + = note: required for the cast to the object type `dyn AsRef` help: consider borrowing the value, since `&OsStr` can be coerced into `dyn AsRef` | LL | check(&s); diff --git a/src/test/ui/traits/coercion-generic-bad.stderr b/src/test/ui/traits/coercion-generic-bad.stderr index 93d6770eb47d1..b213ee635df59 100644 --- a/src/test/ui/traits/coercion-generic-bad.stderr +++ b/src/test/ui/traits/coercion-generic-bad.stderr @@ -5,7 +5,7 @@ LL | let s: Box> = Box::new(Struct { person: "Fred" }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `Struct` | = help: the trait `Trait<&'static str>` is implemented for `Struct` - = note: required for the cast from `Struct` to the object type `dyn Trait` + = note: required for the cast to the object type `dyn Trait` error: aborting due to previous error diff --git a/src/test/ui/traits/map-types.stderr b/src/test/ui/traits/map-types.stderr index f685c50b07d5b..a4686edb71757 100644 --- a/src/test/ui/traits/map-types.stderr +++ b/src/test/ui/traits/map-types.stderr @@ -5,7 +5,7 @@ LL | let y: Box> = Box::new(x); | ^^^^^^^^^^^ the trait `Map` is not implemented for `Box>` | = help: the trait `Map` is implemented for `HashMap` - = note: required for the cast from `Box>` to the object type `dyn Map` + = note: required for the cast to the object type `dyn Map` error: aborting due to previous error diff --git a/src/test/ui/traits/trait-upcasting/type-checking-test-1.stderr b/src/test/ui/traits/trait-upcasting/type-checking-test-1.stderr index 3985372119e88..44f32e0cec91c 100644 --- a/src/test/ui/traits/trait-upcasting/type-checking-test-1.stderr +++ b/src/test/ui/traits/trait-upcasting/type-checking-test-1.stderr @@ -15,7 +15,7 @@ error[E0277]: the trait bound `&dyn Foo: Bar<_>` is not satisfied LL | let _ = x as &dyn Bar<_>; // Ambiguous | ^ the trait `Bar<_>` is not implemented for `&dyn Foo` | - = note: required for the cast from `&dyn Foo` to the object type `dyn Bar<_>` + = note: required for the cast to the object type `dyn Bar<_>` error: aborting due to 2 previous errors diff --git a/src/test/ui/traits/trait-upcasting/type-checking-test-2.stderr b/src/test/ui/traits/trait-upcasting/type-checking-test-2.stderr index 93c71f54eb53a..4ae4c8552c161 100644 --- a/src/test/ui/traits/trait-upcasting/type-checking-test-2.stderr +++ b/src/test/ui/traits/trait-upcasting/type-checking-test-2.stderr @@ -15,7 +15,7 @@ error[E0277]: the trait bound `&dyn Foo: Bar` is not satisfied LL | let _ = x as &dyn Bar; // Error | ^ the trait `Bar` is not implemented for `&dyn Foo` | - = note: required for the cast from `&dyn Foo` to the object type `dyn Bar` + = note: required for the cast to the object type `dyn Bar` error[E0605]: non-primitive cast: `&dyn Foo` as `&dyn Bar<_>` --> $DIR/type-checking-test-2.rs:26:13 @@ -34,7 +34,7 @@ error[E0277]: the trait bound `&dyn Foo: Bar<_>` is not satisfied LL | let a = x as &dyn Bar<_>; // Ambiguous | ^ the trait `Bar<_>` is not implemented for `&dyn Foo` | - = note: required for the cast from `&dyn Foo` to the object type `dyn Bar<_>` + = note: required for the cast to the object type `dyn Bar<_>` error: aborting due to 4 previous errors diff --git a/src/test/ui/unsized/unsized-fn-param.stderr b/src/test/ui/unsized/unsized-fn-param.stderr index 0221ef16b4965..edf0b89596536 100644 --- a/src/test/ui/unsized/unsized-fn-param.stderr +++ b/src/test/ui/unsized/unsized-fn-param.stderr @@ -7,7 +7,7 @@ LL | foo11("bar", &"baz"); | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `str` - = note: required for the cast from `str` to the object type `dyn AsRef` + = note: required for the cast to the object type `dyn AsRef` help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef` | LL | foo11(&"bar", &"baz"); @@ -22,7 +22,7 @@ LL | foo12(&"bar", "baz"); | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `str` - = note: required for the cast from `str` to the object type `dyn AsRef` + = note: required for the cast to the object type `dyn AsRef` help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef` | LL | foo12(&"bar", &"baz"); @@ -37,7 +37,7 @@ LL | foo21("bar", &"baz"); | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `str` - = note: required for the cast from `str` to the object type `dyn AsRef` + = note: required for the cast to the object type `dyn AsRef` help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef` | LL | foo21(&"bar", &"baz"); @@ -52,7 +52,7 @@ LL | foo22(&"bar", "baz"); | required by a bound introduced by this call | = help: the trait `Sized` is not implemented for `str` - = note: required for the cast from `str` to the object type `dyn AsRef` + = note: required for the cast to the object type `dyn AsRef` help: consider borrowing the value, since `&str` can be coerced into `dyn AsRef` | LL | foo22(&"bar", &"baz"); diff --git a/src/tools/cargo b/src/tools/cargo index dbff32b27893b..38472bc19f2f7 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit dbff32b27893b899ae2397f3d56d1be111041d56 +Subproject commit 38472bc19f2f76e245eba54a6e97ee6821b3c1db diff --git a/src/tools/miri b/src/tools/miri index f76ebd6feb9f5..3361eabf38825 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit f76ebd6feb9f59be993336f84ecfdc441ad33d81 +Subproject commit 3361eabf3882578207a483f2cee631646e80eabc diff --git a/src/tools/rls b/src/tools/rls index ece09b88c0365..7241c6cc45bad 160000 --- a/src/tools/rls +++ b/src/tools/rls @@ -1 +1 @@ -Subproject commit ece09b88c0365947af79c0ffdeea02bc6c1eec25 +Subproject commit 7241c6cc45badc0e30cefd6c123a539f82c50cd3 From 3305cb0a8c778b91ea7feb6e456162283a6b07e9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 5 Jul 2022 09:59:20 -0700 Subject: [PATCH 2/2] Revert "Fix trait object reborrow suggestion" This reverts commit 6c0a591deef190ab9bf12836467079367a366c35. --- Cargo.lock | 28 ++++++++++++++----- compiler/rustc_middle/src/traits/mod.rs | 2 +- .../src/traits/error_reporting/mod.rs | 7 +++-- .../src/traits/error_reporting/suggestions.rs | 2 +- .../src/traits/select/confirmation.rs | 6 ++-- .../suggest-borrow-to-dyn-object.rs | 16 ----------- .../suggest-borrow-to-dyn-object.stderr | 19 ------------- 7 files changed, 30 insertions(+), 50 deletions(-) delete mode 100644 src/test/ui/suggestions/suggest-borrow-to-dyn-object.rs delete mode 100644 src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr diff --git a/Cargo.lock b/Cargo.lock index ba0098a977534..7a0353c54cd91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -333,7 +333,6 @@ dependencies = [ "libgit2-sys", "log", "memchr", - "num_cpus", "opener", "openssl", "os_info", @@ -445,7 +444,7 @@ dependencies = [ [[package]] name = "cargo-util" -version = "0.1.4" +version = "0.1.3" dependencies = [ "anyhow", "core-foundation", @@ -2330,6 +2329,20 @@ dependencies = [ "topological-sort", ] +[[package]] +name = "measureme" +version = "9.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78f7a41bc6f856a2cf0e95094ad5121f82500e2d9a0f3c0171d98f6566d8117d" +dependencies = [ + "log", + "memmap2", + "parking_lot 0.11.2", + "perf-event-open-sys", + "rustc-hash", + "smallvec", +] + [[package]] name = "measureme" version = "10.0.0" @@ -2428,7 +2441,7 @@ dependencies = [ "lazy_static", "libc", "log", - "measureme", + "measureme 9.1.2", "rand 0.8.5", "regex", "rustc-workspace-hack", @@ -3040,6 +3053,7 @@ name = "racer" version = "2.2.2" dependencies = [ "bitflags", + "clap 2.34.0", "derive_more", "env_logger 0.7.1", "humantime 2.0.1", @@ -3263,7 +3277,7 @@ dependencies = [ "difference", "env_logger 0.9.0", "futures 0.3.19", - "heck 0.4.0", + "heck 0.3.1", "home", "itertools", "jsonrpc-core", @@ -3639,7 +3653,7 @@ dependencies = [ "cstr", "libc", "libloading", - "measureme", + "measureme 10.0.0", "rustc-demangle", "rustc_ast", "rustc_attr", @@ -3737,7 +3751,7 @@ dependencies = [ "indexmap", "jobserver", "libc", - "measureme", + "measureme 10.0.0", "memmap2", "parking_lot 0.11.2", "rustc-hash", @@ -4294,7 +4308,7 @@ dependencies = [ name = "rustc_query_impl" version = "0.0.0" dependencies = [ - "measureme", + "measureme 10.0.0", "rustc-rayon-core", "rustc_ast", "rustc_data_structures", diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 7f913faf86058..ed8de24a65eef 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -253,7 +253,7 @@ pub enum ObligationCauseCode<'tcx> { ObjectTypeBound(Ty<'tcx>, ty::Region<'tcx>), /// Obligation incurred due to an object cast. - ObjectCastObligation(/* Concrete type */ Ty<'tcx>, /* Object type */ Ty<'tcx>), + ObjectCastObligation(/* Object type */ Ty<'tcx>), /// Obligation incurred due to a coercion. Coercion { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 88b09f4de0a4c..128f9505fa496 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -484,9 +484,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err.span_label(span, explanation); } - if let ObligationCauseCode::ObjectCastObligation(concrete_ty, obj_ty) = obligation.cause.code().peel_derives() && + if let ObligationCauseCode::ObjectCastObligation(obj_ty) = obligation.cause.code().peel_derives() && + let Some(self_ty) = trait_predicate.self_ty().no_bound_vars() && Some(trait_ref.def_id()) == self.tcx.lang_items().sized_trait() { - self.suggest_borrowing_for_object_cast(&mut err, &root_obligation, *concrete_ty, *obj_ty); + self.suggest_borrowing_for_object_cast(&mut err, &obligation, self_ty, *obj_ty); } if trait_predicate.is_const_if_const() && obligation.param_env.is_const() { @@ -1559,7 +1560,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { obligation.cause.code().peel_derives(), ObligationCauseCode::ItemObligation(_) | ObligationCauseCode::BindingObligation(_, _) - | ObligationCauseCode::ObjectCastObligation(..) + | ObligationCauseCode::ObjectCastObligation(_) | ObligationCauseCode::OpaqueType ); if let Err(error) = self.at(&obligation.cause, obligation.param_env).eq_exp( diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 83e12153bf2ea..dfbb47cf4c557 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2216,7 +2216,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err.span_note(tcx.def_span(item_def_id), &descr); } } - ObligationCauseCode::ObjectCastObligation(_, object_ty) => { + ObligationCauseCode::ObjectCastObligation(object_ty) => { err.note(&format!( "required for the cast to the object type `{}`", self.ty_to_string(object_ty) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index e1131140c39e8..5942bb79d69e8 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -813,7 +813,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let cause = ObligationCause::new( obligation.cause.span, obligation.cause.body_id, - ObjectCastObligation(source, target), + ObjectCastObligation(target), ); let outlives = ty::OutlivesPredicate(r_a, r_b); nested.push(Obligation::with_depth( @@ -910,7 +910,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let cause = ObligationCause::new( obligation.cause.span, obligation.cause.body_id, - ObjectCastObligation(source, target), + ObjectCastObligation(target), ); let outlives = ty::OutlivesPredicate(r_a, r_b); nested.push(Obligation::with_depth( @@ -931,7 +931,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let cause = ObligationCause::new( obligation.cause.span, obligation.cause.body_id, - ObjectCastObligation(source, target), + ObjectCastObligation(target), ); let predicate_to_obligation = |predicate| { diff --git a/src/test/ui/suggestions/suggest-borrow-to-dyn-object.rs b/src/test/ui/suggestions/suggest-borrow-to-dyn-object.rs deleted file mode 100644 index 120fc538307a7..0000000000000 --- a/src/test/ui/suggestions/suggest-borrow-to-dyn-object.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::ffi::{OsStr, OsString}; -use std::path::Path; - -fn check(p: &dyn AsRef) { - let m = std::fs::metadata(&p); - println!("{:?}", &m); -} - -fn main() { - let s: OsString = ".".into(); - let s: &OsStr = &s; - check(s); - //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time - //~| HELP within `OsStr`, the trait `Sized` is not implemented for `[u8]` - //~| HELP consider borrowing the value, since `&OsStr` can be coerced into `dyn AsRef` -} diff --git a/src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr b/src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr deleted file mode 100644 index 8961f4275a283..0000000000000 --- a/src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/suggest-borrow-to-dyn-object.rs:12:11 - | -LL | check(s); - | ----- ^ doesn't have a size known at compile-time - | | - | required by a bound introduced by this call - | - = help: within `OsStr`, the trait `Sized` is not implemented for `[u8]` - = note: required because it appears within the type `OsStr` - = note: required for the cast to the object type `dyn AsRef` -help: consider borrowing the value, since `&OsStr` can be coerced into `dyn AsRef` - | -LL | check(&s); - | + - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`.