From 1d15d43f11f16cc711c594e2ce7f494e3a34149d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 28 May 2021 20:16:07 -0700 Subject: [PATCH 01/11] Point at RHS of associated type in obligation span --- compiler/rustc_typeck/src/check/check.rs | 8 +-- .../defaults-suitability.stderr | 72 +++++++++---------- .../defaults-unsound-62211-1.stderr | 32 ++++----- .../defaults-unsound-62211-2.stderr | 32 ++++----- .../issue-43784-associated-type.stderr | 4 +- .../ui/associated-types/issue-43924.stderr | 9 ++- .../ui/associated-types/issue-54108.stderr | 4 +- .../ui/associated-types/issue-63593.stderr | 8 +-- .../ui/associated-types/issue-65774-1.stderr | 9 ++- .../ui/associated-types/issue-65774-2.stderr | 9 ++- .../ui/associated-types/issue-72806.stderr | 4 +- ...int-at-type-on-obligation-failure-2.stderr | 12 ++-- ...point-at-type-on-obligation-failure.stderr | 4 +- src/test/ui/chalkify/impl_wf_2.stderr | 4 +- .../associated-type-bound-fail.full.stderr | 4 +- .../associated-type-bound-fail.min.stderr | 4 +- ...ature-gate-generic_associated_types.stderr | 4 +- .../cross-crate-bounds.stderr | 4 +- .../generic-associated-types-where.stderr | 8 +-- .../impl_bounds.stderr | 16 ++--- .../issue-47206-where-clause.stderr | 4 +- .../issue-68641-check-gat-bounds.stderr | 4 +- .../issue-68642-broken-llvm-ir.stderr | 4 +- .../issue-68643-broken-mir.stderr | 4 +- .../issue-68644-codegen-selection.stderr | 4 +- .../issue-68645-codegen-fulfillment.stderr | 4 +- .../issue-68656-unsized-values.stderr | 4 +- .../issue-74816.stderr | 17 +++-- .../issue-74824.stderr | 18 +++-- .../unsatisfied-outlives-bound.stderr | 8 +-- src/test/ui/never_type/issue-51506.stderr | 4 +- ...-type-region-bound-in-trait-not-met.stderr | 8 +-- ...-type-static-bound-in-trait-not-met.stderr | 4 +- .../deafult-associated-type-bound-1.stderr | 4 +- .../deafult-associated-type-bound-2.stderr | 4 +- ...afult-generic-associated-type-bound.stderr | 4 +- src/test/ui/specialization/issue-33017.stderr | 4 +- src/test/ui/specialization/issue-38091.stderr | 4 +- src/test/ui/specialization/issue-44861.stderr | 4 +- src/test/ui/specialization/issue-59435.stderr | 4 +- .../inductive-overflow/two-traits.stderr | 4 +- src/test/ui/traits/issue-65673.stderr | 4 +- 42 files changed, 172 insertions(+), 202 deletions(-) diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index 70d85796d002e..2bb5ea982d85c 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -790,7 +790,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) { let abi = sig.header.abi; fn_maybe_err(tcx, item.ident.span, abi); } - hir::TraitItemKind::Type(.., Some(_default)) => { + hir::TraitItemKind::Type(.., Some(default)) => { let assoc_item = tcx.associated_item(item.def_id); let trait_substs = InternalSubsts::identity_for_item(tcx, it.def_id.to_def_id()); @@ -798,7 +798,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) { tcx, assoc_item, assoc_item, - item.span, + default.span, ty::TraitRef { def_id: it.def_id.to_def_id(), substs: trait_substs }, ); } @@ -1047,12 +1047,12 @@ pub(super) fn check_impl_items_against_trait<'tcx>( opt_trait_span, ); } - hir::ImplItemKind::TyAlias(_) => { + hir::ImplItemKind::TyAlias(impl_ty) => { let opt_trait_span = tcx.hir().span_if_local(ty_trait_item.def_id); compare_ty_impl( tcx, &ty_impl_item, - impl_item.span, + impl_ty.span, &ty_trait_item, impl_trait_ref, opt_trait_span, diff --git a/src/test/ui/associated-types/defaults-suitability.stderr b/src/test/ui/associated-types/defaults-suitability.stderr index af4e6f0a5c161..cba88fa44b6fd 100644 --- a/src/test/ui/associated-types/defaults-suitability.stderr +++ b/src/test/ui/associated-types/defaults-suitability.stderr @@ -1,32 +1,29 @@ error[E0277]: the trait bound `NotClone: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:13:5 + --> $DIR/defaults-suitability.rs:13:22 | LL | type Ty: Clone = NotClone; - | ^^^^^^^^^-----^^^^^^^^^^^^ - | | | - | | required by this bound in `Tr::Ty` - | the trait `Clone` is not implemented for `NotClone` + | ----- ^^^^^^^^ the trait `Clone` is not implemented for `NotClone` + | | + | required by this bound in `Tr::Ty` error[E0277]: the trait bound `NotClone: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:22:5 + --> $DIR/defaults-suitability.rs:22:15 | LL | Self::Ty: Clone, | ----- required by this bound in `Tr2::Ty` LL | { LL | type Ty = NotClone; - | ^^^^^--^^^^^^^^^^^^ - | | | - | | required by a bound in this - | the trait `Clone` is not implemented for `NotClone` + | -- ^^^^^^^^ the trait `Clone` is not implemented for `NotClone` + | | + | required by a bound in this error[E0277]: the trait bound `T: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:28:5 + --> $DIR/defaults-suitability.rs:28:23 | LL | type Bar: Clone = Vec; - | ^^^^^^^^^^-----^^^^^^^^^^ - | | | - | | required by this bound in `Foo::Bar` - | the trait `Clone` is not implemented for `T` + | ----- ^^^^^^ the trait `Clone` is not implemented for `T` + | | + | required by this bound in `Foo::Bar` | = note: required because of the requirements on the impl of `Clone` for `Vec` help: consider restricting type parameter `T` @@ -35,34 +32,31 @@ LL | trait Foo { | ^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `(): Foo` is not satisfied - --> $DIR/defaults-suitability.rs:34:5 + --> $DIR/defaults-suitability.rs:34:29 | LL | type Assoc: Foo = (); - | ^^^^^^^^^^^^---------^^^^^^ - | | | - | | required by this bound in `Bar::Assoc` - | the trait `Foo` is not implemented for `()` + | --------- ^^ the trait `Foo` is not implemented for `()` + | | + | required by this bound in `Bar::Assoc` error[E0277]: the trait bound `NotClone: IsU8` is not satisfied - --> $DIR/defaults-suitability.rs:56:5 + --> $DIR/defaults-suitability.rs:56:18 | LL | Self::Assoc: IsU8, | ----------------- required by this bound in `D::Assoc` ... LL | type Assoc = NotClone; - | ^^^^^-----^^^^^^^^^^^^ - | | | - | | required by a bound in this - | the trait `IsU8` is not implemented for `NotClone` + | ----- ^^^^^^^^ the trait `IsU8` is not implemented for `NotClone` + | | + | required by a bound in this error[E0277]: the trait bound `>::Baz: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:65:5 + --> $DIR/defaults-suitability.rs:65:23 | LL | type Bar: Clone = Vec; - | ^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `Foo2::Bar` - | the trait `Clone` is not implemented for `>::Baz` + | ----- ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `>::Baz` + | | + | required by this bound in `Foo2::Bar` | = note: required because of the requirements on the impl of `Clone` for `Vec<>::Baz>` help: consider further restricting the associated type @@ -71,13 +65,12 @@ LL | trait Foo2 where >::Baz: Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `>::Baz: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:74:5 + --> $DIR/defaults-suitability.rs:74:23 | LL | type Bar: Clone = Vec; - | ^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `Foo25::Bar` - | the trait `Clone` is not implemented for `>::Baz` + | ----- ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `>::Baz` + | | + | required by this bound in `Foo25::Bar` | = note: required because of the requirements on the impl of `Clone` for `Vec<>::Baz>` help: consider further restricting the associated type @@ -86,16 +79,15 @@ LL | trait Foo25 where >::Baz: Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `T: Clone` is not satisfied - --> $DIR/defaults-suitability.rs:87:5 + --> $DIR/defaults-suitability.rs:87:16 | LL | Self::Baz: Clone, | ----- required by this bound in `Foo3::Baz` ... LL | type Baz = T; - | ^^^^^---^^^^^ - | | | - | | required by a bound in this - | the trait `Clone` is not implemented for `T` + | --- ^ the trait `Clone` is not implemented for `T` + | | + | required by a bound in this | help: consider further restricting type parameter `T` | diff --git a/src/test/ui/associated-types/defaults-unsound-62211-1.stderr b/src/test/ui/associated-types/defaults-unsound-62211-1.stderr index bcdb50aa312cb..5e8ee4a10643d 100644 --- a/src/test/ui/associated-types/defaults-unsound-62211-1.stderr +++ b/src/test/ui/associated-types/defaults-unsound-62211-1.stderr @@ -1,11 +1,10 @@ error[E0277]: `Self` doesn't implement `std::fmt::Display` - --> $DIR/defaults-unsound-62211-1.rs:20:5 + --> $DIR/defaults-unsound-62211-1.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | `Self` cannot be formatted with the default formatter + | ------- ^^^^ `Self` cannot be formatted with the default formatter + | | + | required by this bound in `UncheckedCopy::Output` | = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead help: consider further restricting `Self` @@ -14,13 +13,12 @@ LL | trait UncheckedCopy: Sized + std::fmt::Display { | ^^^^^^^^^^^^^^^^^^^ error[E0277]: cannot add-assign `&'static str` to `Self` - --> $DIR/defaults-unsound-62211-1.rs:20:5 + --> $DIR/defaults-unsound-62211-1.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | no implementation for `Self += &'static str` + | ----------------------- ^^^^ no implementation for `Self += &'static str` + | | + | required by this bound in `UncheckedCopy::Output` | help: consider further restricting `Self` | @@ -28,13 +26,10 @@ LL | trait UncheckedCopy: Sized + AddAssign<&'static str> { | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Self: Deref` is not satisfied - --> $DIR/defaults-unsound-62211-1.rs:20:5 + --> $DIR/defaults-unsound-62211-1.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^-------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | the trait `Deref` is not implemented for `Self` + | ------------------- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Deref` is not implemented for `Self` | help: consider further restricting `Self` | @@ -42,13 +37,10 @@ LL | trait UncheckedCopy: Sized + Deref { | ^^^^^^^ error[E0277]: the trait bound `Self: Copy` is not satisfied - --> $DIR/defaults-unsound-62211-1.rs:20:5 + --> $DIR/defaults-unsound-62211-1.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | the trait `Copy` is not implemented for `Self` + | ---- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Copy` is not implemented for `Self` | help: consider further restricting `Self` | diff --git a/src/test/ui/associated-types/defaults-unsound-62211-2.stderr b/src/test/ui/associated-types/defaults-unsound-62211-2.stderr index fa5cf9196edbd..db3a81218a291 100644 --- a/src/test/ui/associated-types/defaults-unsound-62211-2.stderr +++ b/src/test/ui/associated-types/defaults-unsound-62211-2.stderr @@ -1,11 +1,10 @@ error[E0277]: `Self` doesn't implement `std::fmt::Display` - --> $DIR/defaults-unsound-62211-2.rs:20:5 + --> $DIR/defaults-unsound-62211-2.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | `Self` cannot be formatted with the default formatter + | ------- ^^^^ `Self` cannot be formatted with the default formatter + | | + | required by this bound in `UncheckedCopy::Output` | = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead help: consider further restricting `Self` @@ -14,13 +13,12 @@ LL | trait UncheckedCopy: Sized + std::fmt::Display { | ^^^^^^^^^^^^^^^^^^^ error[E0277]: cannot add-assign `&'static str` to `Self` - --> $DIR/defaults-unsound-62211-2.rs:20:5 + --> $DIR/defaults-unsound-62211-2.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | no implementation for `Self += &'static str` + | ----------------------- ^^^^ no implementation for `Self += &'static str` + | | + | required by this bound in `UncheckedCopy::Output` | help: consider further restricting `Self` | @@ -28,13 +26,10 @@ LL | trait UncheckedCopy: Sized + AddAssign<&'static str> { | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Self: Deref` is not satisfied - --> $DIR/defaults-unsound-62211-2.rs:20:5 + --> $DIR/defaults-unsound-62211-2.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^^^^^^^^-------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | the trait `Deref` is not implemented for `Self` + | ------------------- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Deref` is not implemented for `Self` | help: consider further restricting `Self` | @@ -42,13 +37,10 @@ LL | trait UncheckedCopy: Sized + Deref { | ^^^^^^^ error[E0277]: the trait bound `Self: Copy` is not satisfied - --> $DIR/defaults-unsound-62211-2.rs:20:5 + --> $DIR/defaults-unsound-62211-2.rs:20:96 | LL | type Output: Copy + Deref + AddAssign<&'static str> + From + Display = Self; - | ^^^^^^^^^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `UncheckedCopy::Output` - | the trait `Copy` is not implemented for `Self` + | ---- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Copy` is not implemented for `Self` | help: consider further restricting `Self` | diff --git a/src/test/ui/associated-types/issue-43784-associated-type.stderr b/src/test/ui/associated-types/issue-43784-associated-type.stderr index 0e653a7d3b22f..51dfe7d14f35b 100644 --- a/src/test/ui/associated-types/issue-43784-associated-type.stderr +++ b/src/test/ui/associated-types/issue-43784-associated-type.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/issue-43784-associated-type.rs:14:5 + --> $DIR/issue-43784-associated-type.rs:14:18 | LL | type Assoc: Partial; | ------------- required by this bound in `Complete::Assoc` ... LL | type Assoc = T; - | ^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T` + | ^ the trait `Copy` is not implemented for `T` | help: consider restricting type parameter `T` | diff --git a/src/test/ui/associated-types/issue-43924.stderr b/src/test/ui/associated-types/issue-43924.stderr index 8d4ecac750268..a93dcfe4efaeb 100644 --- a/src/test/ui/associated-types/issue-43924.stderr +++ b/src/test/ui/associated-types/issue-43924.stderr @@ -1,11 +1,10 @@ error[E0277]: the trait bound `(dyn ToString + 'static): Default` is not satisfied - --> $DIR/issue-43924.rs:7:5 + --> $DIR/issue-43924.rs:7:45 | LL | type Out: Default + ToString + ?Sized = dyn ToString; - | ^^^^^^^^^^-------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | | - | | required by this bound in `Foo::Out` - | the trait `Default` is not implemented for `(dyn ToString + 'static)` + | ------- ^^^^^^^^^^^^ the trait `Default` is not implemented for `(dyn ToString + 'static)` + | | + | required by this bound in `Foo::Out` error[E0599]: no function or associated item named `default` found for trait object `(dyn ToString + 'static)` in the current scope --> $DIR/issue-43924.rs:14:39 diff --git a/src/test/ui/associated-types/issue-54108.stderr b/src/test/ui/associated-types/issue-54108.stderr index 927a2de996561..2bf61c50ed695 100644 --- a/src/test/ui/associated-types/issue-54108.stderr +++ b/src/test/ui/associated-types/issue-54108.stderr @@ -1,11 +1,11 @@ error[E0277]: cannot add `::ActualSize` to `::ActualSize` - --> $DIR/issue-54108.rs:19:5 + --> $DIR/issue-54108.rs:19:17 | LL | type Size: Add; | ------------------------ required by this bound in `Encoder::Size` ... LL | type Size = ::ActualSize; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `::ActualSize + ::ActualSize` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `::ActualSize + ::ActualSize` | = help: the trait `Add` is not implemented for `::ActualSize` help: consider further restricting the associated type diff --git a/src/test/ui/associated-types/issue-63593.stderr b/src/test/ui/associated-types/issue-63593.stderr index 16ae07687e2c7..d4654c7d5ace0 100644 --- a/src/test/ui/associated-types/issue-63593.stderr +++ b/src/test/ui/associated-types/issue-63593.stderr @@ -1,10 +1,10 @@ error[E0277]: the size for values of type `Self` cannot be known at compilation time - --> $DIR/issue-63593.rs:9:5 + --> $DIR/issue-63593.rs:9:17 | LL | type This = Self; - | ^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time + | ------------^^^^- + | | | + | | doesn't have a size known at compile-time | required by this bound in `MyTrait::This` | help: consider further restricting `Self` diff --git a/src/test/ui/associated-types/issue-65774-1.stderr b/src/test/ui/associated-types/issue-65774-1.stderr index fc020e40b5ad2..30b14d1bc590f 100644 --- a/src/test/ui/associated-types/issue-65774-1.stderr +++ b/src/test/ui/associated-types/issue-65774-1.stderr @@ -1,11 +1,10 @@ error[E0277]: the trait bound `T: MyDisplay` is not satisfied - --> $DIR/issue-65774-1.rs:10:5 + --> $DIR/issue-65774-1.rs:10:33 | LL | type MpuConfig: MyDisplay = T; - | ^^^^^^^^^^^^^^^^---------^^^^^ - | | | - | | required by this bound in `MPU::MpuConfig` - | the trait `MyDisplay` is not implemented for `T` + | --------- ^ the trait `MyDisplay` is not implemented for `T` + | | + | required by this bound in `MPU::MpuConfig` error[E0277]: the trait bound `T: MyDisplay` is not satisfied --> $DIR/issue-65774-1.rs:44:76 diff --git a/src/test/ui/associated-types/issue-65774-2.stderr b/src/test/ui/associated-types/issue-65774-2.stderr index 572a9cf190952..f00a95b4d017a 100644 --- a/src/test/ui/associated-types/issue-65774-2.stderr +++ b/src/test/ui/associated-types/issue-65774-2.stderr @@ -1,11 +1,10 @@ error[E0277]: the trait bound `T: MyDisplay` is not satisfied - --> $DIR/issue-65774-2.rs:10:5 + --> $DIR/issue-65774-2.rs:10:33 | LL | type MpuConfig: MyDisplay = T; - | ^^^^^^^^^^^^^^^^---------^^^^^ - | | | - | | required by this bound in `MPU::MpuConfig` - | the trait `MyDisplay` is not implemented for `T` + | --------- ^ the trait `MyDisplay` is not implemented for `T` + | | + | required by this bound in `MPU::MpuConfig` error[E0277]: the trait bound `T: MyDisplay` is not satisfied --> $DIR/issue-65774-2.rs:39:25 diff --git a/src/test/ui/associated-types/issue-72806.stderr b/src/test/ui/associated-types/issue-72806.stderr index 23fabbee1c5d4..fac3fdbe82010 100644 --- a/src/test/ui/associated-types/issue-72806.stderr +++ b/src/test/ui/associated-types/issue-72806.stderr @@ -1,11 +1,11 @@ error[E0271]: type mismatch resolving `::Ok == char` - --> $DIR/issue-72806.rs:14:5 + --> $DIR/issue-72806.rs:14:20 | LL | type Sibling: Bar2; | ------- required by this bound in `Bar::Sibling` ... LL | type Sibling = Foo2; - | ^^^^^^^^^^^^^^^^^^^^ expected `char`, found `u32` + | ^^^^ expected `char`, found `u32` error: aborting due to previous error diff --git a/src/test/ui/associated-types/point-at-type-on-obligation-failure-2.stderr b/src/test/ui/associated-types/point-at-type-on-obligation-failure-2.stderr index b23030d7cb52b..88d3da52e9483 100644 --- a/src/test/ui/associated-types/point-at-type-on-obligation-failure-2.stderr +++ b/src/test/ui/associated-types/point-at-type-on-obligation-failure-2.stderr @@ -1,14 +1,14 @@ error[E0277]: the trait bound `bool: Bar` is not satisfied - --> $DIR/point-at-type-on-obligation-failure-2.rs:8:5 + --> $DIR/point-at-type-on-obligation-failure-2.rs:8:18 | LL | type Assoc: Bar; | --- required by this bound in `Foo::Assoc` ... LL | type Assoc = bool; - | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool` + | ^^^^ the trait `Bar` is not implemented for `bool` error[E0277]: the trait bound `bool: Bar` is not satisfied - --> $DIR/point-at-type-on-obligation-failure-2.rs:19:5 + --> $DIR/point-at-type-on-obligation-failure-2.rs:19:18 | LL | Self::Assoc: Bar, | --- required by this bound in `Baz::Assoc` @@ -17,10 +17,10 @@ LL | type Assoc; | ----- required by a bound in this ... LL | type Assoc = bool; - | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool` + | ^^^^ the trait `Bar` is not implemented for `bool` error[E0277]: the trait bound `bool: Bar` is not satisfied - --> $DIR/point-at-type-on-obligation-failure-2.rs:30:5 + --> $DIR/point-at-type-on-obligation-failure-2.rs:30:18 | LL | ::Assoc: Bar, | --- required by this bound in `Bat::Assoc` @@ -29,7 +29,7 @@ LL | type Assoc; | ----- required by a bound in this ... LL | type Assoc = bool; - | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool` + | ^^^^ the trait `Bar` is not implemented for `bool` error: aborting due to 3 previous errors diff --git a/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr b/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr index 7417a5aa3d43a..f0fa2bbc4d104 100644 --- a/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr +++ b/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr @@ -1,11 +1,11 @@ error[E0271]: type mismatch resolving `::Ok == ()` - --> $DIR/point-at-type-on-obligation-failure.rs:14:5 + --> $DIR/point-at-type-on-obligation-failure.rs:14:20 | LL | type Sibling: Bar2; | ----------- required by this bound in `Bar::Sibling` ... LL | type Sibling = Foo2; - | ^^^^^^^^^^^^^^^^^^^^ expected `()`, found `u32` + | ^^^^ expected `()`, found `u32` error: aborting due to previous error diff --git a/src/test/ui/chalkify/impl_wf_2.stderr b/src/test/ui/chalkify/impl_wf_2.stderr index 1da2144c0a5d4..ef218aa937e76 100644 --- a/src/test/ui/chalkify/impl_wf_2.stderr +++ b/src/test/ui/chalkify/impl_wf_2.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `f32: Foo` is not satisfied - --> $DIR/impl_wf_2.rs:25:5 + --> $DIR/impl_wf_2.rs:25:17 | LL | type Item: Foo; | --- required by this bound in `Bar::Item` ... LL | type Item = f32; - | ^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `f32` + | ^^^ the trait `Foo` is not implemented for `f32` error: aborting due to previous error diff --git a/src/test/ui/const-generics/associated-type-bound-fail.full.stderr b/src/test/ui/const-generics/associated-type-bound-fail.full.stderr index 6644e74f97a0b..0ebf9bdd7ad7c 100644 --- a/src/test/ui/const-generics/associated-type-bound-fail.full.stderr +++ b/src/test/ui/const-generics/associated-type-bound-fail.full.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `u16: Bar` is not satisfied - --> $DIR/associated-type-bound-fail.rs:13:5 + --> $DIR/associated-type-bound-fail.rs:13:18 | LL | type Assoc: Bar; | ------ required by this bound in `Foo::Assoc` ... LL | type Assoc = u16; - | ^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `u16` + | ^^^ the trait `Bar` is not implemented for `u16` | = help: the following implementations were found: > diff --git a/src/test/ui/const-generics/associated-type-bound-fail.min.stderr b/src/test/ui/const-generics/associated-type-bound-fail.min.stderr index 6644e74f97a0b..0ebf9bdd7ad7c 100644 --- a/src/test/ui/const-generics/associated-type-bound-fail.min.stderr +++ b/src/test/ui/const-generics/associated-type-bound-fail.min.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `u16: Bar` is not satisfied - --> $DIR/associated-type-bound-fail.rs:13:5 + --> $DIR/associated-type-bound-fail.rs:13:18 | LL | type Assoc: Bar; | ------ required by this bound in `Foo::Assoc` ... LL | type Assoc = u16; - | ^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `u16` + | ^^^ the trait `Bar` is not implemented for `u16` | = help: the following implementations were found: > diff --git a/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr b/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr index 4afbde5021f91..82a18bf92ece1 100644 --- a/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr +++ b/src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr @@ -62,10 +62,10 @@ LL | type Assoc where Self: Sized = Foo; = help: add `#![feature(generic_associated_types)]` to the crate attributes to enable error[E0277]: the trait bound `U32: Clone` is not satisfied - --> $DIR/feature-gate-generic_associated_types.rs:16:5 + --> $DIR/feature-gate-generic_associated_types.rs:16:26 | LL | type Pointer2 = Box; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `U32` + | ^^^^^^^^ the trait `Clone` is not implemented for `U32` | help: consider restricting type parameter `U32` | diff --git a/src/test/ui/generic-associated-types/cross-crate-bounds.stderr b/src/test/ui/generic-associated-types/cross-crate-bounds.stderr index d96c5f4540ef5..f004b42d1f3e7 100644 --- a/src/test/ui/generic-associated-types/cross-crate-bounds.stderr +++ b/src/test/ui/generic-associated-types/cross-crate-bounds.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `(): AsRef<()>` is not satisfied - --> $DIR/cross-crate-bounds.rs:15:5 + --> $DIR/cross-crate-bounds.rs:15:16 | LL | type Bar = (); - | ^^^^^^^^^^^^^^ the trait `AsRef<()>` is not implemented for `()` + | ^^ the trait `AsRef<()>` is not implemented for `()` | ::: $DIR/auxiliary/foo_defn.rs:6:15 | diff --git a/src/test/ui/generic-associated-types/generic-associated-types-where.stderr b/src/test/ui/generic-associated-types/generic-associated-types-where.stderr index da8b625ea7f75..047b756635aa5 100644 --- a/src/test/ui/generic-associated-types/generic-associated-types-where.stderr +++ b/src/test/ui/generic-associated-types/generic-associated-types-where.stderr @@ -1,8 +1,8 @@ error[E0277]: `T` doesn't implement `std::fmt::Display` - --> $DIR/generic-associated-types-where.rs:21:5 + --> $DIR/generic-associated-types-where.rs:21:22 | LL | type Assoc2 = Vec; - | ^^^^^^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted with the default formatter + | ^^^^^^ `T` cannot be formatted with the default formatter | = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead help: consider restricting type parameter `T` @@ -11,13 +11,13 @@ LL | type Assoc2 = Vec; | ^^^^^^^^^^^^^^^^^^^ error[E0276]: impl has stricter requirements than trait - --> $DIR/generic-associated-types-where.rs:23:5 + --> $DIR/generic-associated-types-where.rs:23:40 | LL | type Assoc3; | --------------- definition of `Assoc3` from trait ... LL | type Assoc3 where T: Iterator = Vec; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: Iterator` + | ^^^^^^ impl has extra requirement `T: Iterator` error: aborting due to 2 previous errors diff --git a/src/test/ui/generic-associated-types/impl_bounds.stderr b/src/test/ui/generic-associated-types/impl_bounds.stderr index 58bcb13e68ebd..9c2b9d1440e5e 100644 --- a/src/test/ui/generic-associated-types/impl_bounds.stderr +++ b/src/test/ui/generic-associated-types/impl_bounds.stderr @@ -1,17 +1,17 @@ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/impl_bounds.rs:16:5 + --> $DIR/impl_bounds.rs:16:39 | LL | type A<'a> where Self: 'static = (&'a ()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ | = help: consider adding an explicit lifetime bound `T: 'static`... = note: ...so that the type `Fooy` will meet its required lifetime bounds error[E0478]: lifetime bound not satisfied - --> $DIR/impl_bounds.rs:18:5 + --> $DIR/impl_bounds.rs:18:35 | LL | type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ | note: lifetime parameter instantiated with the lifetime `'b` as defined on the associated item at 18:16 --> $DIR/impl_bounds.rs:18:16 @@ -25,10 +25,10 @@ LL | type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); | ^^ error[E0478]: lifetime bound not satisfied - --> $DIR/impl_bounds.rs:18:5 + --> $DIR/impl_bounds.rs:18:35 | LL | type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ | note: lifetime parameter instantiated with the lifetime `'a` as defined on the associated item at 18:12 --> $DIR/impl_bounds.rs:18:12 @@ -42,10 +42,10 @@ LL | type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); | ^^ error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/impl_bounds.rs:21:5 + --> $DIR/impl_bounds.rs:21:31 | LL | type C where Self: Copy = String; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T` + | ^^^^^^ the trait `Copy` is not implemented for `T` | = note: required because of the requirements on the impl of `Copy` for `Fooy` note: the requirement `Fooy: Copy` appears on the associated impl type `C` but not on the corresponding associated trait type diff --git a/src/test/ui/generic-associated-types/issue-47206-where-clause.stderr b/src/test/ui/generic-associated-types/issue-47206-where-clause.stderr index 439b8ab90c9d8..6d9f081f5ca29 100644 --- a/src/test/ui/generic-associated-types/issue-47206-where-clause.stderr +++ b/src/test/ui/generic-associated-types/issue-47206-where-clause.stderr @@ -1,11 +1,11 @@ error[E0276]: impl has stricter requirements than trait - --> $DIR/issue-47206-where-clause.rs:13:5 + --> $DIR/issue-47206-where-clause.rs:13:40 | LL | type Assoc3; | --------------- definition of `Assoc3` from trait ... LL | type Assoc3 where T: Iterator = Vec; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: Iterator` + | ^^^^^^ impl has extra requirement `T: Iterator` error: aborting due to previous error diff --git a/src/test/ui/generic-associated-types/issue-68641-check-gat-bounds.stderr b/src/test/ui/generic-associated-types/issue-68641-check-gat-bounds.stderr index c92800c3746ad..fae959476f1ff 100644 --- a/src/test/ui/generic-associated-types/issue-68641-check-gat-bounds.stderr +++ b/src/test/ui/generic-associated-types/issue-68641-check-gat-bounds.stderr @@ -8,13 +8,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/issue-68641-check-gat-bounds.rs:15:5 + --> $DIR/issue-68641-check-gat-bounds.rs:15:21 | LL | type Item<'a>: Copy; | ---- required by this bound in `UnsafeCopy::Item` ... LL | type Item<'a> = T; - | ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T` + | ^ the trait `Copy` is not implemented for `T` | help: consider restricting type parameter `T` | diff --git a/src/test/ui/generic-associated-types/issue-68642-broken-llvm-ir.stderr b/src/test/ui/generic-associated-types/issue-68642-broken-llvm-ir.stderr index e44547b10c17b..320d267701a23 100644 --- a/src/test/ui/generic-associated-types/issue-68642-broken-llvm-ir.stderr +++ b/src/test/ui/generic-associated-types/issue-68642-broken-llvm-ir.stderr @@ -8,13 +8,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: expected a `Fn<()>` closure, found `T` - --> $DIR/issue-68642-broken-llvm-ir.rs:15:5 + --> $DIR/issue-68642-broken-llvm-ir.rs:15:18 | LL | type F<'a>: Fn() -> u32; | ----------- required by this bound in `Fun::F` ... LL | type F<'a> = Self; - | ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T` + | ^^^^ expected an `Fn<()>` closure, found `T` | = note: wrap the `T` in a closure with no arguments: `|| { /* code */ }` help: consider restricting type parameter `T` diff --git a/src/test/ui/generic-associated-types/issue-68643-broken-mir.stderr b/src/test/ui/generic-associated-types/issue-68643-broken-mir.stderr index fd0b4733d9359..9469ffc787680 100644 --- a/src/test/ui/generic-associated-types/issue-68643-broken-mir.stderr +++ b/src/test/ui/generic-associated-types/issue-68643-broken-mir.stderr @@ -8,13 +8,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: expected a `Fn<()>` closure, found `T` - --> $DIR/issue-68643-broken-mir.rs:15:5 + --> $DIR/issue-68643-broken-mir.rs:15:18 | LL | type F<'a>: Fn() -> u32; | ----------- required by this bound in `Fun::F` ... LL | type F<'a> = Self; - | ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T` + | ^^^^ expected an `Fn<()>` closure, found `T` | = note: wrap the `T` in a closure with no arguments: `|| { /* code */ }` help: consider restricting type parameter `T` diff --git a/src/test/ui/generic-associated-types/issue-68644-codegen-selection.stderr b/src/test/ui/generic-associated-types/issue-68644-codegen-selection.stderr index 0c23c870f0106..0604df49b2be7 100644 --- a/src/test/ui/generic-associated-types/issue-68644-codegen-selection.stderr +++ b/src/test/ui/generic-associated-types/issue-68644-codegen-selection.stderr @@ -8,13 +8,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: expected a `Fn<()>` closure, found `T` - --> $DIR/issue-68644-codegen-selection.rs:15:5 + --> $DIR/issue-68644-codegen-selection.rs:15:18 | LL | type F<'a>: Fn() -> u32; | ----------- required by this bound in `Fun::F` ... LL | type F<'a> = Self; - | ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T` + | ^^^^ expected an `Fn<()>` closure, found `T` | = note: wrap the `T` in a closure with no arguments: `|| { /* code */ }` help: consider restricting type parameter `T` diff --git a/src/test/ui/generic-associated-types/issue-68645-codegen-fulfillment.stderr b/src/test/ui/generic-associated-types/issue-68645-codegen-fulfillment.stderr index 85d8d3f8e936e..3131e1969704e 100644 --- a/src/test/ui/generic-associated-types/issue-68645-codegen-fulfillment.stderr +++ b/src/test/ui/generic-associated-types/issue-68645-codegen-fulfillment.stderr @@ -8,13 +8,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: expected a `Fn<()>` closure, found `T` - --> $DIR/issue-68645-codegen-fulfillment.rs:15:5 + --> $DIR/issue-68645-codegen-fulfillment.rs:15:18 | LL | type F<'a>: Fn() -> u32; | ----------- required by this bound in `Fun::F` ... LL | type F<'a> = Self; - | ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T` + | ^^^^ expected an `Fn<()>` closure, found `T` | = note: wrap the `T` in a closure with no arguments: `|| { /* code */ }` help: consider restricting type parameter `T` diff --git a/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr b/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr index c4ee2c4e61872..b30f1573983d5 100644 --- a/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr +++ b/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr @@ -8,7 +8,7 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0271]: type mismatch resolving `::Target == T` - --> $DIR/issue-68656-unsized-values.rs:16:5 + --> $DIR/issue-68656-unsized-values.rs:16:21 | LL | type Item<'a>: std::ops::Deref; | ---------- required by this bound in `UnsafeCopy::Item` @@ -16,7 +16,7 @@ LL | type Item<'a>: std::ops::Deref; LL | impl UnsafeCopy for T { | - this type parameter LL | type Item<'a> = T; - | ^^^^^^^^^^^^^^^^^^ expected type parameter `T`, found associated type + | ^ expected type parameter `T`, found associated type | = note: expected type parameter `T` found associated type `::Target` diff --git a/src/test/ui/generic-associated-types/issue-74816.stderr b/src/test/ui/generic-associated-types/issue-74816.stderr index 64bc94d601b78..ecafbfc6f0c2f 100644 --- a/src/test/ui/generic-associated-types/issue-74816.stderr +++ b/src/test/ui/generic-associated-types/issue-74816.stderr @@ -1,11 +1,10 @@ error[E0277]: the trait bound `Self: Trait1` is not satisfied - --> $DIR/issue-74816.rs:10:5 + --> $DIR/issue-74816.rs:10:31 | LL | type Associated: Trait1 = Self; - | ^^^^^^^^^^^^^^^^^------^^^^^^^^ - | | | - | | required by this bound in `Trait2::Associated` - | the trait `Trait1` is not implemented for `Self` + | ------ ^^^^ the trait `Trait1` is not implemented for `Self` + | | + | required by this bound in `Trait2::Associated` | help: consider further restricting `Self` | @@ -13,12 +12,12 @@ LL | trait Trait2: Trait1 { | ^^^^^^^^ error[E0277]: the size for values of type `Self` cannot be known at compilation time - --> $DIR/issue-74816.rs:10:5 + --> $DIR/issue-74816.rs:10:31 | LL | type Associated: Trait1 = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | doesn't have a size known at compile-time + | --------------------------^^^^- + | | | + | | doesn't have a size known at compile-time | required by this bound in `Trait2::Associated` | help: consider further restricting `Self` diff --git a/src/test/ui/generic-associated-types/issue-74824.stderr b/src/test/ui/generic-associated-types/issue-74824.stderr index 7a7b5fd4f1c55..4b2d8c4128944 100644 --- a/src/test/ui/generic-associated-types/issue-74824.stderr +++ b/src/test/ui/generic-associated-types/issue-74824.stderr @@ -1,20 +1,18 @@ error[E0277]: the trait bound `Box: Copy` is not satisfied - --> $DIR/issue-74824.rs:8:5 + --> $DIR/issue-74824.rs:8:26 | LL | type Copy: Copy = Box; - | ^^^^^^^^^^^^^^----^^^^^^^^^^ - | | | - | | required by this bound in `UnsafeCopy::Copy` - | the trait `Copy` is not implemented for `Box` + | ---- ^^^^^^ the trait `Copy` is not implemented for `Box` + | | + | required by this bound in `UnsafeCopy::Copy` error[E0277]: the trait bound `T: Clone` is not satisfied - --> $DIR/issue-74824.rs:8:5 + --> $DIR/issue-74824.rs:8:26 | LL | type Copy: Copy = Box; - | ^^^^^^^^^^^^^^----^^^^^^^^^^ - | | | - | | required by this bound in `UnsafeCopy::Copy` - | the trait `Clone` is not implemented for `T` + | ---- ^^^^^^ the trait `Clone` is not implemented for `T` + | | + | required by this bound in `UnsafeCopy::Copy` | = note: required because of the requirements on the impl of `Clone` for `Box` help: consider restricting type parameter `T` diff --git a/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr b/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr index 5d612284a2187..816144b6f0d58 100644 --- a/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr +++ b/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr @@ -1,8 +1,8 @@ error[E0477]: the type `&'b ()` does not fulfill the required lifetime - --> $DIR/unsatisfied-outlives-bound.rs:9:5 + --> $DIR/unsatisfied-outlives-bound.rs:9:21 | LL | type Item<'a> = &'b (); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ | note: type must outlive the lifetime `'a` as defined on the associated item at 9:15 --> $DIR/unsatisfied-outlives-bound.rs:9:15 @@ -11,10 +11,10 @@ LL | type Item<'a> = &'b (); | ^^ error[E0477]: the type `&'a ()` does not fulfill the required lifetime - --> $DIR/unsatisfied-outlives-bound.rs:18:5 + --> $DIR/unsatisfied-outlives-bound.rs:18:21 | LL | type Item<'a> = &'a (); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ | = note: type must satisfy the static lifetime diff --git a/src/test/ui/never_type/issue-51506.stderr b/src/test/ui/never_type/issue-51506.stderr index 16d93c18900a9..ebb23145a8e84 100644 --- a/src/test/ui/never_type/issue-51506.stderr +++ b/src/test/ui/never_type/issue-51506.stderr @@ -1,11 +1,11 @@ error[E0277]: `!` is not an iterator - --> $DIR/issue-51506.rs:13:5 + --> $DIR/issue-51506.rs:13:24 | LL | type Out: Iterator; | -------------------- required by this bound in `Trait::Out` ... LL | default type Out = !; - | ^^^^^^^^^^^^^^^^^^^^^ `!` is not an iterator + | ^ `!` is not an iterator | = help: the trait `Iterator` is not implemented for `!` diff --git a/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr b/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr index 03da33ae11ffe..24e053b4f6011 100644 --- a/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr +++ b/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr @@ -1,16 +1,16 @@ error[E0477]: the type `&'a i32` does not fulfill the required lifetime - --> $DIR/regions-assoc-type-region-bound-in-trait-not-met.rs:15:5 + --> $DIR/regions-assoc-type-region-bound-in-trait-not-met.rs:15:18 | LL | type Value = &'a i32; - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ | = note: type must satisfy the static lifetime error[E0477]: the type `&'a i32` does not fulfill the required lifetime - --> $DIR/regions-assoc-type-region-bound-in-trait-not-met.rs:20:5 + --> $DIR/regions-assoc-type-region-bound-in-trait-not-met.rs:20:18 | LL | type Value = &'a i32; - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ | note: type must outlive the lifetime `'b` as defined on the impl at 19:10 --> $DIR/regions-assoc-type-region-bound-in-trait-not-met.rs:19:10 diff --git a/src/test/ui/regions/regions-assoc-type-static-bound-in-trait-not-met.stderr b/src/test/ui/regions/regions-assoc-type-static-bound-in-trait-not-met.stderr index d8efeac5b8a30..efc7428808ed3 100644 --- a/src/test/ui/regions/regions-assoc-type-static-bound-in-trait-not-met.stderr +++ b/src/test/ui/regions/regions-assoc-type-static-bound-in-trait-not-met.stderr @@ -1,8 +1,8 @@ error[E0477]: the type `&'a i32` does not fulfill the required lifetime - --> $DIR/regions-assoc-type-static-bound-in-trait-not-met.rs:10:5 + --> $DIR/regions-assoc-type-static-bound-in-trait-not-met.rs:10:18 | LL | type Value = &'a i32; - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ | = note: type must satisfy the static lifetime diff --git a/src/test/ui/specialization/deafult-associated-type-bound-1.stderr b/src/test/ui/specialization/deafult-associated-type-bound-1.stderr index 4ca3d83119839..aaad03eadf834 100644 --- a/src/test/ui/specialization/deafult-associated-type-bound-1.stderr +++ b/src/test/ui/specialization/deafult-associated-type-bound-1.stderr @@ -9,13 +9,13 @@ LL | #![feature(specialization)] = help: consider using `min_specialization` instead, which is more stable and complete error[E0277]: the trait bound `str: Clone` is not satisfied - --> $DIR/deafult-associated-type-bound-1.rs:19:5 + --> $DIR/deafult-associated-type-bound-1.rs:19:22 | LL | type U: Clone; | ----- required by this bound in `X::U` ... LL | default type U = str; - | ^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `str` + | ^^^ the trait `Clone` is not implemented for `str` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/specialization/deafult-associated-type-bound-2.stderr b/src/test/ui/specialization/deafult-associated-type-bound-2.stderr index 0e8a774bce37f..053e1f8500a62 100644 --- a/src/test/ui/specialization/deafult-associated-type-bound-2.stderr +++ b/src/test/ui/specialization/deafult-associated-type-bound-2.stderr @@ -9,13 +9,13 @@ LL | #![feature(specialization)] = help: consider using `min_specialization` instead, which is more stable and complete error[E0277]: can't compare `&'static B` with `B` - --> $DIR/deafult-associated-type-bound-2.rs:16:5 + --> $DIR/deafult-associated-type-bound-2.rs:16:22 | LL | type U: PartialEq; | ------------ required by this bound in `X::U` ... LL | default type U = &'static B; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&'static B == B` + | ^^^^^^^^^^ no implementation for `&'static B == B` | = help: the trait `PartialEq` is not implemented for `&'static B` help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement diff --git a/src/test/ui/specialization/deafult-generic-associated-type-bound.stderr b/src/test/ui/specialization/deafult-generic-associated-type-bound.stderr index eb5d80bc4dda6..749a4a8420a26 100644 --- a/src/test/ui/specialization/deafult-generic-associated-type-bound.stderr +++ b/src/test/ui/specialization/deafult-generic-associated-type-bound.stderr @@ -17,13 +17,13 @@ LL | #![feature(generic_associated_types)] = note: see issue #44265 for more information error[E0277]: can't compare `T` with `T` - --> $DIR/deafult-generic-associated-type-bound.rs:19:5 + --> $DIR/deafult-generic-associated-type-bound.rs:19:26 | LL | type U<'a>: PartialEq<&'a Self> where Self: 'a; | ------------------- required by this bound in `X::U` ... LL | default type U<'a> = &'a T; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `T == T` + | ^^^^^ no implementation for `T == T` | = note: required because of the requirements on the impl of `PartialEq` for `&'a T` help: consider further restricting this bound diff --git a/src/test/ui/specialization/issue-33017.stderr b/src/test/ui/specialization/issue-33017.stderr index bff4618d0be4c..27e2d09eb44cc 100644 --- a/src/test/ui/specialization/issue-33017.stderr +++ b/src/test/ui/specialization/issue-33017.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/issue-33017.rs:12:5 + --> $DIR/issue-33017.rs:12:27 | LL | type Output: From + Copy + Into; | ---- required by this bound in `UncheckedCopy::Output` ... LL | default type Output = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T` + | ^^^^ the trait `Copy` is not implemented for `T` | help: consider restricting type parameter `T` | diff --git a/src/test/ui/specialization/issue-38091.stderr b/src/test/ui/specialization/issue-38091.stderr index 97e5775ab54ee..3c089c9f005c9 100644 --- a/src/test/ui/specialization/issue-38091.stderr +++ b/src/test/ui/specialization/issue-38091.stderr @@ -9,13 +9,13 @@ LL | #![feature(specialization)] = help: consider using `min_specialization` instead, which is more stable and complete error[E0277]: the trait bound `(): Valid` is not satisfied - --> $DIR/issue-38091.rs:12:5 + --> $DIR/issue-38091.rs:12:23 | LL | type Ty: Valid; | ----- required by this bound in `Iterate::Ty` ... LL | default type Ty = (); - | ^^^^^^^^^^^^^^^^^^^^^ the trait `Valid` is not implemented for `()` + | ^^ the trait `Valid` is not implemented for `()` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/specialization/issue-44861.stderr b/src/test/ui/specialization/issue-44861.stderr index 3935a4a5f9931..eca43e2f75165 100644 --- a/src/test/ui/specialization/issue-44861.stderr +++ b/src/test/ui/specialization/issue-44861.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `(): CoerceUnsized<*const [u8]>` is not satisfied - --> $DIR/issue-44861.rs:21:5 + --> $DIR/issue-44861.rs:21:26 | LL | type Data2: CoerceUnsized<*const [u8]>; | -------------------------- required by this bound in `Smartass::Data2` ... LL | default type Data2 = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `CoerceUnsized<*const [u8]>` is not implemented for `()` + | ^^ the trait `CoerceUnsized<*const [u8]>` is not implemented for `()` error: aborting due to previous error diff --git a/src/test/ui/specialization/issue-59435.stderr b/src/test/ui/specialization/issue-59435.stderr index f3f8b022b01e1..aa9d611331d7b 100644 --- a/src/test/ui/specialization/issue-59435.stderr +++ b/src/test/ui/specialization/issue-59435.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `MyStruct: Default` is not satisfied - --> $DIR/issue-59435.rs:11:5 + --> $DIR/issue-59435.rs:11:27 | LL | type MyType: Default; | ------- required by this bound in `MyTrait::MyType` ... LL | default type MyType = MyStruct; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `MyStruct` + | ^^^^^^^^ the trait `Default` is not implemented for `MyStruct` error: aborting due to previous error diff --git a/src/test/ui/traits/inductive-overflow/two-traits.stderr b/src/test/ui/traits/inductive-overflow/two-traits.stderr index 508a12d859a62..6a39a28df3501 100644 --- a/src/test/ui/traits/inductive-overflow/two-traits.stderr +++ b/src/test/ui/traits/inductive-overflow/two-traits.stderr @@ -1,11 +1,11 @@ error[E0277]: `T` cannot be shared between threads safely - --> $DIR/two-traits.rs:11:5 + --> $DIR/two-traits.rs:11:14 | LL | type X: Trait; | ----- required by this bound in `Magic::X` ... LL | type X = Self; - | ^^^^^^^^^^^^^^ `T` cannot be shared between threads safely + | ^^^^ `T` cannot be shared between threads safely | help: consider further restricting this bound | diff --git a/src/test/ui/traits/issue-65673.stderr b/src/test/ui/traits/issue-65673.stderr index 64cc0bab3f33c..6f9bb3edfe047 100644 --- a/src/test/ui/traits/issue-65673.stderr +++ b/src/test/ui/traits/issue-65673.stderr @@ -1,11 +1,11 @@ error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time - --> $DIR/issue-65673.rs:9:5 + --> $DIR/issue-65673.rs:9:16 | LL | type Ctx; | --------- required by this bound in `WithType::Ctx` ... LL | type Ctx = dyn Alias; - | ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | ^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `(dyn Trait + 'static)` From 280d4e1c37da5054fc21299bf24a814934c9d779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 28 May 2021 20:29:33 -0700 Subject: [PATCH 02/11] Point at `impl` assoc type on projection error --- .../src/traits/error_reporting/mod.rs | 32 +++++++++++++++++++ ...nding-to-type-defined-in-supertrait.stderr | 6 ++++ .../associated-types-eq-3.stderr | 6 ++++ .../associated-types-eq-hr.stderr | 6 ++++ .../associated-types-issue-20346.stderr | 3 ++ ...sociated-types-overridden-binding-2.stderr | 5 +++ .../ui/associated-types/issue-44153.stderr | 3 ++ .../ui/associated-types/issue-72806.stderr | 3 ++ ...point-at-type-on-obligation-failure.stderr | 3 ++ ...block-control-flow-static-semantics.stderr | 10 ++++++ src/test/ui/error-codes/E0271.stderr | 3 ++ ...erator-yielding-or-returning-itself.stderr | 10 ++++++ .../type-mismatch-signature-deduction.stderr | 5 +++ .../issue-68656-unsized-values.stderr | 5 +++ .../issue-74684-2.stderr | 3 ++ src/test/ui/hrtb/issue-62203-hrtb-ice.stderr | 8 +++++ .../bound-normalization-fail.stderr | 6 ++++ .../issues/issue-70877.full_tait.stderr | 5 +++ .../issues/issue-70877.min_tait.stderr | 5 +++ ...ction-mismatch-in-impl-where-clause.stderr | 3 ++ src/test/ui/issues/issue-31173.stderr | 5 +++ src/test/ui/issues/issue-33941.stderr | 15 +++++++++ src/test/ui/issues/issue-39970.stderr | 3 ++ .../issue-67039-unsound-pin-partialeq.stderr | 5 +++ .../ui/traits/assoc-type-in-superbad.stderr | 5 +++ .../check-trait-object-bounds-5.stderr | 3 ++ .../check-trait-object-bounds-6.stderr | 3 ++ .../ui/try-block/try-block-bad-type.stderr | 10 ++++++ .../ui/try-block/try-block-type-error.stderr | 10 ++++++ .../issue-63279.full_tait.stderr | 5 +++ .../issue-63279.min_tait.stderr | 5 +++ 31 files changed, 199 insertions(+) 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 19c3385dd4cbc..ad3f3d15534c8 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1262,6 +1262,38 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { ); self.note_type_err(&mut diag, &obligation.cause, None, values, err); self.note_obligation_cause(&mut diag, obligation); + match predicate.kind().skip_binder() { + ty::PredicateKind::Projection(proj) => { + let item = self + .tcx + .opt_associated_item(proj.projection_ty.item_def_id) + .and_then(|trait_assoc_item| { + self.tcx + .trait_of_item(proj.projection_ty.item_def_id) + .map(|id| (trait_assoc_item, id)) + }) + .and_then(|(trait_assoc_item, id)| { + self.tcx.find_map_relevant_impl( + id, + proj.projection_ty.self_ty(), + |did| { + self.tcx + .associated_items(did) + .in_definition_order() + .filter(|assoc| assoc.ident == trait_assoc_item.ident) + .next() + }, + ) + }); + if let Some(item) = item { + diag.span_label( + item.ident.span, + &format!("type mismatch with `{}` here", proj.ty), + ); + } + } + _ => {} + } diag.emit(); } }); diff --git a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr index 029c923aa7d4a..a6063aaa7b40c 100644 --- a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr +++ b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr @@ -1,6 +1,9 @@ error[E0271]: type mismatch resolving `::Color == Blue` --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:31:10 | +LL | impl Vehicle for ModelT { type Color = Black; } + | ----- type mismatch with `Blue` here +... LL | fn blue_car>(c: C) { | ---------- required by this bound in `blue_car` ... @@ -10,6 +13,9 @@ LL | fn b() { blue_car(ModelT); } error[E0271]: type mismatch resolving `::Color == Black` --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:10 | +LL | impl Vehicle for ModelU { type Color = Blue; } + | ----- type mismatch with `Black` here +... LL | fn black_car>(c: C) { | ----------- required by this bound in `black_car` ... 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 dffa4780a09ff..4d4b6ab277c35 100644 --- a/src/test/ui/associated-types/associated-types-eq-3.stderr +++ b/src/test/ui/associated-types/associated-types-eq-3.stderr @@ -16,6 +16,9 @@ LL | fn foo2>(x: I) { error[E0271]: type mismatch resolving `::A == Bar` --> $DIR/associated-types-eq-3.rs:38:5 | +LL | type A = usize; + | - type mismatch with `Bar` here +... LL | fn foo1>(x: I) { | ----- required by this bound in `foo1` ... @@ -25,6 +28,9 @@ LL | foo1(a); error[E0271]: type mismatch resolving `::A == Bar` --> $DIR/associated-types-eq-3.rs:41:9 | +LL | type A = usize; + | - type mismatch with `Bar` here +... LL | baz(&a); | ^^ expected struct `Bar`, found `usize` | diff --git a/src/test/ui/associated-types/associated-types-eq-hr.stderr b/src/test/ui/associated-types/associated-types-eq-hr.stderr index 6897b31fe4685..4951b308ba97b 100644 --- a/src/test/ui/associated-types/associated-types-eq-hr.stderr +++ b/src/test/ui/associated-types/associated-types-eq-hr.stderr @@ -1,6 +1,9 @@ error[E0271]: type mismatch resolving `for<'x> >::A == &'x isize` --> $DIR/associated-types-eq-hr.rs:87:5 | +LL | type A = &'a usize; + | - type mismatch with `&'x isize` here +... LL | fn foo() | --- required by a bound in this LL | where @@ -16,6 +19,9 @@ LL | foo::(); error[E0271]: type mismatch resolving `for<'x> >::A == &'x usize` --> $DIR/associated-types-eq-hr.rs:91:5 | +LL | type A = &'a isize; + | - type mismatch with `&'x usize` here +... LL | fn bar() | --- required by a bound in this LL | where diff --git a/src/test/ui/associated-types/associated-types-issue-20346.stderr b/src/test/ui/associated-types/associated-types-issue-20346.stderr index 7193d4163b9ce..e738506c55799 100644 --- a/src/test/ui/associated-types/associated-types-issue-20346.stderr +++ b/src/test/ui/associated-types/associated-types-issue-20346.stderr @@ -4,6 +4,9 @@ error[E0271]: type mismatch resolving ` as Iterator>::Item == Option< LL | fn is_iterator_of>(_: &I) {} | ------ required by this bound in `is_iterator_of` ... +LL | type Item = T; + | ---- type mismatch with `Option` here +... LL | fn test_adapter>>(it: I) { | - this type parameter ... 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 9f1abf2a6c4b6..795799bbc89b0 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 @@ -3,6 +3,11 @@ error[E0271]: type mismatch resolving ` as Iterator>::It | LL | let _: &dyn I32Iterator = &vec![42].into_iter(); | ^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32` + | + ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | +LL | type Item = I::Item; + | ---- type mismatch with `i32` here | = note: required for the cast to the object type `dyn Iterator` diff --git a/src/test/ui/associated-types/issue-44153.stderr b/src/test/ui/associated-types/issue-44153.stderr index b7db5d385829c..e1865dfb162bd 100644 --- a/src/test/ui/associated-types/issue-44153.stderr +++ b/src/test/ui/associated-types/issue-44153.stderr @@ -4,6 +4,9 @@ error[E0271]: type mismatch resolving `<() as Array>::Element == &()` LL | fn visit() {} | ---------- required by `Visit::visit` ... +LL | type Element = (); + | ------- type mismatch with `&()` here +... LL | <() as Visit>::visit(); | ^^^^^^^^^^^^^^^^^^^^ expected `&()`, found `()` | diff --git a/src/test/ui/associated-types/issue-72806.stderr b/src/test/ui/associated-types/issue-72806.stderr index fac3fdbe82010..931f242cb6321 100644 --- a/src/test/ui/associated-types/issue-72806.stderr +++ b/src/test/ui/associated-types/issue-72806.stderr @@ -6,6 +6,9 @@ LL | type Sibling: Bar2; ... LL | type Sibling = Foo2; | ^^^^ expected `char`, found `u32` +... +LL | type Ok = u32; + | -- type mismatch with `char` here error: aborting due to previous error diff --git a/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr b/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr index f0fa2bbc4d104..0d6a00d69996e 100644 --- a/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr +++ b/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr @@ -6,6 +6,9 @@ LL | type Sibling: Bar2; ... LL | type Sibling = Foo2; | ^^^^ expected `()`, found `u32` +... +LL | type Ok = u32; + | -- type mismatch with `()` here error: aborting due to previous error 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 919904ce3b6a2..4a1a3232ccd2e 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 @@ -36,6 +36,11 @@ error[E0271]: type mismatch resolving `::Output == ()` | LL | let _: &dyn Future = █ | ^^^^^^ expected `()`, found `u8` + | + ::: $SRC_DIR/core/src/future/future.rs:LL:COL + | +LL | type Output = F::Output; + | ------ type mismatch with `()` here | = note: required for the cast to the object type `dyn Future` @@ -52,6 +57,11 @@ error[E0271]: type mismatch resolving `::Output == ()` | LL | let _: &dyn Future = █ | ^^^^^^ expected `()`, found `u8` + | + ::: $SRC_DIR/core/src/future/future.rs:LL:COL + | +LL | type Output = F::Output; + | ------ type mismatch with `()` here | = note: required for the cast to the object type `dyn Future` diff --git a/src/test/ui/error-codes/E0271.stderr b/src/test/ui/error-codes/E0271.stderr index 580b5aef07e6d..bc99769b86329 100644 --- a/src/test/ui/error-codes/E0271.stderr +++ b/src/test/ui/error-codes/E0271.stderr @@ -4,6 +4,9 @@ error[E0271]: type mismatch resolving `::AssociatedType == u32` LL | fn foo(t: T) where T: Trait { | ------------------ required by this bound in `foo` ... +LL | impl Trait for i8 { type AssociatedType = &'static str; } + | -------------- type mismatch with `u32` here +... LL | foo(3_i8); | ^^^ expected `u32`, found `&str` diff --git a/src/test/ui/generator/generator-yielding-or-returning-itself.stderr b/src/test/ui/generator/generator-yielding-or-returning-itself.stderr index 5043a3be91d52..10e84f000a45b 100644 --- a/src/test/ui/generator/generator-yielding-or-returning-itself.stderr +++ b/src/test/ui/generator/generator-yielding-or-returning-itself.stderr @@ -8,6 +8,11 @@ LL | where T: Generator ... LL | want_cyclic_generator_return(|| { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size + | + ::: $SRC_DIR/core/src/ops/generator.rs:LL:COL + | +LL | type Return = G::Return; + | ------ type mismatch with `[generator@$DIR/generator-yielding-or-returning-itself.rs:15:34: 19:6]` here | = note: closures cannot capture themselves or take themselves as argument; this error may be the result of a recent compiler bug-fix, @@ -24,6 +29,11 @@ LL | where T: Generator ... LL | want_cyclic_generator_yield(|| { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size + | + ::: $SRC_DIR/core/src/ops/generator.rs:LL:COL + | +LL | type Yield = G::Yield; + | ----- type mismatch with `[generator@$DIR/generator-yielding-or-returning-itself.rs:28:33: 32:6]` here | = note: closures cannot capture themselves or take themselves as argument; this error may be the result of a recent compiler bug-fix, diff --git a/src/test/ui/generator/type-mismatch-signature-deduction.stderr b/src/test/ui/generator/type-mismatch-signature-deduction.stderr index 3f1f33a3b123f..3620b841c4697 100644 --- a/src/test/ui/generator/type-mismatch-signature-deduction.stderr +++ b/src/test/ui/generator/type-mismatch-signature-deduction.stderr @@ -17,6 +17,11 @@ error[E0271]: type mismatch resolving `<[generator@$DIR/type-mismatch-signature- | LL | fn foo() -> impl Generator { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found enum `Result` + | + ::: $SRC_DIR/core/src/ops/generator.rs:LL:COL + | +LL | type Return = G::Return; + | ------ type mismatch with `i32` here | = note: expected type `i32` found enum `Result<{integer}, _>` diff --git a/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr b/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr index b30f1573983d5..b71350324c236 100644 --- a/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr +++ b/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr @@ -17,6 +17,11 @@ LL | impl UnsafeCopy for T { | - this type parameter LL | type Item<'a> = T; | ^ expected type parameter `T`, found associated type + | + ::: $SRC_DIR/core/src/ops/deref.rs:LL:COL + | +LL | type Target = T; + | ------ type mismatch with `T` here | = note: expected type parameter `T` found associated type `::Target` diff --git a/src/test/ui/generic-associated-types/issue-74684-2.stderr b/src/test/ui/generic-associated-types/issue-74684-2.stderr index 8c3484f9a7300..c0c5bfc72283d 100644 --- a/src/test/ui/generic-associated-types/issue-74684-2.stderr +++ b/src/test/ui/generic-associated-types/issue-74684-2.stderr @@ -10,6 +10,9 @@ LL | #![feature(generic_associated_types)] error[E0271]: type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]` --> $DIR/issue-74684-2.rs:24:5 | +LL | type F<'a> = i32; + | - type mismatch with `[u8]` here +... LL | fn bug<'a, T: ?Sized + Fun = [u8]>>(t: Box) -> &'static T::F<'a> { | ------------ required by this bound in `bug` ... diff --git a/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr index 7b81beeed4167..e736fe396a5d9 100644 --- a/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr +++ b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr @@ -1,6 +1,9 @@ error[E0271]: type mismatch resolving `for<'r> as T0<'r, (>::V,)>>::O == <_ as Ty<'r>>::V` --> $DIR/issue-62203-hrtb-ice.rs:38:19 | +LL | type O = T::Output; + | - type mismatch with `<_ as Ty<'r>>::V` here +... LL | let v = Unit2.m( | ^ expected struct `Unit4`, found associated type | @@ -14,6 +17,11 @@ error[E0271]: type mismatch resolving `<[closure@$DIR/issue-62203-hrtb-ice.rs:42 | LL | let v = Unit2.m( | ^ expected struct `Unit4`, found struct `Unit3` + | + ::: $SRC_DIR/core/src/ops/function.rs:LL:COL + | +LL | type Output = F::Output; + | ------ type mismatch with `Unit3` here | note: required because of the requirements on the impl of `for<'r> T0<'r, (>::V,)>` for `L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39]>` --> $DIR/issue-62203-hrtb-ice.rs:17:16 diff --git a/src/test/ui/impl-trait/bound-normalization-fail.stderr b/src/test/ui/impl-trait/bound-normalization-fail.stderr index ba3a2e7f8d4c9..49db449b4e542 100644 --- a/src/test/ui/impl-trait/bound-normalization-fail.stderr +++ b/src/test/ui/impl-trait/bound-normalization-fail.stderr @@ -10,6 +10,9 @@ LL | #![feature(impl_trait_in_bindings)] error[E0271]: type mismatch resolving ` as FooLike>::Output == ::Assoc` --> $DIR/bound-normalization-fail.rs:26:32 | +LL | type Output = T; + | ------ type mismatch with `::Assoc` here +... LL | fn foo_fail() -> impl FooLike { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `()` | @@ -29,6 +32,9 @@ LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike { error[E0271]: type mismatch resolving ` as FooLike>::Output == >::Assoc` --> $DIR/bound-normalization-fail.rs:42:41 | +LL | type Output = T; + | ------ type mismatch with `>::Assoc` here +... LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `()` | diff --git a/src/test/ui/impl-trait/issues/issue-70877.full_tait.stderr b/src/test/ui/impl-trait/issues/issue-70877.full_tait.stderr index 8e42b9d46db39..374ffcf796645 100644 --- a/src/test/ui/impl-trait/issues/issue-70877.full_tait.stderr +++ b/src/test/ui/impl-trait/issues/issue-70877.full_tait.stderr @@ -6,6 +6,11 @@ LL | type FooRet = impl std::fmt::Debug; ... LL | type Foo = impl Iterator; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found opaque type + | + ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | +LL | type Item = I::Item; + | ---- type mismatch with `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option + 'static)>` here | = note: expected struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option + 'static)>` found struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> impl Debug + 'static)>` diff --git a/src/test/ui/impl-trait/issues/issue-70877.min_tait.stderr b/src/test/ui/impl-trait/issues/issue-70877.min_tait.stderr index 8e42b9d46db39..374ffcf796645 100644 --- a/src/test/ui/impl-trait/issues/issue-70877.min_tait.stderr +++ b/src/test/ui/impl-trait/issues/issue-70877.min_tait.stderr @@ -6,6 +6,11 @@ LL | type FooRet = impl std::fmt::Debug; ... LL | type Foo = impl Iterator; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found opaque type + | + ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | +LL | type Item = I::Item; + | ---- type mismatch with `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option + 'static)>` here | = note: expected struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option + 'static)>` found struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> impl Debug + 'static)>` diff --git a/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr b/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr index 54eb5a96c9d81..af2674ecb9628 100644 --- a/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr +++ b/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr @@ -1,6 +1,9 @@ error[E0271]: type mismatch resolving `<() as Super>::Assoc == ()` --> $DIR/projection-mismatch-in-impl-where-clause.rs:13:14 | +LL | type Assoc = u8; + | ----- type mismatch with `()` here +... LL | fn test() -> impl Test { | ^^^^^^^^^ expected `()`, found `u8` | diff --git a/src/test/ui/issues/issue-31173.stderr b/src/test/ui/issues/issue-31173.stderr index 0b7ffc39646a6..0c4f88f37ed11 100644 --- a/src/test/ui/issues/issue-31173.stderr +++ b/src/test/ui/issues/issue-31173.stderr @@ -3,6 +3,11 @@ error[E0271]: type mismatch resolving `, [ | LL | .cloned() | ^^^^^^ expected `u8`, found reference + | + ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | +LL | type Item = I::Item; + | ---- type mismatch with `&_` here | = note: expected type `u8` found reference `&_` diff --git a/src/test/ui/issues/issue-33941.stderr b/src/test/ui/issues/issue-33941.stderr index 043658c9508f3..bcc9e893a825f 100644 --- a/src/test/ui/issues/issue-33941.stderr +++ b/src/test/ui/issues/issue-33941.stderr @@ -3,6 +3,11 @@ error[E0271]: type mismatch resolving ` <() as Array<'a>>::Element == ()` LL | fn visit() {} | ---------- required by `Visit::visit` ... +LL | type Element = &'a (); + | ------- type mismatch with `()` here +... LL | <() as Visit>::visit(); | ^^^^^^^^^^^^^^^^^^^^ expected `()`, found `&()` | diff --git a/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr b/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr index 036a9300a174d..9b80568cafa5d 100644 --- a/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr +++ b/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr @@ -3,6 +3,11 @@ error[E0271]: type mismatch resolving ` as Deref>::Target == Rc | LL | let _ = Pin::new(Apple) == Rc::pin(Apple); | ^^ expected struct `Apple`, found struct `Rc` + | + ::: $SRC_DIR/core/src/ops/deref.rs:LL:COL + | +LL | type Target = T; + | ------ type mismatch with `Rc` here | = note: expected type `Apple` found struct `Rc` diff --git a/src/test/ui/traits/assoc-type-in-superbad.stderr b/src/test/ui/traits/assoc-type-in-superbad.stderr index cbdb6b96f468f..0764e691221d7 100644 --- a/src/test/ui/traits/assoc-type-in-superbad.stderr +++ b/src/test/ui/traits/assoc-type-in-superbad.stderr @@ -3,6 +3,11 @@ error[E0271]: type mismatch resolving ` as Iterator>::It | LL | type Key = u32; | ^^^ expected `i32`, found `u32` + | + ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | +LL | type Item = I::Item; + | ---- type mismatch with `u32` here error: aborting due to previous error diff --git a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr index bd2b789cd9908..43c1775a8a8a3 100644 --- a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr +++ b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr @@ -1,6 +1,9 @@ error[E0271]: type mismatch resolving `::T == i64` --> $DIR/check-trait-object-bounds-5.rs:23:5 | +LL | type T = U; + | - type mismatch with `i64` here +... LL | fn is_obj(_: &T) {} | --- required by this bound in `is_obj` ... diff --git a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr index ea1fdaf46f6ae..ecfa512846cd2 100644 --- a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr +++ b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr @@ -1,6 +1,9 @@ error[E0271]: type mismatch resolving `::T == i64` --> $DIR/check-trait-object-bounds-6.rs:20:5 | +LL | type T = U; + | - type mismatch with `i64` here +... LL | fn is_obj(_: &T) {} | --- required by this bound in `is_obj` ... diff --git a/src/test/ui/try-block/try-block-bad-type.stderr b/src/test/ui/try-block/try-block-bad-type.stderr index ec5e91f10c286..796252963dae7 100644 --- a/src/test/ui/try-block/try-block-bad-type.stderr +++ b/src/test/ui/try-block/try-block-bad-type.stderr @@ -15,12 +15,22 @@ error[E0271]: type mismatch resolving ` as Try>::Output == &str | LL | "" | ^^ expected `i32`, found `&str` + | + ::: $SRC_DIR/core/src/result.rs:LL:COL + | +LL | type Ok = T; + | -- type mismatch with `&str` here error[E0271]: type mismatch resolving ` as Try>::Output == ()` --> $DIR/try-block-bad-type.rs:15:39 | LL | let res: Result = try { }; | ^ expected `i32`, found `()` + | + ::: $SRC_DIR/core/src/result.rs:LL:COL + | +LL | type Ok = T; + | -- type mismatch with `()` here error[E0277]: a `try` block must return `Result` or `Option` (or another type that implements `Try`) --> $DIR/try-block-bad-type.rs:17:25 diff --git a/src/test/ui/try-block/try-block-type-error.stderr b/src/test/ui/try-block/try-block-type-error.stderr index 3e9a584a5510a..cc38544330aba 100644 --- a/src/test/ui/try-block/try-block-type-error.stderr +++ b/src/test/ui/try-block/try-block-type-error.stderr @@ -6,12 +6,22 @@ LL | 42 | | | expected `f32`, found integer | help: use a float literal: `42.0` + | + ::: $SRC_DIR/core/src/option.rs:LL:COL + | +LL | type Ok = T; + | -- type mismatch with `{integer}` here error[E0271]: type mismatch resolving ` as Try>::Output == ()` --> $DIR/try-block-type-error.rs:16:5 | LL | }; | ^ expected `i32`, found `()` + | + ::: $SRC_DIR/core/src/option.rs:LL:COL + | +LL | type Ok = T; + | -- type mismatch with `()` here error: aborting due to 2 previous errors diff --git a/src/test/ui/type-alias-impl-trait/issue-63279.full_tait.stderr b/src/test/ui/type-alias-impl-trait/issue-63279.full_tait.stderr index 53a0016c08eb5..de68e2433998c 100644 --- a/src/test/ui/type-alias-impl-trait/issue-63279.full_tait.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-63279.full_tait.stderr @@ -12,6 +12,11 @@ error[E0271]: type mismatch resolving `<[closure@$DIR/issue-63279.rs:11:5: 11:28 | LL | type Closure = impl FnOnce(); | ^^^^^^^^^^^^^ expected `()`, found opaque type + | + ::: $SRC_DIR/core/src/ops/function.rs:LL:COL + | +LL | type Output = F::Output; + | ------ type mismatch with `()` here | = note: expected unit type `()` found opaque type `impl FnOnce<()>` diff --git a/src/test/ui/type-alias-impl-trait/issue-63279.min_tait.stderr b/src/test/ui/type-alias-impl-trait/issue-63279.min_tait.stderr index be386ab90ea00..ea113238ea58c 100644 --- a/src/test/ui/type-alias-impl-trait/issue-63279.min_tait.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-63279.min_tait.stderr @@ -12,6 +12,11 @@ error[E0271]: type mismatch resolving `<[closure@$DIR/issue-63279.rs:11:5: 11:28 | LL | type Closure = impl FnOnce(); | ^^^^^^^^^^^^^ expected `()`, found opaque type + | + ::: $SRC_DIR/core/src/ops/function.rs:LL:COL + | +LL | type Output = F::Output; + | ------ type mismatch with `()` here | = note: expected unit type `()` found opaque type `impl FnOnce<()>` From ccf6d4fa90cd1eb9941e8242b85e2403ab24aa2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 29 May 2021 16:05:32 -0700 Subject: [PATCH 03/11] Tweak spans and labels --- .../src/infer/error_reporting/mod.rs | 14 +++- .../src/traits/error_reporting/mod.rs | 73 ++++++++++--------- .../rustc_typeck/src/check/compare_method.rs | 5 +- ...nding-to-type-defined-in-supertrait.stderr | 8 +- .../associated-types/associated-types-eq-3.rs | 2 - .../associated-types-eq-3.stderr | 10 +-- .../associated-types-eq-hr.stderr | 8 +- .../associated-types-issue-20346.stderr | 4 +- ...sociated-types-overridden-binding-2.stderr | 5 -- .../ui/associated-types/issue-44153.stderr | 4 +- .../ui/associated-types/issue-72806.stderr | 4 +- ...point-at-type-on-obligation-failure.stderr | 4 +- ...block-control-flow-static-semantics.stderr | 10 --- src/test/ui/error-codes/E0271.stderr | 4 +- ...erator-yielding-or-returning-itself.stderr | 10 --- .../type-mismatch-signature-deduction.stderr | 5 -- .../issue-68656-unsized-values.stderr | 5 -- .../issue-74684-2.stderr | 4 +- src/test/ui/hrtb/issue-62203-hrtb-ice.stderr | 9 +-- .../bound-normalization-fail.stderr | 8 +- .../issues/issue-70877.full_tait.stderr | 5 -- .../issues/issue-70877.min_tait.stderr | 5 -- ...ction-mismatch-in-impl-where-clause.stderr | 4 +- src/test/ui/issues/issue-31173.stderr | 5 -- src/test/ui/issues/issue-33941.stderr | 15 ---- src/test/ui/issues/issue-39970.stderr | 4 +- .../issue-67039-unsound-pin-partialeq.stderr | 5 -- .../ui/traits/assoc-type-in-superbad.stderr | 5 -- .../check-trait-object-bounds-5.stderr | 4 +- .../check-trait-object-bounds-6.stderr | 4 +- .../ui/try-block/try-block-bad-type.stderr | 10 --- .../ui/try-block/try-block-type-error.stderr | 10 --- .../issue-63279.full_tait.stderr | 5 -- .../issue-63279.min_tait.stderr | 5 -- 34 files changed, 93 insertions(+), 189 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index fb762d2deba7c..f25cc0bd9be06 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1428,6 +1428,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { secondary_span: Option<(Span, String)>, mut values: Option>, terr: &TypeError<'tcx>, + swap_secondary_and_primary: bool, ) { let span = cause.span(self.tcx); debug!("note_type_err cause={:?} values={:?}, terr={:?}", cause, values, terr); @@ -1582,9 +1583,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { match terr { TypeError::ObjectUnsafeCoercion(_) => {} _ => { - diag.span_label(span, terr.to_string()); if let Some((sp, msg)) = secondary_span { - diag.span_label(sp, msg); + if swap_secondary_and_primary { + diag.span_label(sp, terr.to_string()); + diag.span_label(span, msg); + } else { + diag.span_label(span, terr.to_string()); + diag.span_label(sp, msg); + } + } else { + diag.span_label(span, terr.to_string()); } } }; @@ -1971,7 +1979,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { struct_span_err!(self.tcx.sess, span, E0644, "{}", failure_str) } }; - self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr); + self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr, false); diag } 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 ad3f3d15534c8..a8d560d15ee9a 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1260,40 +1260,47 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { "type mismatch resolving `{}`", predicate ); - self.note_type_err(&mut diag, &obligation.cause, None, values, err); + let secondary_span = match predicate.kind().skip_binder() { + ty::PredicateKind::Projection(proj) => self + .tcx + .opt_associated_item(proj.projection_ty.item_def_id) + .and_then(|trait_assoc_item| { + self.tcx + .trait_of_item(proj.projection_ty.item_def_id) + .map(|id| (trait_assoc_item, id)) + }) + .and_then(|(trait_assoc_item, id)| { + self.tcx.find_map_relevant_impl( + id, + proj.projection_ty.self_ty(), + |did| { + self.tcx + .associated_items(did) + .in_definition_order() + .filter(|assoc| assoc.ident == trait_assoc_item.ident) + .next() + }, + ) + }) + .and_then(|item| match self.tcx.hir().get_if_local(item.def_id) { + Some( + hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Type(_, Some(ty)), + .. + }) + | hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::TyAlias(ty), + .. + }), + ) => { + Some((ty.span, format!("type mismatch resolving `{}`", predicate))) + } + _ => None, + }), + _ => None, + }; + self.note_type_err(&mut diag, &obligation.cause, secondary_span, values, err, true); self.note_obligation_cause(&mut diag, obligation); - match predicate.kind().skip_binder() { - ty::PredicateKind::Projection(proj) => { - let item = self - .tcx - .opt_associated_item(proj.projection_ty.item_def_id) - .and_then(|trait_assoc_item| { - self.tcx - .trait_of_item(proj.projection_ty.item_def_id) - .map(|id| (trait_assoc_item, id)) - }) - .and_then(|(trait_assoc_item, id)| { - self.tcx.find_map_relevant_impl( - id, - proj.projection_ty.self_ty(), - |did| { - self.tcx - .associated_items(did) - .in_definition_order() - .filter(|assoc| assoc.ident == trait_assoc_item.ident) - .next() - }, - ) - }); - if let Some(item) = item { - diag.span_label( - item.ident.span, - &format!("type mismatch with `{}` here", proj.ty), - ); - } - } - _ => {} - } diag.emit(); } }); diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 60ca562f99200..242890ec4fc72 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -374,6 +374,7 @@ fn compare_predicate_entailment<'tcx>( found: impl_fty, })), &terr, + false, ); diag.emit(); return Err(ErrorReported); @@ -748,8 +749,7 @@ fn compare_number_of_method_arguments<'tcx>( tcx.sess, impl_span, E0050, - "method `{}` has {} but the declaration in \ - trait `{}` has {}", + "method `{}` has {} but the declaration in trait `{}` has {}", trait_m.ident, potentially_plural_count(impl_number_args, "parameter"), tcx.def_path_str(trait_m.def_id), @@ -1023,6 +1023,7 @@ crate fn compare_const_impl<'tcx>( found: impl_ty, })), &terr, + false, ); diag.emit(); } diff --git a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr index a6063aaa7b40c..a84724f7895b5 100644 --- a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr +++ b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr @@ -2,25 +2,25 @@ error[E0271]: type mismatch resolving `::Color == Blue` --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:31:10 | LL | impl Vehicle for ModelT { type Color = Black; } - | ----- type mismatch with `Blue` here + | ----- expected struct `Blue`, found struct `Black` ... LL | fn blue_car>(c: C) { | ---------- required by this bound in `blue_car` ... LL | fn b() { blue_car(ModelT); } - | ^^^^^^^^ expected struct `Blue`, found struct `Black` + | ^^^^^^^^ type mismatch resolving `::Color == Blue` error[E0271]: type mismatch resolving `::Color == Black` --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:10 | LL | impl Vehicle for ModelU { type Color = Blue; } - | ----- type mismatch with `Black` here + | ---- expected struct `Black`, found struct `Blue` ... LL | fn black_car>(c: C) { | ----------- required by this bound in `black_car` ... LL | fn c() { black_car(ModelU); } - | ^^^^^^^^^ expected struct `Black`, found struct `Blue` + | ^^^^^^^^^ type mismatch resolving `::Color == Black` error: aborting due to 2 previous errors diff --git a/src/test/ui/associated-types/associated-types-eq-3.rs b/src/test/ui/associated-types/associated-types-eq-3.rs index 3bb03c39e0f60..f6988dcf65ebf 100644 --- a/src/test/ui/associated-types/associated-types-eq-3.rs +++ b/src/test/ui/associated-types/associated-types-eq-3.rs @@ -37,8 +37,6 @@ pub fn main() { let a = 42; foo1(a); //~^ ERROR type mismatch resolving - //~| expected struct `Bar`, found `usize` baz(&a); //~^ ERROR type mismatch resolving - //~| expected struct `Bar`, found `usize` } 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 4d4b6ab277c35..f9e5dae47c5b9 100644 --- a/src/test/ui/associated-types/associated-types-eq-3.stderr +++ b/src/test/ui/associated-types/associated-types-eq-3.stderr @@ -17,22 +17,22 @@ error[E0271]: type mismatch resolving `::A == Bar` --> $DIR/associated-types-eq-3.rs:38:5 | LL | type A = usize; - | - type mismatch with `Bar` here + | ----- expected struct `Bar`, found `usize` ... LL | fn foo1>(x: I) { | ----- required by this bound in `foo1` ... LL | foo1(a); - | ^^^^ expected struct `Bar`, found `usize` + | ^^^^ type mismatch resolving `::A == Bar` error[E0271]: type mismatch resolving `::A == Bar` - --> $DIR/associated-types-eq-3.rs:41:9 + --> $DIR/associated-types-eq-3.rs:40:9 | LL | type A = usize; - | - type mismatch with `Bar` here + | ----- expected struct `Bar`, found `usize` ... LL | baz(&a); - | ^^ expected struct `Bar`, found `usize` + | ^^ type mismatch resolving `::A == Bar` | = note: required for the cast to the object type `dyn Foo` diff --git a/src/test/ui/associated-types/associated-types-eq-hr.stderr b/src/test/ui/associated-types/associated-types-eq-hr.stderr index 4951b308ba97b..1913d0ff57730 100644 --- a/src/test/ui/associated-types/associated-types-eq-hr.stderr +++ b/src/test/ui/associated-types/associated-types-eq-hr.stderr @@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `for<'x> $DIR/associated-types-eq-hr.rs:87:5 | LL | type A = &'a usize; - | - type mismatch with `&'x isize` here + | --------- expected `isize`, found `usize` ... LL | fn foo() | --- required by a bound in this @@ -11,7 +11,7 @@ LL | T: for<'x> TheTrait<&'x isize, A = &'x isize>, | ------------- required by this bound in `foo` ... LL | foo::(); - | ^^^^^^^^^^^^^^^^^ expected `isize`, found `usize` + | ^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> >::A == &'x isize` | = note: expected reference `&isize` found reference `&usize` @@ -20,7 +20,7 @@ error[E0271]: type mismatch resolving `for<'x> --> $DIR/associated-types-eq-hr.rs:91:5 | LL | type A = &'a isize; - | - type mismatch with `&'x usize` here + | --------- expected `usize`, found `isize` ... LL | fn bar() | --- required by a bound in this @@ -29,7 +29,7 @@ LL | T: for<'x> TheTrait<&'x isize, A = &'x usize>, | ------------- required by this bound in `bar` ... LL | bar::(); - | ^^^^^^^^^^^^^^^^ expected `usize`, found `isize` + | ^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> >::A == &'x usize` | = note: expected reference `&usize` found reference `&isize` diff --git a/src/test/ui/associated-types/associated-types-issue-20346.stderr b/src/test/ui/associated-types/associated-types-issue-20346.stderr index e738506c55799..2b8f711084c7f 100644 --- a/src/test/ui/associated-types/associated-types-issue-20346.stderr +++ b/src/test/ui/associated-types/associated-types-issue-20346.stderr @@ -5,13 +5,13 @@ LL | fn is_iterator_of>(_: &I) {} | ------ required by this bound in `is_iterator_of` ... LL | type Item = T; - | ---- type mismatch with `Option` here + | - expected enum `Option`, found type parameter `T` ... LL | fn test_adapter>>(it: I) { | - this type parameter ... LL | is_iterator_of::, _>(&adapter); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found type parameter `T` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving ` as Iterator>::Item == Option` | = note: expected enum `Option` found type `T` 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 795799bbc89b0..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 @@ -3,11 +3,6 @@ error[E0271]: type mismatch resolving ` as Iterator>::It | LL | let _: &dyn I32Iterator = &vec![42].into_iter(); | ^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32` - | - ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL - | -LL | type Item = I::Item; - | ---- type mismatch with `i32` here | = note: required for the cast to the object type `dyn Iterator` diff --git a/src/test/ui/associated-types/issue-44153.stderr b/src/test/ui/associated-types/issue-44153.stderr index e1865dfb162bd..346a6b8edb860 100644 --- a/src/test/ui/associated-types/issue-44153.stderr +++ b/src/test/ui/associated-types/issue-44153.stderr @@ -5,10 +5,10 @@ LL | fn visit() {} | ---------- required by `Visit::visit` ... LL | type Element = (); - | ------- type mismatch with `&()` here + | -- expected `&()`, found `()` ... LL | <() as Visit>::visit(); - | ^^^^^^^^^^^^^^^^^^^^ expected `&()`, found `()` + | ^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<() as Array>::Element == &()` | note: required because of the requirements on the impl of `Visit` for `()` --> $DIR/issue-44153.rs:13:10 diff --git a/src/test/ui/associated-types/issue-72806.stderr b/src/test/ui/associated-types/issue-72806.stderr index 931f242cb6321..60eee22c04350 100644 --- a/src/test/ui/associated-types/issue-72806.stderr +++ b/src/test/ui/associated-types/issue-72806.stderr @@ -5,10 +5,10 @@ LL | type Sibling: Bar2; | ------- required by this bound in `Bar::Sibling` ... LL | type Sibling = Foo2; - | ^^^^ expected `char`, found `u32` + | ^^^^ type mismatch resolving `::Ok == char` ... LL | type Ok = u32; - | -- type mismatch with `char` here + | --- expected `char`, found `u32` error: aborting due to previous error diff --git a/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr b/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr index 0d6a00d69996e..e533aaaa3561b 100644 --- a/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr +++ b/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr @@ -5,10 +5,10 @@ LL | type Sibling: Bar2; | ----------- required by this bound in `Bar::Sibling` ... LL | type Sibling = Foo2; - | ^^^^ expected `()`, found `u32` + | ^^^^ type mismatch resolving `::Ok == ()` ... LL | type Ok = u32; - | -- type mismatch with `()` here + | --- expected `()`, found `u32` error: aborting due to previous error 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 4a1a3232ccd2e..919904ce3b6a2 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 @@ -36,11 +36,6 @@ error[E0271]: type mismatch resolving `::Output == ()` | LL | let _: &dyn Future = █ | ^^^^^^ expected `()`, found `u8` - | - ::: $SRC_DIR/core/src/future/future.rs:LL:COL - | -LL | type Output = F::Output; - | ------ type mismatch with `()` here | = note: required for the cast to the object type `dyn Future` @@ -57,11 +52,6 @@ error[E0271]: type mismatch resolving `::Output == ()` | LL | let _: &dyn Future = █ | ^^^^^^ expected `()`, found `u8` - | - ::: $SRC_DIR/core/src/future/future.rs:LL:COL - | -LL | type Output = F::Output; - | ------ type mismatch with `()` here | = note: required for the cast to the object type `dyn Future` diff --git a/src/test/ui/error-codes/E0271.stderr b/src/test/ui/error-codes/E0271.stderr index bc99769b86329..555fb93cf88d8 100644 --- a/src/test/ui/error-codes/E0271.stderr +++ b/src/test/ui/error-codes/E0271.stderr @@ -5,10 +5,10 @@ LL | fn foo(t: T) where T: Trait { | ------------------ required by this bound in `foo` ... LL | impl Trait for i8 { type AssociatedType = &'static str; } - | -------------- type mismatch with `u32` here + | ------------ expected `u32`, found `&str` ... LL | foo(3_i8); - | ^^^ expected `u32`, found `&str` + | ^^^ type mismatch resolving `::AssociatedType == u32` error: aborting due to previous error diff --git a/src/test/ui/generator/generator-yielding-or-returning-itself.stderr b/src/test/ui/generator/generator-yielding-or-returning-itself.stderr index 10e84f000a45b..5043a3be91d52 100644 --- a/src/test/ui/generator/generator-yielding-or-returning-itself.stderr +++ b/src/test/ui/generator/generator-yielding-or-returning-itself.stderr @@ -8,11 +8,6 @@ LL | where T: Generator ... LL | want_cyclic_generator_return(|| { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size - | - ::: $SRC_DIR/core/src/ops/generator.rs:LL:COL - | -LL | type Return = G::Return; - | ------ type mismatch with `[generator@$DIR/generator-yielding-or-returning-itself.rs:15:34: 19:6]` here | = note: closures cannot capture themselves or take themselves as argument; this error may be the result of a recent compiler bug-fix, @@ -29,11 +24,6 @@ LL | where T: Generator ... LL | want_cyclic_generator_yield(|| { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size - | - ::: $SRC_DIR/core/src/ops/generator.rs:LL:COL - | -LL | type Yield = G::Yield; - | ----- type mismatch with `[generator@$DIR/generator-yielding-or-returning-itself.rs:28:33: 32:6]` here | = note: closures cannot capture themselves or take themselves as argument; this error may be the result of a recent compiler bug-fix, diff --git a/src/test/ui/generator/type-mismatch-signature-deduction.stderr b/src/test/ui/generator/type-mismatch-signature-deduction.stderr index 3620b841c4697..3f1f33a3b123f 100644 --- a/src/test/ui/generator/type-mismatch-signature-deduction.stderr +++ b/src/test/ui/generator/type-mismatch-signature-deduction.stderr @@ -17,11 +17,6 @@ error[E0271]: type mismatch resolving `<[generator@$DIR/type-mismatch-signature- | LL | fn foo() -> impl Generator { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found enum `Result` - | - ::: $SRC_DIR/core/src/ops/generator.rs:LL:COL - | -LL | type Return = G::Return; - | ------ type mismatch with `i32` here | = note: expected type `i32` found enum `Result<{integer}, _>` diff --git a/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr b/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr index b71350324c236..b30f1573983d5 100644 --- a/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr +++ b/src/test/ui/generic-associated-types/issue-68656-unsized-values.stderr @@ -17,11 +17,6 @@ LL | impl UnsafeCopy for T { | - this type parameter LL | type Item<'a> = T; | ^ expected type parameter `T`, found associated type - | - ::: $SRC_DIR/core/src/ops/deref.rs:LL:COL - | -LL | type Target = T; - | ------ type mismatch with `T` here | = note: expected type parameter `T` found associated type `::Target` diff --git a/src/test/ui/generic-associated-types/issue-74684-2.stderr b/src/test/ui/generic-associated-types/issue-74684-2.stderr index c0c5bfc72283d..43e5c821abb98 100644 --- a/src/test/ui/generic-associated-types/issue-74684-2.stderr +++ b/src/test/ui/generic-associated-types/issue-74684-2.stderr @@ -11,13 +11,13 @@ error[E0271]: type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]` --> $DIR/issue-74684-2.rs:24:5 | LL | type F<'a> = i32; - | - type mismatch with `[u8]` here + | --- expected slice `[u8]`, found `i32` ... LL | fn bug<'a, T: ?Sized + Fun = [u8]>>(t: Box) -> &'static T::F<'a> { | ------------ required by this bound in `bug` ... LL | bug(Box::new(x)); - | ^^^ expected slice `[u8]`, found `i32` + | ^^^ type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr index e736fe396a5d9..69a90dc6fbecd 100644 --- a/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr +++ b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr @@ -2,10 +2,10 @@ error[E0271]: type mismatch resolving `for<'r> $DIR/issue-62203-hrtb-ice.rs:38:19 | LL | type O = T::Output; - | - type mismatch with `<_ as Ty<'r>>::V` here + | --------- expected struct `Unit4`, found associated type ... LL | let v = Unit2.m( - | ^ expected struct `Unit4`, found associated type + | ^ type mismatch resolving `for<'r> as T0<'r, (>::V,)>>::O == <_ as Ty<'r>>::V` | = note: expected struct `Unit4` found associated type `<_ as Ty<'_>>::V` @@ -17,11 +17,6 @@ error[E0271]: type mismatch resolving `<[closure@$DIR/issue-62203-hrtb-ice.rs:42 | LL | let v = Unit2.m( | ^ expected struct `Unit4`, found struct `Unit3` - | - ::: $SRC_DIR/core/src/ops/function.rs:LL:COL - | -LL | type Output = F::Output; - | ------ type mismatch with `Unit3` here | note: required because of the requirements on the impl of `for<'r> T0<'r, (>::V,)>` for `L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39]>` --> $DIR/issue-62203-hrtb-ice.rs:17:16 diff --git a/src/test/ui/impl-trait/bound-normalization-fail.stderr b/src/test/ui/impl-trait/bound-normalization-fail.stderr index 49db449b4e542..2032db2f0b96b 100644 --- a/src/test/ui/impl-trait/bound-normalization-fail.stderr +++ b/src/test/ui/impl-trait/bound-normalization-fail.stderr @@ -11,10 +11,10 @@ error[E0271]: type mismatch resolving ` as FooLike>::Output == $DIR/bound-normalization-fail.rs:26:32 | LL | type Output = T; - | ------ type mismatch with `::Assoc` here + | - expected associated type, found `()` ... LL | fn foo_fail() -> impl FooLike { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `()` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving ` as FooLike>::Output == ::Assoc` | = note: expected associated type `::Assoc` found type `()` @@ -33,10 +33,10 @@ error[E0271]: type mismatch resolving ` as FooLike>::Output == $DIR/bound-normalization-fail.rs:42:41 | LL | type Output = T; - | ------ type mismatch with `>::Assoc` here + | - expected associated type, found `()` ... LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `()` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving ` as FooLike>::Output == >::Assoc` | = note: expected associated type `>::Assoc` found type `()` diff --git a/src/test/ui/impl-trait/issues/issue-70877.full_tait.stderr b/src/test/ui/impl-trait/issues/issue-70877.full_tait.stderr index 374ffcf796645..8e42b9d46db39 100644 --- a/src/test/ui/impl-trait/issues/issue-70877.full_tait.stderr +++ b/src/test/ui/impl-trait/issues/issue-70877.full_tait.stderr @@ -6,11 +6,6 @@ LL | type FooRet = impl std::fmt::Debug; ... LL | type Foo = impl Iterator; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found opaque type - | - ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL - | -LL | type Item = I::Item; - | ---- type mismatch with `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option + 'static)>` here | = note: expected struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option + 'static)>` found struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> impl Debug + 'static)>` diff --git a/src/test/ui/impl-trait/issues/issue-70877.min_tait.stderr b/src/test/ui/impl-trait/issues/issue-70877.min_tait.stderr index 374ffcf796645..8e42b9d46db39 100644 --- a/src/test/ui/impl-trait/issues/issue-70877.min_tait.stderr +++ b/src/test/ui/impl-trait/issues/issue-70877.min_tait.stderr @@ -6,11 +6,6 @@ LL | type FooRet = impl std::fmt::Debug; ... LL | type Foo = impl Iterator; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found opaque type - | - ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL - | -LL | type Item = I::Item; - | ---- type mismatch with `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option + 'static)>` here | = note: expected struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option + 'static)>` found struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> impl Debug + 'static)>` diff --git a/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr b/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr index af2674ecb9628..a335221b31c6d 100644 --- a/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr +++ b/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr @@ -2,10 +2,10 @@ error[E0271]: type mismatch resolving `<() as Super>::Assoc == ()` --> $DIR/projection-mismatch-in-impl-where-clause.rs:13:14 | LL | type Assoc = u8; - | ----- type mismatch with `()` here + | -- expected `()`, found `u8` ... LL | fn test() -> impl Test { - | ^^^^^^^^^ expected `()`, found `u8` + | ^^^^^^^^^ type mismatch resolving `<() as Super>::Assoc == ()` | note: required because of the requirements on the impl of `Test` for `()` --> $DIR/projection-mismatch-in-impl-where-clause.rs:11:9 diff --git a/src/test/ui/issues/issue-31173.stderr b/src/test/ui/issues/issue-31173.stderr index 0c4f88f37ed11..0b7ffc39646a6 100644 --- a/src/test/ui/issues/issue-31173.stderr +++ b/src/test/ui/issues/issue-31173.stderr @@ -3,11 +3,6 @@ error[E0271]: type mismatch resolving `, [ | LL | .cloned() | ^^^^^^ expected `u8`, found reference - | - ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL - | -LL | type Item = I::Item; - | ---- type mismatch with `&_` here | = note: expected type `u8` found reference `&_` diff --git a/src/test/ui/issues/issue-33941.stderr b/src/test/ui/issues/issue-33941.stderr index bcc9e893a825f..043658c9508f3 100644 --- a/src/test/ui/issues/issue-33941.stderr +++ b/src/test/ui/issues/issue-33941.stderr @@ -3,11 +3,6 @@ error[E0271]: type mismatch resolving `::visit(); - | ^^^^^^^^^^^^^^^^^^^^ expected `()`, found `&()` + | ^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'a> <() as Array<'a>>::Element == ()` | note: required because of the requirements on the impl of `Visit` for `()` --> $DIR/issue-39970.rs:13:6 diff --git a/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr b/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr index 9b80568cafa5d..036a9300a174d 100644 --- a/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr +++ b/src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr @@ -3,11 +3,6 @@ error[E0271]: type mismatch resolving ` as Deref>::Target == Rc | LL | let _ = Pin::new(Apple) == Rc::pin(Apple); | ^^ expected struct `Apple`, found struct `Rc` - | - ::: $SRC_DIR/core/src/ops/deref.rs:LL:COL - | -LL | type Target = T; - | ------ type mismatch with `Rc` here | = note: expected type `Apple` found struct `Rc` diff --git a/src/test/ui/traits/assoc-type-in-superbad.stderr b/src/test/ui/traits/assoc-type-in-superbad.stderr index 0764e691221d7..cbdb6b96f468f 100644 --- a/src/test/ui/traits/assoc-type-in-superbad.stderr +++ b/src/test/ui/traits/assoc-type-in-superbad.stderr @@ -3,11 +3,6 @@ error[E0271]: type mismatch resolving ` as Iterator>::It | LL | type Key = u32; | ^^^ expected `i32`, found `u32` - | - ::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL - | -LL | type Item = I::Item; - | ---- type mismatch with `u32` here error: aborting due to previous error diff --git a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr index 43c1775a8a8a3..d94f8600b65fa 100644 --- a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr +++ b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr @@ -2,13 +2,13 @@ error[E0271]: type mismatch resolving `::T == i64` --> $DIR/check-trait-object-bounds-5.rs:23:5 | LL | type T = U; - | - type mismatch with `i64` here + | - expected `i64`, found `i32` ... LL | fn is_obj(_: &T) {} | --- required by this bound in `is_obj` ... LL | is_obj(x) - | ^^^^^^ expected `i64`, found `i32` + | ^^^^^^ type mismatch resolving `::T == i64` error: aborting due to previous error diff --git a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr index ecfa512846cd2..56f459084d2d7 100644 --- a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr +++ b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr @@ -2,13 +2,13 @@ error[E0271]: type mismatch resolving `::T == i64` --> $DIR/check-trait-object-bounds-6.rs:20:5 | LL | type T = U; - | - type mismatch with `i64` here + | - expected `i64`, found `i32` ... LL | fn is_obj(_: &T) {} | --- required by this bound in `is_obj` ... LL | is_obj(x) - | ^^^^^^ expected `i64`, found `i32` + | ^^^^^^ type mismatch resolving `::T == i64` error: aborting due to previous error diff --git a/src/test/ui/try-block/try-block-bad-type.stderr b/src/test/ui/try-block/try-block-bad-type.stderr index 796252963dae7..ec5e91f10c286 100644 --- a/src/test/ui/try-block/try-block-bad-type.stderr +++ b/src/test/ui/try-block/try-block-bad-type.stderr @@ -15,22 +15,12 @@ error[E0271]: type mismatch resolving ` as Try>::Output == &str | LL | "" | ^^ expected `i32`, found `&str` - | - ::: $SRC_DIR/core/src/result.rs:LL:COL - | -LL | type Ok = T; - | -- type mismatch with `&str` here error[E0271]: type mismatch resolving ` as Try>::Output == ()` --> $DIR/try-block-bad-type.rs:15:39 | LL | let res: Result = try { }; | ^ expected `i32`, found `()` - | - ::: $SRC_DIR/core/src/result.rs:LL:COL - | -LL | type Ok = T; - | -- type mismatch with `()` here error[E0277]: a `try` block must return `Result` or `Option` (or another type that implements `Try`) --> $DIR/try-block-bad-type.rs:17:25 diff --git a/src/test/ui/try-block/try-block-type-error.stderr b/src/test/ui/try-block/try-block-type-error.stderr index cc38544330aba..3e9a584a5510a 100644 --- a/src/test/ui/try-block/try-block-type-error.stderr +++ b/src/test/ui/try-block/try-block-type-error.stderr @@ -6,22 +6,12 @@ LL | 42 | | | expected `f32`, found integer | help: use a float literal: `42.0` - | - ::: $SRC_DIR/core/src/option.rs:LL:COL - | -LL | type Ok = T; - | -- type mismatch with `{integer}` here error[E0271]: type mismatch resolving ` as Try>::Output == ()` --> $DIR/try-block-type-error.rs:16:5 | LL | }; | ^ expected `i32`, found `()` - | - ::: $SRC_DIR/core/src/option.rs:LL:COL - | -LL | type Ok = T; - | -- type mismatch with `()` here error: aborting due to 2 previous errors diff --git a/src/test/ui/type-alias-impl-trait/issue-63279.full_tait.stderr b/src/test/ui/type-alias-impl-trait/issue-63279.full_tait.stderr index de68e2433998c..53a0016c08eb5 100644 --- a/src/test/ui/type-alias-impl-trait/issue-63279.full_tait.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-63279.full_tait.stderr @@ -12,11 +12,6 @@ error[E0271]: type mismatch resolving `<[closure@$DIR/issue-63279.rs:11:5: 11:28 | LL | type Closure = impl FnOnce(); | ^^^^^^^^^^^^^ expected `()`, found opaque type - | - ::: $SRC_DIR/core/src/ops/function.rs:LL:COL - | -LL | type Output = F::Output; - | ------ type mismatch with `()` here | = note: expected unit type `()` found opaque type `impl FnOnce<()>` diff --git a/src/test/ui/type-alias-impl-trait/issue-63279.min_tait.stderr b/src/test/ui/type-alias-impl-trait/issue-63279.min_tait.stderr index ea113238ea58c..be386ab90ea00 100644 --- a/src/test/ui/type-alias-impl-trait/issue-63279.min_tait.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-63279.min_tait.stderr @@ -12,11 +12,6 @@ error[E0271]: type mismatch resolving `<[closure@$DIR/issue-63279.rs:11:5: 11:28 | LL | type Closure = impl FnOnce(); | ^^^^^^^^^^^^^ expected `()`, found opaque type - | - ::: $SRC_DIR/core/src/ops/function.rs:LL:COL - | -LL | type Output = F::Output; - | ------ type mismatch with `()` here | = note: expected unit type `()` found opaque type `impl FnOnce<()>` From 01cb828c88c06409c35c4989059b545712532fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 29 May 2021 19:22:15 -0700 Subject: [PATCH 04/11] Further tweak labels --- compiler/rustc_infer/src/infer/error_reporting/mod.rs | 11 ++++++++++- compiler/rustc_middle/src/ty/error.rs | 6 ++---- ...types-binding-to-type-defined-in-supertrait.stderr | 4 ++-- .../ui/associated-types/associated-types-eq-3.stderr | 4 ++-- .../ui/associated-types/associated-types-eq-hr.stderr | 4 ++-- .../associated-types-issue-20346.stderr | 2 +- src/test/ui/associated-types/issue-44153.stderr | 2 +- src/test/ui/associated-types/issue-72806.stderr | 2 +- .../point-at-type-on-obligation-failure.stderr | 2 +- src/test/ui/error-codes/E0271.stderr | 2 +- .../ui/generic-associated-types/issue-74684-2.stderr | 2 +- src/test/ui/hrtb/issue-62203-hrtb-ice.stderr | 2 +- .../ui/impl-trait/bound-normalization-fail.stderr | 4 ++-- .../projection-mismatch-in-impl-where-clause.stderr | 2 +- src/test/ui/issues/issue-39970.stderr | 2 +- .../check-trait-object-bounds-5.stderr | 2 +- .../check-trait-object-bounds-6.stderr | 2 +- 17 files changed, 31 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index f25cc0bd9be06..39d6f0270681c 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1585,7 +1585,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { _ => { if let Some((sp, msg)) = secondary_span { if swap_secondary_and_primary { - diag.span_label(sp, terr.to_string()); + let terr = if let Some(infer::ValuePairs::Types(infer::ExpectedFound { + expected, + .. + })) = values + { + format!("expected this to be `{}`", expected) + } else { + terr.to_string() + }; + diag.span_label(sp, terr); diag.span_label(span, msg); } else { diag.span_label(span, terr.to_string()); diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 96aae3bd70cd2..b82f760ff4b90 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -115,8 +115,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { ArgumentMutability(_) | Mutability => write!(f, "types differ in mutability"), TupleSize(values) => write!( f, - "expected a tuple with {} element{}, \ - found one with {} element{}", + "expected a tuple with {} element{}, found one with {} element{}", values.expected, pluralize!(values.expected), values.found, @@ -124,8 +123,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { ), FixedArraySize(values) => write!( f, - "expected an array with a fixed size of {} element{}, \ - found one with {} element{}", + "expected an array with a fixed size of {} element{}, found one with {} element{}", values.expected, pluralize!(values.expected), values.found, diff --git a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr index a84724f7895b5..df8e8b07ca53d 100644 --- a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr +++ b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr @@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `::Color == Blue` --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:31:10 | LL | impl Vehicle for ModelT { type Color = Black; } - | ----- expected struct `Blue`, found struct `Black` + | ----- expected this to be `Blue` ... LL | fn blue_car>(c: C) { | ---------- required by this bound in `blue_car` @@ -14,7 +14,7 @@ error[E0271]: type mismatch resolving `::Color == Black` --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:10 | LL | impl Vehicle for ModelU { type Color = Blue; } - | ---- expected struct `Black`, found struct `Blue` + | ---- expected this to be `Black` ... LL | fn black_car>(c: C) { | ----------- required by this bound in `black_car` 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 f9e5dae47c5b9..109ac613773c2 100644 --- a/src/test/ui/associated-types/associated-types-eq-3.stderr +++ b/src/test/ui/associated-types/associated-types-eq-3.stderr @@ -17,7 +17,7 @@ error[E0271]: type mismatch resolving `::A == Bar` --> $DIR/associated-types-eq-3.rs:38:5 | LL | type A = usize; - | ----- expected struct `Bar`, found `usize` + | ----- expected this to be `Bar` ... LL | fn foo1>(x: I) { | ----- required by this bound in `foo1` @@ -29,7 +29,7 @@ error[E0271]: type mismatch resolving `::A == Bar` --> $DIR/associated-types-eq-3.rs:40:9 | LL | type A = usize; - | ----- expected struct `Bar`, found `usize` + | ----- expected this to be `Bar` ... LL | baz(&a); | ^^ type mismatch resolving `::A == Bar` diff --git a/src/test/ui/associated-types/associated-types-eq-hr.stderr b/src/test/ui/associated-types/associated-types-eq-hr.stderr index 1913d0ff57730..6e6e77e03bc73 100644 --- a/src/test/ui/associated-types/associated-types-eq-hr.stderr +++ b/src/test/ui/associated-types/associated-types-eq-hr.stderr @@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `for<'x> $DIR/associated-types-eq-hr.rs:87:5 | LL | type A = &'a usize; - | --------- expected `isize`, found `usize` + | --------- expected this to be `&isize` ... LL | fn foo() | --- required by a bound in this @@ -20,7 +20,7 @@ error[E0271]: type mismatch resolving `for<'x> --> $DIR/associated-types-eq-hr.rs:91:5 | LL | type A = &'a isize; - | --------- expected `usize`, found `isize` + | --------- expected this to be `&usize` ... LL | fn bar() | --- required by a bound in this diff --git a/src/test/ui/associated-types/associated-types-issue-20346.stderr b/src/test/ui/associated-types/associated-types-issue-20346.stderr index 2b8f711084c7f..09b0ffb416048 100644 --- a/src/test/ui/associated-types/associated-types-issue-20346.stderr +++ b/src/test/ui/associated-types/associated-types-issue-20346.stderr @@ -5,7 +5,7 @@ LL | fn is_iterator_of>(_: &I) {} | ------ required by this bound in `is_iterator_of` ... LL | type Item = T; - | - expected enum `Option`, found type parameter `T` + | - expected this to be `Option` ... LL | fn test_adapter>>(it: I) { | - this type parameter diff --git a/src/test/ui/associated-types/issue-44153.stderr b/src/test/ui/associated-types/issue-44153.stderr index 346a6b8edb860..4d185b7a7f602 100644 --- a/src/test/ui/associated-types/issue-44153.stderr +++ b/src/test/ui/associated-types/issue-44153.stderr @@ -5,7 +5,7 @@ LL | fn visit() {} | ---------- required by `Visit::visit` ... LL | type Element = (); - | -- expected `&()`, found `()` + | -- expected this to be `&()` ... LL | <() as Visit>::visit(); | ^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<() as Array>::Element == &()` diff --git a/src/test/ui/associated-types/issue-72806.stderr b/src/test/ui/associated-types/issue-72806.stderr index 60eee22c04350..7f6623014abd5 100644 --- a/src/test/ui/associated-types/issue-72806.stderr +++ b/src/test/ui/associated-types/issue-72806.stderr @@ -8,7 +8,7 @@ LL | type Sibling = Foo2; | ^^^^ type mismatch resolving `::Ok == char` ... LL | type Ok = u32; - | --- expected `char`, found `u32` + | --- expected this to be `char` error: aborting due to previous error diff --git a/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr b/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr index e533aaaa3561b..aa632514e104e 100644 --- a/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr +++ b/src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr @@ -8,7 +8,7 @@ LL | type Sibling = Foo2; | ^^^^ type mismatch resolving `::Ok == ()` ... LL | type Ok = u32; - | --- expected `()`, found `u32` + | --- expected this to be `()` error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0271.stderr b/src/test/ui/error-codes/E0271.stderr index 555fb93cf88d8..f05c7b4490504 100644 --- a/src/test/ui/error-codes/E0271.stderr +++ b/src/test/ui/error-codes/E0271.stderr @@ -5,7 +5,7 @@ LL | fn foo(t: T) where T: Trait { | ------------------ required by this bound in `foo` ... LL | impl Trait for i8 { type AssociatedType = &'static str; } - | ------------ expected `u32`, found `&str` + | ------------ expected this to be `u32` ... LL | foo(3_i8); | ^^^ type mismatch resolving `::AssociatedType == u32` diff --git a/src/test/ui/generic-associated-types/issue-74684-2.stderr b/src/test/ui/generic-associated-types/issue-74684-2.stderr index 43e5c821abb98..83fac225808aa 100644 --- a/src/test/ui/generic-associated-types/issue-74684-2.stderr +++ b/src/test/ui/generic-associated-types/issue-74684-2.stderr @@ -11,7 +11,7 @@ error[E0271]: type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]` --> $DIR/issue-74684-2.rs:24:5 | LL | type F<'a> = i32; - | --- expected slice `[u8]`, found `i32` + | --- expected this to be `[u8]` ... LL | fn bug<'a, T: ?Sized + Fun = [u8]>>(t: Box) -> &'static T::F<'a> { | ------------ required by this bound in `bug` diff --git a/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr index 69a90dc6fbecd..eefe172809469 100644 --- a/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr +++ b/src/test/ui/hrtb/issue-62203-hrtb-ice.stderr @@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `for<'r> $DIR/issue-62203-hrtb-ice.rs:38:19 | LL | type O = T::Output; - | --------- expected struct `Unit4`, found associated type + | --------- expected this to be `Unit4` ... LL | let v = Unit2.m( | ^ type mismatch resolving `for<'r> as T0<'r, (>::V,)>>::O == <_ as Ty<'r>>::V` diff --git a/src/test/ui/impl-trait/bound-normalization-fail.stderr b/src/test/ui/impl-trait/bound-normalization-fail.stderr index 2032db2f0b96b..be7467c33fc6a 100644 --- a/src/test/ui/impl-trait/bound-normalization-fail.stderr +++ b/src/test/ui/impl-trait/bound-normalization-fail.stderr @@ -11,7 +11,7 @@ error[E0271]: type mismatch resolving ` as FooLike>::Output == $DIR/bound-normalization-fail.rs:26:32 | LL | type Output = T; - | - expected associated type, found `()` + | - expected this to be `::Assoc` ... LL | fn foo_fail() -> impl FooLike { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving ` as FooLike>::Output == ::Assoc` @@ -33,7 +33,7 @@ error[E0271]: type mismatch resolving ` as FooLike>::Output == $DIR/bound-normalization-fail.rs:42:41 | LL | type Output = T; - | - expected associated type, found `()` + | - expected this to be `>::Assoc` ... LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving ` as FooLike>::Output == >::Assoc` diff --git a/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr b/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr index a335221b31c6d..b598230c4f02e 100644 --- a/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr +++ b/src/test/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr @@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<() as Super>::Assoc == ()` --> $DIR/projection-mismatch-in-impl-where-clause.rs:13:14 | LL | type Assoc = u8; - | -- expected `()`, found `u8` + | -- expected this to be `()` ... LL | fn test() -> impl Test { | ^^^^^^^^^ type mismatch resolving `<() as Super>::Assoc == ()` diff --git a/src/test/ui/issues/issue-39970.stderr b/src/test/ui/issues/issue-39970.stderr index bd76452c4d9f3..d5f1bd3876e9d 100644 --- a/src/test/ui/issues/issue-39970.stderr +++ b/src/test/ui/issues/issue-39970.stderr @@ -5,7 +5,7 @@ LL | fn visit() {} | ---------- required by `Visit::visit` ... LL | type Element = &'a (); - | ------ expected `()`, found `&()` + | ------ expected this to be `()` ... LL | <() as Visit>::visit(); | ^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'a> <() as Array<'a>>::Element == ()` diff --git a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr index d94f8600b65fa..3aa0171c3e69b 100644 --- a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr +++ b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-5.stderr @@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `::T == i64` --> $DIR/check-trait-object-bounds-5.rs:23:5 | LL | type T = U; - | - expected `i64`, found `i32` + | - expected this to be `i64` ... LL | fn is_obj(_: &T) {} | --- required by this bound in `is_obj` diff --git a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr index 56f459084d2d7..09651d91bef49 100644 --- a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr +++ b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-6.stderr @@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `::T == i64` --> $DIR/check-trait-object-bounds-6.rs:20:5 | LL | type T = U; - | - expected `i64`, found `i32` + | - expected this to be `i64` ... LL | fn is_obj(_: &T) {} | --- required by this bound in `is_obj` From 1c02dbb5b0bdbdc9ea812b7b4fe792536ef2a5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 29 May 2021 20:21:56 -0700 Subject: [PATCH 05/11] Revert span for "impl assoc type has extra requirements" --- compiler/rustc_typeck/src/check/compare_method.rs | 3 ++- .../generic-associated-types-where.stderr | 4 ++-- .../ui/generic-associated-types/impl_bounds.stderr | 12 ++++++------ .../issue-47206-where-clause.stderr | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 242890ec4fc72..0d5b3ad8dbb3f 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -1053,7 +1053,8 @@ crate fn compare_ty_impl<'tcx>( let _: Result<(), ErrorReported> = (|| { compare_number_of_generics(tcx, impl_ty, impl_ty_span, trait_ty, trait_item_span)?; - compare_type_predicate_entailment(tcx, impl_ty, impl_ty_span, trait_ty, impl_trait_ref)?; + let sp = tcx.def_span(impl_ty.def_id); + compare_type_predicate_entailment(tcx, impl_ty, sp, trait_ty, impl_trait_ref)?; check_type_bounds(tcx, trait_ty, impl_ty, impl_ty_span, impl_trait_ref) })(); diff --git a/src/test/ui/generic-associated-types/generic-associated-types-where.stderr b/src/test/ui/generic-associated-types/generic-associated-types-where.stderr index 047b756635aa5..9026d95b9e9cf 100644 --- a/src/test/ui/generic-associated-types/generic-associated-types-where.stderr +++ b/src/test/ui/generic-associated-types/generic-associated-types-where.stderr @@ -11,13 +11,13 @@ LL | type Assoc2 = Vec; | ^^^^^^^^^^^^^^^^^^^ error[E0276]: impl has stricter requirements than trait - --> $DIR/generic-associated-types-where.rs:23:40 + --> $DIR/generic-associated-types-where.rs:23:5 | LL | type Assoc3; | --------------- definition of `Assoc3` from trait ... LL | type Assoc3 where T: Iterator = Vec; - | ^^^^^^ impl has extra requirement `T: Iterator` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: Iterator` error: aborting due to 2 previous errors diff --git a/src/test/ui/generic-associated-types/impl_bounds.stderr b/src/test/ui/generic-associated-types/impl_bounds.stderr index 9c2b9d1440e5e..81122341dacba 100644 --- a/src/test/ui/generic-associated-types/impl_bounds.stderr +++ b/src/test/ui/generic-associated-types/impl_bounds.stderr @@ -1,17 +1,17 @@ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/impl_bounds.rs:16:39 + --> $DIR/impl_bounds.rs:16:5 | LL | type A<'a> where Self: 'static = (&'a ()); - | ^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider adding an explicit lifetime bound `T: 'static`... = note: ...so that the type `Fooy` will meet its required lifetime bounds error[E0478]: lifetime bound not satisfied - --> $DIR/impl_bounds.rs:18:35 + --> $DIR/impl_bounds.rs:18:5 | LL | type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: lifetime parameter instantiated with the lifetime `'b` as defined on the associated item at 18:16 --> $DIR/impl_bounds.rs:18:16 @@ -42,10 +42,10 @@ LL | type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); | ^^ error[E0277]: the trait bound `T: Copy` is not satisfied - --> $DIR/impl_bounds.rs:21:31 + --> $DIR/impl_bounds.rs:21:5 | LL | type C where Self: Copy = String; - | ^^^^^^ the trait `Copy` is not implemented for `T` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T` | = note: required because of the requirements on the impl of `Copy` for `Fooy` note: the requirement `Fooy: Copy` appears on the associated impl type `C` but not on the corresponding associated trait type diff --git a/src/test/ui/generic-associated-types/issue-47206-where-clause.stderr b/src/test/ui/generic-associated-types/issue-47206-where-clause.stderr index 6d9f081f5ca29..439b8ab90c9d8 100644 --- a/src/test/ui/generic-associated-types/issue-47206-where-clause.stderr +++ b/src/test/ui/generic-associated-types/issue-47206-where-clause.stderr @@ -1,11 +1,11 @@ error[E0276]: impl has stricter requirements than trait - --> $DIR/issue-47206-where-clause.rs:13:40 + --> $DIR/issue-47206-where-clause.rs:13:5 | LL | type Assoc3; | --------------- definition of `Assoc3` from trait ... LL | type Assoc3 where T: Iterator = Vec; - | ^^^^^^ impl has extra requirement `T: Iterator` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: Iterator` error: aborting due to previous error From 0f533e5b88b286a47e78af830ba630d5add4ef2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 2 Jun 2021 16:16:06 -0700 Subject: [PATCH 06/11] Mention where implicit `Sized` obligations come from on E0277 WIP: ordering of `Sized` obligations can affect the presence of the note. Some tweaks needed to make this the best it can be. --- compiler/rustc_infer/src/traits/util.rs | 2 +- compiler/rustc_lint/src/traits.rs | 2 +- compiler/rustc_lint/src/unused.rs | 2 +- compiler/rustc_middle/src/ty/assoc.rs | 39 +++++++++- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/flags.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 77 +++++++++++++++++-- compiler/rustc_middle/src/ty/print/pretty.rs | 7 +- .../rustc_middle/src/ty/structural_impls.rs | 6 +- .../src/borrow_check/type_check/mod.rs | 1 + .../src/transform/check_consts/validation.rs | 2 +- .../src/transform/function_item_references.rs | 2 +- compiler/rustc_privacy/src/lib.rs | 2 +- compiler/rustc_resolve/src/late/lifetimes.rs | 2 +- .../src/traits/auto_trait.rs | 6 +- .../src/traits/error_reporting/mod.rs | 67 ++++++++++++++-- .../src/traits/error_reporting/suggestions.rs | 2 +- .../src/traits/fulfill.rs | 4 +- .../src/traits/object_safety.rs | 4 +- .../traits/query/type_op/prove_predicate.rs | 3 +- .../src/traits/select/mod.rs | 6 +- .../rustc_trait_selection/src/traits/wf.rs | 4 +- compiler/rustc_traits/src/chalk/lowering.rs | 8 +- compiler/rustc_typeck/src/astconv/mod.rs | 2 +- compiler/rustc_typeck/src/bounds.rs | 4 +- compiler/rustc_typeck/src/check/_match.rs | 3 +- compiler/rustc_typeck/src/check/coercion.rs | 2 +- compiler/rustc_typeck/src/check/dropck.rs | 2 +- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 2 +- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 4 +- .../rustc_typeck/src/check/fn_ctxt/mod.rs | 2 +- .../rustc_typeck/src/check/method/confirm.rs | 4 +- .../rustc_typeck/src/check/method/probe.rs | 2 +- .../rustc_typeck/src/check/method/suggest.rs | 6 +- compiler/rustc_typeck/src/check/mod.rs | 2 +- compiler/rustc_typeck/src/collect.rs | 6 +- .../rustc_typeck/src/collect/item_bounds.rs | 2 +- .../src/impl_wf_check/min_specialization.rs | 6 +- .../ui/associated-types/defaults-wf.stderr | 1 + ...with-supertraits-needing-sized-self.stderr | 1 + src/test/ui/dst/dst-sized-trait-param.stderr | 1 + .../ui/extern/extern-types-unsized.stderr | 4 + ...e-param-can-reference-self-in-trait.stderr | 1 + src/test/ui/issues/issue-10412.stderr | 1 + src/test/ui/issues/issue-18919.stderr | 1 + src/test/ui/issues/issue-20433.stderr | 1 + src/test/ui/issues/issue-23281.stderr | 1 + src/test/ui/issues/issue-60283.stderr | 1 + src/test/ui/mir/issue-80742.stderr | 1 + src/test/ui/range/range-1.stderr | 1 + src/test/ui/substs-ppaux.normal.stderr | 1 + src/test/ui/substs-ppaux.verbose.stderr | 1 + ...adt-param-with-implicit-sized-bound.stderr | 1 + src/test/ui/traits/bad-sized.stderr | 2 + src/test/ui/traits/issue-65673.stderr | 5 ++ .../ui/traits/suggest-where-clause.stderr | 5 ++ .../ui/unsized/unsized-bare-typaram.stderr | 2 + src/test/ui/unsized/unsized-enum.stderr | 1 + .../unsized-inherent-impl-self-type.stderr | 1 + src/test/ui/unsized/unsized-struct.stderr | 2 + .../unsized-trait-impl-self-type.stderr | 1 + .../unsized-trait-impl-trait-arg.stderr | 1 + src/test/ui/unsized/unsized3.stderr | 4 + src/test/ui/unsized/unsized7.stderr | 1 + src/test/ui/wf/wf-fn-where-clause.stderr | 1 + src/test/ui/wf/wf-impl-self-type.stderr | 1 + 66 files changed, 277 insertions(+), 69 deletions(-) diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 1cde4802a40b0..ead2f03ec400a 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -124,7 +124,7 @@ impl Elaborator<'tcx> { let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(data, _) => { + ty::PredicateKind::Trait(data, ..) => { // Get predicates declared on the trait. let predicates = tcx.super_predicates_of(data.def_id()); diff --git a/compiler/rustc_lint/src/traits.rs b/compiler/rustc_lint/src/traits.rs index e632f29e672c0..96a92965a34e5 100644 --- a/compiler/rustc_lint/src/traits.rs +++ b/compiler/rustc_lint/src/traits.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints { let predicates = cx.tcx.explicit_predicates_of(item.def_id); for &(predicate, span) in predicates.predicates { let trait_predicate = match predicate.kind().skip_binder() { - Trait(trait_predicate, _constness) => trait_predicate, + Trait(trait_predicate, _constness, _) => trait_predicate, _ => continue, }; let def_id = trait_predicate.trait_ref.def_id; diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 44c2a550c30e2..befebeca731c0 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -202,7 +202,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { let mut has_emitted = false; for &(predicate, _) in cx.tcx.explicit_item_bounds(def) { // We only look at the `DefId`, so it is safe to skip the binder here. - if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = + if let ty::PredicateKind::Trait(ref poly_trait_predicate, _, _) = predicate.kind().skip_binder() { let def_id = poly_trait_predicate.trait_ref.def_id; diff --git a/compiler/rustc_middle/src/ty/assoc.rs b/compiler/rustc_middle/src/ty/assoc.rs index d005f63ed4383..045b5ae96092e 100644 --- a/compiler/rustc_middle/src/ty/assoc.rs +++ b/compiler/rustc_middle/src/ty/assoc.rs @@ -58,9 +58,44 @@ impl AssocItem { // regions just fine, showing `fn(&MyType)`. tcx.fn_sig(self.def_id).skip_binder().to_string() } - ty::AssocKind::Type => format!("type {};", self.ident), + ty::AssocKind::Type => { + let default = match tcx.hir().get_if_local(self.def_id) { + Some( + hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Type(_, Some(ty)), + .. + }) + | hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::TyAlias(ty), + .. + }), + ) => { + format!(" = {:?}", ty) + } + _ => String::new(), + }; + format!("type {}{};", self.ident, default) + } ty::AssocKind::Const => { - format!("const {}: {:?};", self.ident, tcx.type_of(self.def_id)) + let default = match tcx.hir().get_if_local(self.def_id) { + Some( + hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Const(_, Some(body_id)), + .. + }) + | hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::Const(_, body_id), + .. + }), + ) => match tcx.hir().find(body_id.hir_id) { + Some(value) => { + format!(" = {:?}", value) + } + None => String::new(), + }, + _ => String::new(), + }; + format!("const {}: {:?}{};", self.ident, tcx.type_of(self.def_id), default) } } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index d13cbdd122854..20052ff2861e8 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2097,7 +2097,7 @@ impl<'tcx> TyCtxt<'tcx> { let generic_predicates = self.super_predicates_of(trait_did); for (predicate, _) in generic_predicates.predicates { - if let ty::PredicateKind::Trait(data, _) = predicate.kind().skip_binder() { + if let ty::PredicateKind::Trait(data, ..) = predicate.kind().skip_binder() { if set.insert(data.def_id()) { stack.push(data.def_id()); } diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 9faa172a4973f..c02ecc2912429 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -216,7 +216,7 @@ impl FlagComputation { fn add_predicate_atom(&mut self, atom: ty::PredicateKind<'_>) { match atom { - ty::PredicateKind::Trait(trait_pred, _constness) => { + ty::PredicateKind::Trait(trait_pred, _constness, _) => { self.add_substs(trait_pred.trait_ref.substs); } ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 227aa8dc284e2..ae84306ebb836 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -424,6 +424,38 @@ impl<'a, 'tcx> HashStable> for Predicate<'tcx> { } } +#[derive(Clone, Copy, Debug, Eq, TyEncodable, TyDecodable, TypeFoldable)] +pub enum ImplicitTraitPredicate { + Yes, + No, +} + +impl Hash for ImplicitTraitPredicate { + fn hash(&self, _: &mut H) + where + H: Hasher, + { + // This type is used purely for improving diagnostics involving default `Sized` bounds on + // type parameters and associated types, it has no incidence whatsoever on anything else. + } +} + +impl ::rustc_data_structures::stable_hasher::HashStable for ImplicitTraitPredicate { + #[inline] + fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut StableHasher) { + // This type is used purely for improving diagnostics involving default `Sized` bounds on + // type parameters and associated types, it has no incidence whatsoever on anything else. + } +} + +impl PartialEq for ImplicitTraitPredicate { + fn eq(&self, _: &ImplicitTraitPredicate) -> bool { + // This type is used purely for improving diagnostics involving default `Sized` bounds on + // type parameters and associated types, it has no incidence whatsoever on anything else. + true + } +} + #[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub enum PredicateKind<'tcx> { @@ -434,7 +466,7 @@ pub enum PredicateKind<'tcx> { /// A trait predicate will have `Constness::Const` if it originates /// from a bound on a `const fn` without the `?const` opt-out (e.g., /// `const fn foobar() {}`). - Trait(TraitPredicate<'tcx>, Constness), + Trait(TraitPredicate<'tcx>, Constness, ImplicitTraitPredicate), /// `where 'a: 'b` RegionOutlives(RegionOutlivesPredicate<'tcx>), @@ -723,8 +755,23 @@ impl ToPredicate<'tcx> for PredicateKind<'tcx> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - PredicateKind::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness) - .to_predicate(tcx) + PredicateKind::Trait( + ty::TraitPredicate { trait_ref: self.value }, + self.constness, + ImplicitTraitPredicate::No, + ) + .to_predicate(tcx) + } +} + +impl<'tcx> ToPredicate<'tcx> for ImplicitSized>>> { + fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + PredicateKind::Trait( + ty::TraitPredicate { trait_ref: self.0.value.skip_binder() }, + self.0.constness, + ImplicitTraitPredicate::Yes, + ) + .to_predicate(tcx) } } @@ -732,7 +779,11 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { self.value .map_bound(|trait_ref| { - PredicateKind::Trait(ty::TraitPredicate { trait_ref }, self.constness) + PredicateKind::Trait( + ty::TraitPredicate { trait_ref }, + self.constness, + ImplicitTraitPredicate::No, + ) }) .to_predicate(tcx) } @@ -740,7 +791,11 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - self.value.map_bound(|value| PredicateKind::Trait(value, self.constness)).to_predicate(tcx) + self.value + .map_bound(|value| { + PredicateKind::Trait(value, self.constness, ImplicitTraitPredicate::No) + }) + .to_predicate(tcx) } } @@ -766,7 +821,7 @@ impl<'tcx> Predicate<'tcx> { pub fn to_opt_poly_trait_ref(self) -> Option>> { let predicate = self.kind(); match predicate.skip_binder() { - PredicateKind::Trait(t, constness) => { + PredicateKind::Trait(t, constness, _) => { Some(ConstnessAnd { constness, value: predicate.rebind(t.trait_ref) }) } PredicateKind::Projection(..) @@ -1264,7 +1319,17 @@ pub trait WithConstness: Sized { } } +pub struct ImplicitSized(T); + +pub trait WithImplicitSized: Sized { + #[inline] + fn with_implicit(self) -> ImplicitSized { + ImplicitSized(self) + } +} + impl WithConstness for T {} +impl WithImplicitSized for T {} #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable)] pub struct ParamEnvAnd<'tcx, T> { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 25557bdd1000e..dd2c31ebbfe50 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -630,8 +630,11 @@ pub trait PrettyPrinter<'tcx>: for (predicate, _) in bounds { let predicate = predicate.subst(self.tcx(), substs); let bound_predicate = predicate.kind(); - if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() { + if let ty::PredicateKind::Trait(pred, _, _default) = + bound_predicate.skip_binder() + { let trait_ref = bound_predicate.rebind(pred.trait_ref); + // Maybe use `_default` to determine whether to show `Sized` if `Yes`. // Don't print +Sized, but rather +?Sized if absent. if Some(trait_ref.def_id()) == self.tcx().lang_items().sized_trait() { is_sized = true; @@ -2191,7 +2194,7 @@ define_print_and_forward_display! { ty::PredicateKind<'tcx> { match *self { - ty::PredicateKind::Trait(ref data, constness) => { + ty::PredicateKind::Trait(ref data, constness, _) => { if let hir::Constness::Const = constness { p!("const "); } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 7290c41d615df..0f995eac79e66 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -174,7 +174,7 @@ impl fmt::Debug for ty::Predicate<'tcx> { impl fmt::Debug for ty::PredicateKind<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - ty::PredicateKind::Trait(ref a, constness) => { + ty::PredicateKind::Trait(ref a, constness, _) => { if let hir::Constness::Const = constness { write!(f, "const ")?; } @@ -419,8 +419,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> { type Lifted = ty::PredicateKind<'tcx>; fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option { match self { - ty::PredicateKind::Trait(data, constness) => { - tcx.lift(data).map(|data| ty::PredicateKind::Trait(data, constness)) + ty::PredicateKind::Trait(data, constness, d) => { + tcx.lift(data).map(|data| ty::PredicateKind::Trait(data, constness, d)) } ty::PredicateKind::Subtype(data) => tcx.lift(data).map(ty::PredicateKind::Subtype), ty::PredicateKind::RegionOutlives(data) => { diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs index 09cafddeeffde..9080bda62d7ed 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs @@ -2718,6 +2718,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Some(ty::PredicateKind::Trait( ty::TraitPredicate { trait_ref }, hir::Constness::NotConst, + ty::ImplicitTraitPredicate::No, )), locations, category, diff --git a/compiler/rustc_mir/src/transform/check_consts/validation.rs b/compiler/rustc_mir/src/transform/check_consts/validation.rs index 4fbd27c89d9c8..77fd3563316ce 100644 --- a/compiler/rustc_mir/src/transform/check_consts/validation.rs +++ b/compiler/rustc_mir/src/transform/check_consts/validation.rs @@ -423,7 +423,7 @@ impl Validator<'mir, 'tcx> { ty::PredicateKind::Subtype(_) => { bug!("subtype predicate on function: {:#?}", predicate) } - ty::PredicateKind::Trait(pred, _constness) => { + ty::PredicateKind::Trait(pred, _constness, _) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } diff --git a/compiler/rustc_mir/src/transform/function_item_references.rs b/compiler/rustc_mir/src/transform/function_item_references.rs index 8d02ac6d9b774..c1f5603cd3fc3 100644 --- a/compiler/rustc_mir/src/transform/function_item_references.rs +++ b/compiler/rustc_mir/src/transform/function_item_references.rs @@ -132,7 +132,7 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> { /// If the given predicate is the trait `fmt::Pointer`, returns the bound parameter type. fn is_pointer_trait(&self, bound: &PredicateKind<'tcx>) -> Option> { - if let ty::PredicateKind::Trait(predicate, _) = bound { + if let ty::PredicateKind::Trait(predicate, _, _) = bound { if self.tcx.is_diagnostic_item(sym::pointer_trait, predicate.def_id()) { Some(predicate.trait_ref.self_ty()) } else { diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index e64f12ef48f22..16b07fbe11aff 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -122,7 +122,7 @@ where fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow { match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => { + ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _, _) => { self.visit_trait(trait_ref) } ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => { diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index ca7cdc4caf505..f3deb28bc4131 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -2658,7 +2658,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { let obligations = predicates.predicates.iter().filter_map(|&(pred, _)| { let bound_predicate = pred.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(data, _) => { + ty::PredicateKind::Trait(data, _, _) => { // The order here needs to match what we would get from `subst_supertrait` let pred_bound_vars = bound_predicate.bound_vars(); let mut all_bound_vars = bound_vars.clone(); diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index f54eb0914a5a7..f6a363362b44b 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -415,8 +415,8 @@ impl AutoTraitFinder<'tcx> { let mut should_add_new = true; user_computed_preds.retain(|&old_pred| { if let ( - ty::PredicateKind::Trait(new_trait, _), - ty::PredicateKind::Trait(old_trait, _), + ty::PredicateKind::Trait(new_trait, _, _), + ty::PredicateKind::Trait(old_trait, _, _), ) = (new_pred.kind().skip_binder(), old_pred.kind().skip_binder()) { if new_trait.def_id() == old_trait.def_id() { @@ -638,7 +638,7 @@ impl AutoTraitFinder<'tcx> { let bound_predicate = predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(p, _) => { + ty::PredicateKind::Trait(p, _, _) => { // Add this to `predicates` so that we end up calling `select` // with it. If this predicate ends up being unimplemented, // then `evaluate_predicates` will handle adding it the `ParamEnv` 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 a8d560d15ee9a..0c41fe4b12123 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -259,7 +259,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(trait_predicate, _) => { + ty::PredicateKind::Trait(trait_predicate, _, implicit) => { let trait_predicate = bound_predicate.rebind(trait_predicate); let trait_predicate = self.resolve_vars_if_possible(trait_predicate); @@ -311,6 +311,61 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { post_message, )) ); + if let ty::ImplicitTraitPredicate::Yes = implicit { + if let ObligationCauseCode::BindingObligation(item_def_id, _) = + obligation.cause.code.peel_derives() + { + match self.tcx.hir().get_if_local(*item_def_id) { + Some(hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Type(bounds, ty), + ident, + .. + })) => { + err.note( + "associated types introduce an implicit `Sized` \ + obligation", + ); + match (bounds, ty) { + ([], None) => { + err.span_suggestion_verbose( + ident.span.shrink_to_hi(), + "consider relaxing the `Sized` obligation", + ": ?Sized".to_string(), + Applicability::MaybeIncorrect, + ); + } + ([.., bound], None) => { + err.span_suggestion_verbose( + bound.span().shrink_to_hi(), + "consider relaxing the `Sized` obligation", + " + ?Sized".to_string(), + Applicability::MaybeIncorrect, + ); + } + _ => {} + } + } + Some(hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::TyAlias(_), + .. + })) => { + err.note( + "associated types on `impl` blocks for types, have an \ + implicit mandatory `Sized` obligation; associated \ + types from `trait`s can be relaxed to `?Sized`", + ); + } + _ => { + // This is (likely?) a type parameter. The suggestion is handled + // in `rustc_middle/src/ty/diagnostics.rs`. + err.note( + "type parameters introduce an implicit `Sized` \ + obligation", + ); + } + } + } + } if is_try_conversion { let none_error = self @@ -1106,7 +1161,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { // FIXME: It should be possible to deal with `ForAll` in a cleaner way. let bound_error = error.kind(); let (cond, error) = match (cond.kind().skip_binder(), bound_error.skip_binder()) { - (ty::PredicateKind::Trait(..), ty::PredicateKind::Trait(error, _)) => { + (ty::PredicateKind::Trait(..), ty::PredicateKind::Trait(error, _, _)) => { (cond, bound_error.rebind(error)) } _ => { @@ -1117,7 +1172,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) { let bound_predicate = obligation.predicate.kind(); - if let ty::PredicateKind::Trait(implication, _) = bound_predicate.skip_binder() { + if let ty::PredicateKind::Trait(implication, _, _) = bound_predicate.skip_binder() { let error = error.to_poly_trait_ref(); let implication = bound_predicate.rebind(implication.trait_ref); // FIXME: I'm just not taking associated types at all here. @@ -1532,9 +1587,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { let bound_predicate = predicate.kind(); let mut err = match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(data, _) => { + ty::PredicateKind::Trait(data, _, implicit_sized) => { let trait_ref = bound_predicate.rebind(data.trait_ref); - debug!("trait_ref {:?}", trait_ref); + debug!(?trait_ref, ?implicit_sized); if predicate.references_error() { return; @@ -1797,7 +1852,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { match (obligation.predicate.kind().skip_binder(), obligation.cause.code.peel_derives()) { ( - ty::PredicateKind::Trait(pred, _), + ty::PredicateKind::Trait(pred, _, _), &ObligationCauseCode::BindingObligation(item_def_id, span), ) => (pred, item_def_id, span), _ => return, 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 5c35b515f3d02..cd4410c0dc719 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1384,7 +1384,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // bound was introduced. At least one generator should be present for this diagnostic to be // modified. let (mut trait_ref, mut target_ty) = match obligation.predicate.kind().skip_binder() { - ty::PredicateKind::Trait(p, _) => (Some(p.trait_ref), Some(p.self_ty())), + ty::PredicateKind::Trait(p, _, _) => (Some(p.trait_ref), Some(p.self_ty())), _ => (None, None), }; let mut generator = None; diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 120680092baaa..87390c50ef405 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -353,7 +353,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { // Evaluation will discard candidates using the leak check. // This means we need to pass it the bound version of our // predicate. - ty::PredicateKind::Trait(trait_ref, _constness) => { + ty::PredicateKind::Trait(trait_ref, _constness, _) => { let trait_obligation = obligation.with(binder.rebind(trait_ref)); self.process_trait_obligation( @@ -388,7 +388,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> { } }, Some(pred) => match pred { - ty::PredicateKind::Trait(data, _) => { + ty::PredicateKind::Trait(data, _, _) => { let trait_obligation = obligation.with(Binder::dummy(data)); self.process_trait_obligation( diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index d5e1bd3f9ea2e..081c2e446ceda 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -280,7 +280,7 @@ fn predicate_references_self( let self_ty = tcx.types.self_param; let has_self_ty = |arg: &GenericArg<'_>| arg.walk().any(|arg| arg == self_ty.into()); match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(ref data, _) => { + ty::PredicateKind::Trait(ref data, _, _) => { // In the case of a trait predicate, we can skip the "self" type. if data.trait_ref.substs[1..].iter().any(has_self_ty) { Some(sp) } else { None } } @@ -331,7 +331,7 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool { let predicates = predicates.instantiate_identity(tcx).predicates; elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| { match obligation.predicate.kind().skip_binder() { - ty::PredicateKind::Trait(ref trait_pred, _) => { + ty::PredicateKind::Trait(ref trait_pred, _, _) => { trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0) } ty::PredicateKind::Projection(..) diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs index de538c62c5e39..481c2241950a9 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs @@ -15,7 +15,8 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> { // `&T`, accounts for about 60% percentage of the predicates // we have to prove. No need to canonicalize and all that for // such cases. - if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate.kind().skip_binder() { + if let ty::PredicateKind::Trait(trait_ref, _, _) = key.value.predicate.kind().skip_binder() + { if let Some(sized_def_id) = tcx.lang_items().sized_trait() { if trait_ref.def_id() == sized_def_id { if trait_ref.self_ty().is_trivially_sized(tcx) { diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index ea5eb2b68667f..f3f4856de0286 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -454,7 +454,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let result = ensure_sufficient_stack(|| { let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(t, _) => { + ty::PredicateKind::Trait(t, _, _) => { let t = bound_predicate.rebind(t); debug_assert!(!t.has_escaping_bound_vars()); let obligation = obligation.with(t); @@ -865,7 +865,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool { let result = match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()), + ty::PredicateKind::Trait(ref data, _, _) => self.tcx().trait_is_auto(data.def_id()), _ => false, }; debug!(?predicate, ?result, "coinductive_predicate"); @@ -1205,7 +1205,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .enumerate() .filter_map(|(idx, bound)| { let bound_predicate = bound.kind(); - if let ty::PredicateKind::Trait(pred, _) = bound_predicate.skip_binder() { + if let ty::PredicateKind::Trait(pred, _, _) = bound_predicate.skip_binder() { let bound = bound_predicate.rebind(pred.trait_ref); if self.infcx.probe(|_| { match self.match_normalize_trait_ref( diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index f592cf1cd249d..145468c42efda 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -107,7 +107,7 @@ pub fn predicate_obligations<'a, 'tcx>( // It's ok to skip the binder here because wf code is prepared for it match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(t, _) => { + ty::PredicateKind::Trait(t, _, _) => { wf.compute_trait_ref(&t.trait_ref, Elaborate::None); } ty::PredicateKind::RegionOutlives(..) => {} @@ -225,7 +225,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( } } } - ty::PredicateKind::Trait(pred, _) => { + ty::PredicateKind::Trait(pred, _, _) => { // An associated item obligation born out of the `trait` failed to be met. An example // can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`. debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred); diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 39890fd5b0574..6d4855c3ecd36 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -87,7 +87,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment { chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner))) } - ty::PredicateKind::Trait(predicate, _) => chalk_ir::DomainGoal::FromEnv( + ty::PredicateKind::Trait(predicate, _, _) => chalk_ir::DomainGoal::FromEnv( chalk_ir::FromEnv::Trait(predicate.trait_ref.lower_into(interner)), ), ty::PredicateKind::RegionOutlives(predicate) => chalk_ir::DomainGoal::Holds( @@ -137,7 +137,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predi collect_bound_vars(interner, interner.tcx, self.kind()); let value = match predicate { - ty::PredicateKind::Trait(predicate, _) => { + ty::PredicateKind::Trait(predicate, _, _) => { chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::Holds( chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner)), )) @@ -569,7 +569,7 @@ impl<'tcx> LowerInto<'tcx, Option { + ty::PredicateKind::Trait(predicate, _, _) => { Some(chalk_ir::WhereClause::Implemented(predicate.trait_ref.lower_into(interner))) } ty::PredicateKind::RegionOutlives(predicate) => { @@ -702,7 +702,7 @@ impl<'tcx> LowerInto<'tcx, Option Some(chalk_ir::Binders::new( + ty::PredicateKind::Trait(predicate, _, _) => Some(chalk_ir::Binders::new( binders, chalk_solve::rust_ir::InlineBound::TraitBound( predicate.trait_ref.lower_into(interner), diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index ef1956210448d..1a6d2c09c5ab7 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -1293,7 +1293,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(pred, _) => { + ty::PredicateKind::Trait(pred, _, _) => { let pred = bound_predicate.rebind(pred); associated_types.entry(span).or_default().extend( tcx.associated_items(pred.def_id()) diff --git a/compiler/rustc_typeck/src/bounds.rs b/compiler/rustc_typeck/src/bounds.rs index 5d20064072263..80dac62c55ee3 100644 --- a/compiler/rustc_typeck/src/bounds.rs +++ b/compiler/rustc_typeck/src/bounds.rs @@ -2,7 +2,7 @@ //! `ty` form from the HIR. use rustc_hir::Constness; -use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, WithConstness}; +use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, WithConstness, WithImplicitSized}; use rustc_span::Span; /// Collects together a list of type bounds. These lists of bounds occur in many places @@ -61,7 +61,7 @@ impl<'tcx> Bounds<'tcx> { def_id: sized, substs: tcx.mk_substs_trait(param_ty, &[]), }); - (trait_ref.without_const().to_predicate(tcx), span) + (trait_ref.without_const().with_implicit().to_predicate(tcx), span) }) }); diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index d056f2c90f988..acd35eb85181b 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -603,7 +603,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut suggest_box = !impl_trait_ret_ty.obligations.is_empty(); for o in impl_trait_ret_ty.obligations { match o.predicate.kind().skip_binder() { - ty::PredicateKind::Trait(t, constness) => { + ty::PredicateKind::Trait(t, constness, _) => { let pred = ty::PredicateKind::Trait( ty::TraitPredicate { trait_ref: ty::TraitRef { @@ -612,6 +612,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, }, constness, + ty::ImplicitTraitPredicate::No, ); let obl = Obligation::new( o.cause.clone(), diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 236fec94bdba7..3b29fb48f38be 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -586,7 +586,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { debug!("coerce_unsized resolve step: {:?}", obligation); let bound_predicate = obligation.predicate.kind(); let trait_pred = match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(trait_pred, _) + ty::PredicateKind::Trait(trait_pred, _, _) if traits.contains(&trait_pred.def_id()) => { if unsize_did == trait_pred.def_id() { diff --git a/compiler/rustc_typeck/src/check/dropck.rs b/compiler/rustc_typeck/src/check/dropck.rs index 01276495c185a..1d3f1c8cdf203 100644 --- a/compiler/rustc_typeck/src/check/dropck.rs +++ b/compiler/rustc_typeck/src/check/dropck.rs @@ -229,7 +229,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( let predicate = predicate.kind(); let p = p.kind(); match (predicate.skip_binder(), p.skip_binder()) { - (ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => { + (ty::PredicateKind::Trait(a, _, _), ty::PredicateKind::Trait(b, _, _)) => { relator.relate(predicate.rebind(a), p.rebind(b)).is_ok() } (ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => { diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 96569ae0e7720..c38fd79740c58 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -793,7 +793,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { bound_predicate.rebind(data).required_poly_trait_ref(self.tcx), obligation, )), - ty::PredicateKind::Trait(data, _) => { + ty::PredicateKind::Trait(data, _, _) => { Some((bound_predicate.rebind(data).to_poly_trait_ref(), obligation)) } ty::PredicateKind::Subtype(..) => None, diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 49aea19c8d099..be3fa7661df4d 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -903,7 +903,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { continue; } - if let ty::PredicateKind::Trait(predicate, _) = + if let ty::PredicateKind::Trait(predicate, _, _) = error.obligation.predicate.kind().skip_binder() { // Collect the argument position for all arguments that could have caused this @@ -954,7 +954,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let hir::ExprKind::Path(qpath) = &path.kind { if let hir::QPath::Resolved(_, path) = &qpath { for error in errors { - if let ty::PredicateKind::Trait(predicate, _) = + if let ty::PredicateKind::Trait(predicate, _, _) = error.obligation.predicate.kind().skip_binder() { // If any of the type arguments in this path segment caused the diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs index 4da4835f7cfbb..3b888f2ddb5d3 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs @@ -201,7 +201,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { predicates: tcx.arena.alloc_from_iter( self.param_env.caller_bounds().iter().filter_map(|predicate| { match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(data, _) if data.self_ty().is_param(index) => { + ty::PredicateKind::Trait(data, _, _) if data.self_ty().is_param(index) => { // HACK(eddyb) should get the original `Span`. let span = tcx.def_span(def_id); Some((predicate, span)) diff --git a/compiler/rustc_typeck/src/check/method/confirm.rs b/compiler/rustc_typeck/src/check/method/confirm.rs index f546a0d896354..44f7124b43808 100644 --- a/compiler/rustc_typeck/src/check/method/confirm.rs +++ b/compiler/rustc_typeck/src/check/method/confirm.rs @@ -496,7 +496,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied()) // We don't care about regions here. .filter_map(|obligation| match obligation.predicate.kind().skip_binder() { - ty::PredicateKind::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => { + ty::PredicateKind::Trait(trait_pred, _, _) + if trait_pred.def_id() == sized_def_id => + { let span = iter::zip(&predicates.predicates, &predicates.spans) .find_map( |(p, span)| { diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index 440e0f4e1a2ac..02b5296a25444 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -832,7 +832,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| { let bound_predicate = predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(trait_predicate, _) => { + ty::PredicateKind::Trait(trait_predicate, _, _) => { match *trait_predicate.trait_ref.self_ty().kind() { ty::Param(p) if p == param_ty => { Some(bound_predicate.rebind(trait_predicate.trait_ref)) diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 16382c7e7a4bd..9d43e940c50a1 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -683,7 +683,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut collect_type_param_suggestions = |self_ty: Ty<'tcx>, parent_pred: &ty::Predicate<'tcx>, obligation: &str| { // We don't care about regions here, so it's fine to skip the binder here. - if let (ty::Param(_), ty::PredicateKind::Trait(p, _)) = + if let (ty::Param(_), ty::PredicateKind::Trait(p, _, _)) = (self_ty.kind(), parent_pred.kind().skip_binder()) { if let ty::Adt(def, _) = p.trait_ref.self_ty().kind() { @@ -763,7 +763,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { bound_span_label(projection_ty.self_ty(), &obligation, &quiet); Some((obligation, projection_ty.self_ty())) } - ty::PredicateKind::Trait(poly_trait_ref, _) => { + ty::PredicateKind::Trait(poly_trait_ref, _, _) => { let p = poly_trait_ref.trait_ref; let self_ty = p.self_ty(); let path = p.print_only_trait_path(); @@ -1194,7 +1194,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match p.kind().skip_binder() { // Hide traits if they are present in predicates as they can be fixed without // having to implement them. - ty::PredicateKind::Trait(t, _) => t.def_id() == info.def_id, + ty::PredicateKind::Trait(t, _, _) => t.def_id() == info.def_id, ty::PredicateKind::Projection(p) => { p.projection_ty.item_def_id == info.def_id } diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index ad7853b7cd0f1..ee5e46d07a757 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -886,7 +886,7 @@ fn bounds_from_generic_predicates<'tcx>( debug!("predicate {:?}", predicate); let bound_predicate = predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(trait_predicate, _) => { + ty::PredicateKind::Trait(trait_predicate, _, _) => { let entry = types.entry(trait_predicate.self_ty()).or_default(); let def_id = trait_predicate.def_id(); if Some(def_id) != tcx.lang_items().sized_trait() { diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index ee3ac3b62d9ec..a7177274c33f3 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -619,7 +619,7 @@ fn type_param_predicates( ) .into_iter() .filter(|(predicate, _)| match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(data, _) => data.self_ty().is_param(index), + ty::PredicateKind::Trait(data, _, _) => data.self_ty().is_param(index), _ => false, }), ); @@ -1153,7 +1153,7 @@ fn super_predicates_that_define_assoc_type( // which will, in turn, reach indirect supertraits. for &(pred, span) in superbounds { debug!("superbound: {:?}", pred); - if let ty::PredicateKind::Trait(bound, _) = pred.kind().skip_binder() { + if let ty::PredicateKind::Trait(bound, _, _) = pred.kind().skip_binder() { tcx.at(span).super_predicates_of(bound.def_id()); } } @@ -2331,7 +2331,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat .iter() .copied() .filter(|(pred, _)| match pred.kind().skip_binder() { - ty::PredicateKind::Trait(tr, _) => !is_assoc_item_ty(tr.self_ty()), + ty::PredicateKind::Trait(tr, _, _) => !is_assoc_item_ty(tr.self_ty()), ty::PredicateKind::Projection(proj) => { !is_assoc_item_ty(proj.projection_ty.self_ty()) } diff --git a/compiler/rustc_typeck/src/collect/item_bounds.rs b/compiler/rustc_typeck/src/collect/item_bounds.rs index a5b36445aae2e..706bdb4fa5736 100644 --- a/compiler/rustc_typeck/src/collect/item_bounds.rs +++ b/compiler/rustc_typeck/src/collect/item_bounds.rs @@ -38,7 +38,7 @@ fn associated_type_bounds<'tcx>( let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| { match pred.kind().skip_binder() { - ty::PredicateKind::Trait(tr, _) => tr.self_ty() == item_ty, + ty::PredicateKind::Trait(tr, _, _) => tr.self_ty() == item_ty, ty::PredicateKind::Projection(proj) => proj.projection_ty.self_ty() == item_ty, ty::PredicateKind::TypeOutlives(outlives) => outlives.0 == item_ty, _ => false, diff --git a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs index 505d9a59d9c2f..e4196bc0c5e4e 100644 --- a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs @@ -366,7 +366,7 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc _ if predicate.is_global() => (), // We allow specializing on explicitly marked traits with no associated // items. - ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => { + ty::PredicateKind::Trait(pred, hir::Constness::NotConst, _) => { if !matches!( trait_predicate_kind(tcx, predicate), Some(TraitSpecializationKind::Marker) @@ -394,10 +394,10 @@ fn trait_predicate_kind<'tcx>( predicate: ty::Predicate<'tcx>, ) -> Option { match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => { + ty::PredicateKind::Trait(pred, hir::Constness::NotConst, _) => { Some(tcx.trait_def(pred.def_id()).specialization_kind) } - ty::PredicateKind::Trait(_, hir::Constness::Const) + ty::PredicateKind::Trait(_, hir::Constness::Const, _) | ty::PredicateKind::RegionOutlives(_) | ty::PredicateKind::TypeOutlives(_) | ty::PredicateKind::Projection(_) diff --git a/src/test/ui/associated-types/defaults-wf.stderr b/src/test/ui/associated-types/defaults-wf.stderr index d4fa5be742ff3..2c0662a8bc4f2 100644 --- a/src/test/ui/associated-types/defaults-wf.stderr +++ b/src/test/ui/associated-types/defaults-wf.stderr @@ -9,6 +9,7 @@ LL | type Ty = Vec<[u8]>; LL | pub struct Vec { | - required by this bound in `Vec` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[u8]` error: aborting due to previous error diff --git a/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr b/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr index 8fdca54d2d8b8..4a38a36543b2e 100644 --- a/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr +++ b/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr @@ -9,6 +9,7 @@ LL | trait ArithmeticOps: Add + Sub + Mul LL | pub trait Add { | --- required by this bound in `Add` | + = note: type parameters introduce an implicit `Sized` obligation help: consider further restricting `Self` | LL | trait ArithmeticOps: Add + Sub + Mul + Div + Sized {} diff --git a/src/test/ui/dst/dst-sized-trait-param.stderr b/src/test/ui/dst/dst-sized-trait-param.stderr index 481c01a75e5a9..319dbb1ddf170 100644 --- a/src/test/ui/dst/dst-sized-trait-param.stderr +++ b/src/test/ui/dst/dst-sized-trait-param.stderr @@ -7,6 +7,7 @@ LL | LL | impl Foo<[isize]> for usize { } | ^^^^^^^^^^^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[isize]` help: consider relaxing the implicit `Sized` restriction | diff --git a/src/test/ui/extern/extern-types-unsized.stderr b/src/test/ui/extern/extern-types-unsized.stderr index 72e4be51822e2..629b6452d0280 100644 --- a/src/test/ui/extern/extern-types-unsized.stderr +++ b/src/test/ui/extern/extern-types-unsized.stderr @@ -7,6 +7,7 @@ LL | fn assert_sized() {} LL | assert_sized::(); | ^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `A` help: consider relaxing the implicit `Sized` restriction | @@ -22,6 +23,7 @@ LL | fn assert_sized() {} LL | assert_sized::(); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation = help: within `Foo`, the trait `Sized` is not implemented for `A` note: required because it appears within the type `Foo` --> $DIR/extern-types-unsized.rs:9:8 @@ -42,6 +44,7 @@ LL | fn assert_sized() {} LL | assert_sized::>(); | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation = help: within `Bar`, the trait `Sized` is not implemented for `A` note: required because it appears within the type `Bar` --> $DIR/extern-types-unsized.rs:14:8 @@ -62,6 +65,7 @@ LL | fn assert_sized() {} LL | assert_sized::>>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation = help: within `Bar>`, the trait `Sized` is not implemented for `A` note: required because it appears within the type `Bar` --> $DIR/extern-types-unsized.rs:14:8 diff --git a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr index 2b88a6046fdfd..aadd91f5bd700 100644 --- a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr +++ b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr @@ -7,6 +7,7 @@ LL | LL | impl Tsized for () {} | ^^^^^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[()]` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-10412.stderr b/src/test/ui/issues/issue-10412.stderr index 2a6e2414593aa..3f1aded5bc523 100644 --- a/src/test/ui/issues/issue-10412.stderr +++ b/src/test/ui/issues/issue-10412.stderr @@ -55,6 +55,7 @@ LL | trait Serializable<'self, T> { LL | impl<'self> Serializable for &'self str { | ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `str` help: consider relaxing the implicit `Sized` restriction | diff --git a/src/test/ui/issues/issue-18919.stderr b/src/test/ui/issues/issue-18919.stderr index d4b93eb074cfe..9240ae331be45 100644 --- a/src/test/ui/issues/issue-18919.stderr +++ b/src/test/ui/issues/issue-18919.stderr @@ -7,6 +7,7 @@ LL | fn ho_func(f: Option) { LL | enum Option { | - required by this bound in `Option` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `dyn for<'r> Fn(&'r isize) -> isize` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/issue-18919.rs:7:13 diff --git a/src/test/ui/issues/issue-20433.stderr b/src/test/ui/issues/issue-20433.stderr index 5fed02164b5b7..bfeed2806b2c5 100644 --- a/src/test/ui/issues/issue-20433.stderr +++ b/src/test/ui/issues/issue-20433.stderr @@ -9,6 +9,7 @@ LL | fn iceman(c: Vec<[i32]>) {} LL | pub struct Vec { | - required by this bound in `Vec` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[i32]` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-23281.stderr b/src/test/ui/issues/issue-23281.stderr index a3d2583292551..c8389974447af 100644 --- a/src/test/ui/issues/issue-23281.stderr +++ b/src/test/ui/issues/issue-23281.stderr @@ -7,6 +7,7 @@ LL | pub fn function(funs: Vec ()>) {} LL | struct Vec { | - required by this bound in `Vec` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `(dyn Fn() + 'static)` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/issue-23281.rs:8:12 diff --git a/src/test/ui/issues/issue-60283.stderr b/src/test/ui/issues/issue-60283.stderr index 650570b6471eb..c25e324a10ace 100644 --- a/src/test/ui/issues/issue-60283.stderr +++ b/src/test/ui/issues/issue-60283.stderr @@ -24,6 +24,7 @@ LL | foo((), drop) LL | pub fn drop(_x: T) {} | - required by this bound in `std::mem::drop` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `<() as Trait<'_>>::Item` help: consider further restricting the associated type | diff --git a/src/test/ui/mir/issue-80742.stderr b/src/test/ui/mir/issue-80742.stderr index 961234cf7e854..f26df5254225d 100644 --- a/src/test/ui/mir/issue-80742.stderr +++ b/src/test/ui/mir/issue-80742.stderr @@ -58,6 +58,7 @@ LL | struct Inline LL | let dst = Inline::::new(0); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `dyn Debug` help: consider relaxing the implicit `Sized` restriction | diff --git a/src/test/ui/range/range-1.stderr b/src/test/ui/range/range-1.stderr index 2cebffec990f6..77450cc75c226 100644 --- a/src/test/ui/range/range-1.stderr +++ b/src/test/ui/range/range-1.stderr @@ -25,6 +25,7 @@ LL | let range = *arr..; LL | pub struct RangeFrom { | --- required by this bound in `RangeFrom` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[{integer}]` error: aborting due to 3 previous errors diff --git a/src/test/ui/substs-ppaux.normal.stderr b/src/test/ui/substs-ppaux.normal.stderr index 5bbf4225812b6..cb95654c723ed 100644 --- a/src/test/ui/substs-ppaux.normal.stderr +++ b/src/test/ui/substs-ppaux.normal.stderr @@ -79,6 +79,7 @@ LL | fn bar<'a, T>() where T: 'a {} LL | >::bar; | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `str` note: required because of the requirements on the impl of `Foo<'_, '_, u8>` for `str` --> $DIR/substs-ppaux.rs:11:17 diff --git a/src/test/ui/substs-ppaux.verbose.stderr b/src/test/ui/substs-ppaux.verbose.stderr index 20d7655337448..dff0c9bdff2e8 100644 --- a/src/test/ui/substs-ppaux.verbose.stderr +++ b/src/test/ui/substs-ppaux.verbose.stderr @@ -79,6 +79,7 @@ LL | fn bar<'a, T>() where T: 'a {} LL | >::bar; | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `str` note: required because of the requirements on the impl of `Foo<'_#0r, '_#1r, u8>` for `str` --> $DIR/substs-ppaux.rs:11:17 diff --git a/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr b/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr index 5cb3a404037a7..f86a223093708 100644 --- a/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr +++ b/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr @@ -9,6 +9,7 @@ LL | struct Struct5{ LL | _t: X, | ^^^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/adt-param-with-implicit-sized-bound.rs:18:10 | diff --git a/src/test/ui/traits/bad-sized.stderr b/src/test/ui/traits/bad-sized.stderr index 768893d6e25d4..c1c3d1b9f6d51 100644 --- a/src/test/ui/traits/bad-sized.stderr +++ b/src/test/ui/traits/bad-sized.stderr @@ -20,6 +20,7 @@ LL | let x: Vec = Vec::new(); LL | pub struct Vec { | - required by this bound in `Vec` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `dyn Trait` error[E0277]: the size for values of type `dyn Trait` cannot be known at compilation time @@ -42,6 +43,7 @@ LL | let x: Vec = Vec::new(); LL | pub struct Vec { | - required by this bound in `Vec` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `dyn Trait` error: aborting due to 4 previous errors diff --git a/src/test/ui/traits/issue-65673.stderr b/src/test/ui/traits/issue-65673.stderr index 6f9bb3edfe047..056c7e7223b0d 100644 --- a/src/test/ui/traits/issue-65673.stderr +++ b/src/test/ui/traits/issue-65673.stderr @@ -7,7 +7,12 @@ LL | type Ctx; LL | type Ctx = dyn Alias; | ^^^^^^^^^^^^ doesn't have a size known at compile-time | + = note: associated types introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `(dyn Trait + 'static)` +help: consider relaxing the `Sized` obligation + | +LL | type Ctx: ?Sized; + | ^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/traits/suggest-where-clause.stderr b/src/test/ui/traits/suggest-where-clause.stderr index 025706480821d..e1855b3d137ef 100644 --- a/src/test/ui/traits/suggest-where-clause.stderr +++ b/src/test/ui/traits/suggest-where-clause.stderr @@ -11,6 +11,8 @@ LL | mem::size_of::(); | LL | pub const fn size_of() -> usize { | - required by this bound in `std::mem::size_of` + | + = note: type parameters introduce an implicit `Sized` obligation error[E0277]: the size for values of type `U` cannot be known at compilation time --> $DIR/suggest-where-clause.rs:10:5 @@ -26,6 +28,7 @@ LL | mem::size_of::>(); LL | pub const fn size_of() -> usize { | - required by this bound in `std::mem::size_of` | + = note: type parameters introduce an implicit `Sized` obligation note: required because it appears within the type `Misc` --> $DIR/suggest-where-clause.rs:3:8 | @@ -75,6 +78,7 @@ LL | mem::size_of::<[T]>(); LL | pub const fn size_of() -> usize { | - required by this bound in `std::mem::size_of` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[T]` error[E0277]: the size for values of type `[&U]` cannot be known at compilation time @@ -88,6 +92,7 @@ LL | mem::size_of::<[&U]>(); LL | pub const fn size_of() -> usize { | - required by this bound in `std::mem::size_of` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[&U]` error: aborting due to 7 previous errors diff --git a/src/test/ui/unsized/unsized-bare-typaram.stderr b/src/test/ui/unsized/unsized-bare-typaram.stderr index 19978ae24cacb..f945ae16f567e 100644 --- a/src/test/ui/unsized/unsized-bare-typaram.stderr +++ b/src/test/ui/unsized/unsized-bare-typaram.stderr @@ -7,6 +7,8 @@ LL | fn foo() { bar::() } | - ^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` + | + = note: type parameters introduce an implicit `Sized` obligation error: aborting due to previous error diff --git a/src/test/ui/unsized/unsized-enum.stderr b/src/test/ui/unsized/unsized-enum.stderr index 601db7d1cd983..90ff343b8b3d0 100644 --- a/src/test/ui/unsized/unsized-enum.stderr +++ b/src/test/ui/unsized/unsized-enum.stderr @@ -9,6 +9,7 @@ LL | fn foo2() { not_sized::>() } | | | this type parameter needs to be `std::marker::Sized` | + = note: type parameters introduce an implicit `Sized` obligation help: you could relax the implicit `Sized` bound on `U` if it were used through indirection like `&U` or `Box` --> $DIR/unsized-enum.rs:4:10 | diff --git a/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr b/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr index 9d072eda4e81c..f883d218a1576 100644 --- a/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr +++ b/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr @@ -9,6 +9,7 @@ LL | impl S5 { | | | this type parameter needs to be `std::marker::Sized` | + = note: type parameters introduce an implicit `Sized` obligation help: you could relax the implicit `Sized` bound on `Y` if it were used through indirection like `&Y` or `Box` --> $DIR/unsized-inherent-impl-self-type.rs:5:11 | diff --git a/src/test/ui/unsized/unsized-struct.stderr b/src/test/ui/unsized/unsized-struct.stderr index e38375bff46cf..8b56002ea2537 100644 --- a/src/test/ui/unsized/unsized-struct.stderr +++ b/src/test/ui/unsized/unsized-struct.stderr @@ -9,6 +9,7 @@ LL | fn foo2() { not_sized::>() } | | | this type parameter needs to be `std::marker::Sized` | + = note: type parameters introduce an implicit `Sized` obligation help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/unsized-struct.rs:4:12 | @@ -28,6 +29,7 @@ LL | fn bar2() { is_sized::>() } | | | this type parameter needs to be `std::marker::Sized` | + = note: type parameters introduce an implicit `Sized` obligation note: required because it appears within the type `Bar` --> $DIR/unsized-struct.rs:11:8 | diff --git a/src/test/ui/unsized/unsized-trait-impl-self-type.stderr b/src/test/ui/unsized/unsized-trait-impl-self-type.stderr index aef0d0cbb8395..e91b586446d4c 100644 --- a/src/test/ui/unsized/unsized-trait-impl-self-type.stderr +++ b/src/test/ui/unsized/unsized-trait-impl-self-type.stderr @@ -9,6 +9,7 @@ LL | impl T3 for S5 { | | | this type parameter needs to be `std::marker::Sized` | + = note: type parameters introduce an implicit `Sized` obligation help: you could relax the implicit `Sized` bound on `Y` if it were used through indirection like `&Y` or `Box` --> $DIR/unsized-trait-impl-self-type.rs:8:11 | diff --git a/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr b/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr index f48d4ef9f1461..ec42784d162d9 100644 --- a/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr +++ b/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr @@ -9,6 +9,7 @@ LL | impl T2 for S4 { | | | this type parameter needs to be `std::marker::Sized` | + = note: type parameters introduce an implicit `Sized` obligation help: consider relaxing the implicit `Sized` restriction | LL | trait T2 { diff --git a/src/test/ui/unsized/unsized3.stderr b/src/test/ui/unsized/unsized3.stderr index bd36008aca044..86fd9b8f208e3 100644 --- a/src/test/ui/unsized/unsized3.stderr +++ b/src/test/ui/unsized/unsized3.stderr @@ -9,6 +9,7 @@ LL | f2::(x); LL | fn f2(x: &X) { | - required by this bound in `f2` | + = note: type parameters introduce an implicit `Sized` obligation help: consider relaxing the implicit `Sized` restriction | LL | fn f2(x: &X) { @@ -25,6 +26,7 @@ LL | f4::(x); LL | fn f4(x: &X) { | - required by this bound in `f4` | + = note: type parameters introduce an implicit `Sized` obligation help: consider relaxing the implicit `Sized` restriction | LL | fn f4(x: &X) { @@ -41,6 +43,7 @@ LL | fn f8(x1: &S, x2: &S) { LL | f5(x1); | ^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation note: required because it appears within the type `S` --> $DIR/unsized3.rs:28:8 | @@ -93,6 +96,7 @@ LL | fn f10(x1: Box>) { LL | f5(&(32, *x1)); | ^^^^^^^^^^ doesn't have a size known at compile-time | + = note: type parameters introduce an implicit `Sized` obligation note: required because it appears within the type `S` --> $DIR/unsized3.rs:28:8 | diff --git a/src/test/ui/unsized/unsized7.stderr b/src/test/ui/unsized/unsized7.stderr index 7dbddd4ed2443..072dcdca92cf5 100644 --- a/src/test/ui/unsized/unsized7.stderr +++ b/src/test/ui/unsized/unsized7.stderr @@ -9,6 +9,7 @@ LL | impl T1 for S3 { | | | this type parameter needs to be `std::marker::Sized` | + = note: type parameters introduce an implicit `Sized` obligation help: consider relaxing the implicit `Sized` restriction | LL | trait T1 { diff --git a/src/test/ui/wf/wf-fn-where-clause.stderr b/src/test/ui/wf/wf-fn-where-clause.stderr index e463e3db887a5..3337dce440a36 100644 --- a/src/test/ui/wf/wf-fn-where-clause.stderr +++ b/src/test/ui/wf/wf-fn-where-clause.stderr @@ -21,6 +21,7 @@ LL | fn bar() where Vec:, {} LL | struct Vec { | - required by this bound in `Vec` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `(dyn Copy + 'static)` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/wf-fn-where-clause.rs:16:12 diff --git a/src/test/ui/wf/wf-impl-self-type.stderr b/src/test/ui/wf/wf-impl-self-type.stderr index bc30fc90f3a28..e13deb422459a 100644 --- a/src/test/ui/wf/wf-impl-self-type.stderr +++ b/src/test/ui/wf/wf-impl-self-type.stderr @@ -9,6 +9,7 @@ LL | impl Foo for Option<[u8]> {} LL | pub enum Option { | - required by this bound in `Option` | + = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[u8]` error: aborting due to previous error From 2c58ef5a5a77c7f7cfeab23a9e91b2e2e1306da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 2 Jun 2021 16:49:51 -0700 Subject: [PATCH 07/11] Move label for `Sized` obligation introduced by type param or assoc type to its own note --- .../src/traits/error_reporting/mod.rs | 19 +++++---- .../src/traits/error_reporting/suggestions.rs | 14 ++++++- .../ui/associated-types/defaults-wf.stderr | 11 +++-- ...with-supertraits-needing-sized-self.stderr | 9 ++-- src/test/ui/dst/dst-sized-trait-param.stderr | 9 ++-- .../ui/extern/extern-types-unsized.stderr | 36 +++++++++------- ...e-param-can-reference-self-in-trait.stderr | 9 ++-- src/test/ui/issues/issue-10412.stderr | 9 ++-- src/test/ui/issues/issue-18919.stderr | 9 ++-- src/test/ui/issues/issue-20433.stderr | 11 +++-- src/test/ui/issues/issue-23281.stderr | 9 ++-- src/test/ui/issues/issue-60283.stderr | 11 +++-- src/test/ui/mir/issue-80742.stderr | 9 ++-- src/test/ui/range/range-1.stderr | 11 +++-- src/test/ui/substs-ppaux.normal.stderr | 9 ++-- src/test/ui/substs-ppaux.verbose.stderr | 9 ++-- ...adt-param-with-implicit-sized-bound.stderr | 9 ++-- src/test/ui/traits/bad-sized.stderr | 22 +++++----- src/test/ui/traits/issue-65673.stderr | 9 ++-- .../ui/traits/suggest-where-clause.stderr | 42 +++++++++---------- .../ui/unsized/unsized-bare-typaram.stderr | 8 ++-- src/test/ui/unsized/unsized-enum.stderr | 9 ++-- .../unsized-inherent-impl-self-type.stderr | 9 ++-- src/test/ui/unsized/unsized-struct.stderr | 18 ++++---- .../unsized-trait-impl-self-type.stderr | 9 ++-- .../unsized-trait-impl-trait-arg.stderr | 9 ++-- src/test/ui/unsized/unsized3.stderr | 36 +++++++++------- src/test/ui/unsized/unsized7.stderr | 9 ++-- src/test/ui/wf/wf-fn-where-clause.stderr | 9 ++-- src/test/ui/wf/wf-impl-self-type.stderr | 11 +++-- 30 files changed, 218 insertions(+), 185 deletions(-) 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 0c41fe4b12123..d6b9b9df6b83f 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -202,6 +202,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &obligation.cause.code, &mut vec![], &mut Default::default(), + None, ); err.emit(); @@ -232,6 +233,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) { let tcx = self.tcx; let span = obligation.cause.span; + let mut obligation_note = None; let mut err = match *error { SelectionError::Unimplemented => { @@ -321,7 +323,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ident, .. })) => { - err.note( + obligation_note = Some( "associated types introduce an implicit `Sized` \ obligation", ); @@ -349,7 +351,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { kind: hir::ImplItemKind::TyAlias(_), .. })) => { - err.note( + obligation_note = Some( "associated types on `impl` blocks for types, have an \ implicit mandatory `Sized` obligation; associated \ types from `trait`s can be relaxed to `?Sized`", @@ -358,7 +360,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { _ => { // This is (likely?) a type parameter. The suggestion is handled // in `rustc_middle/src/ty/diagnostics.rs`. - err.note( + obligation_note = Some( "type parameters introduce an implicit `Sized` \ obligation", ); @@ -423,7 +425,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { points_at_arg, have_alt_message, ) { - self.note_obligation_cause(&mut err, obligation); + self.note_obligation_cause(&mut err, obligation, obligation_note); err.emit(); return; } @@ -852,7 +854,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } }; - self.note_obligation_cause(&mut err, obligation); + self.note_obligation_cause(&mut err, obligation, obligation_note); self.point_at_returns_when_relevant(&mut err, &obligation); err.emit(); @@ -1135,6 +1137,7 @@ trait InferCtxtPrivExt<'tcx> { &self, err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, + note: Option<&str>, ); fn suggest_unsized_bound_if_applicable( @@ -1355,7 +1358,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { _ => None, }; self.note_type_err(&mut diag, &obligation.cause, secondary_span, values, err, true); - self.note_obligation_cause(&mut diag, obligation); + self.note_obligation_cause(&mut diag, obligation, None); diag.emit(); } }); @@ -1764,7 +1767,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { err } }; - self.note_obligation_cause(&mut err, obligation); + self.note_obligation_cause(&mut err, obligation, None); err.emit(); } @@ -1828,6 +1831,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { &self, err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, + note: Option<&str>, ) { // First, attempt to add note to this error with an async-await-specific // message, and fall back to regular note otherwise. @@ -1838,6 +1842,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { &obligation.cause.code, &mut vec![], &mut Default::default(), + note, ); self.suggest_unsized_bound_if_applicable(err, obligation); } 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 cd4410c0dc719..51e72c1161901 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -162,6 +162,7 @@ pub trait InferCtxtExt<'tcx> { cause_code: &ObligationCauseCode<'tcx>, obligated_types: &mut Vec<&ty::TyS<'tcx>>, seen_requirements: &mut FxHashSet, + note: Option<&str>, ) where T: fmt::Display; @@ -1872,6 +1873,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { next_code.unwrap(), &mut Vec::new(), &mut Default::default(), + None, ); } @@ -1882,6 +1884,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { cause_code: &ObligationCauseCode<'tcx>, obligated_types: &mut Vec<&ty::TyS<'tcx>>, seen_requirements: &mut FxHashSet, + note: Option<&str>, ) where T: fmt::Display, { @@ -1946,7 +1949,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } } if span != DUMMY_SP { - err.span_label(span, &msg); + if let Some(note) = note { + let mut sp: MultiSpan = span.into(); + sp.push_span_label(span, msg); + err.span_note(sp, note); + } else { + err.span_label(span, &msg); + } } else { err.note(&msg); } @@ -2148,6 +2157,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &data.parent_code, obligated_types, seen_requirements, + note, ) }); } @@ -2218,6 +2228,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &data.parent_code, obligated_types, seen_requirements, + note, ) }); } @@ -2232,6 +2243,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &data.parent_code, obligated_types, seen_requirements, + note, ) }); } diff --git a/src/test/ui/associated-types/defaults-wf.stderr b/src/test/ui/associated-types/defaults-wf.stderr index 2c0662a8bc4f2..4a0ddb33ba9d8 100644 --- a/src/test/ui/associated-types/defaults-wf.stderr +++ b/src/test/ui/associated-types/defaults-wf.stderr @@ -3,14 +3,13 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | LL | type Ty = Vec<[u8]>; | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | -LL | pub struct Vec { - | - required by this bound in `Vec` - | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[u8]` +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | +LL | pub struct Vec { + | ^ required by this bound in `Vec` error: aborting due to previous error diff --git a/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr b/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr index 4a38a36543b2e..d43c9d387fcd8 100644 --- a/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr +++ b/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr @@ -3,13 +3,12 @@ error[E0277]: the size for values of type `Self` cannot be known at compilation | LL | trait ArithmeticOps: Add + Sub + Mul + Div {} | ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/ops/arith.rs:LL:COL | -LL | pub trait Add { - | --- required by this bound in `Add` +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/core/src/ops/arith.rs:LL:COL | - = note: type parameters introduce an implicit `Sized` obligation +LL | pub trait Add { + | ^^^ required by this bound in `Add` help: consider further restricting `Self` | LL | trait ArithmeticOps: Add + Sub + Mul + Div + Sized {} diff --git a/src/test/ui/dst/dst-sized-trait-param.stderr b/src/test/ui/dst/dst-sized-trait-param.stderr index 319dbb1ddf170..80b2c7e57ba40 100644 --- a/src/test/ui/dst/dst-sized-trait-param.stderr +++ b/src/test/ui/dst/dst-sized-trait-param.stderr @@ -1,14 +1,15 @@ error[E0277]: the size for values of type `[isize]` cannot be known at compilation time --> $DIR/dst-sized-trait-param.rs:7:6 | -LL | trait Foo : Sized { fn take(self, x: &T) { } } // Note: T is sized - | - required by this bound in `Foo` -LL | LL | impl Foo<[isize]> for usize { } | ^^^^^^^^^^^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[isize]` +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/dst-sized-trait-param.rs:5:11 + | +LL | trait Foo : Sized { fn take(self, x: &T) { } } // Note: T is sized + | ^ required by this bound in `Foo` help: consider relaxing the implicit `Sized` restriction | LL | trait Foo : Sized { fn take(self, x: &T) { } } // Note: T is sized diff --git a/src/test/ui/extern/extern-types-unsized.stderr b/src/test/ui/extern/extern-types-unsized.stderr index 629b6452d0280..848ad6f6605d4 100644 --- a/src/test/ui/extern/extern-types-unsized.stderr +++ b/src/test/ui/extern/extern-types-unsized.stderr @@ -1,14 +1,15 @@ error[E0277]: the size for values of type `A` cannot be known at compilation time --> $DIR/extern-types-unsized.rs:22:20 | -LL | fn assert_sized() {} - | - required by this bound in `assert_sized` -... LL | assert_sized::(); | ^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `A` +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/extern-types-unsized.rs:19:17 + | +LL | fn assert_sized() {} + | ^ required by this bound in `assert_sized` help: consider relaxing the implicit `Sized` restriction | LL | fn assert_sized() {} @@ -17,19 +18,20 @@ LL | fn assert_sized() {} error[E0277]: the size for values of type `A` cannot be known at compilation time --> $DIR/extern-types-unsized.rs:25:5 | -LL | fn assert_sized() {} - | - required by this bound in `assert_sized` -... LL | assert_sized::(); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation = help: within `Foo`, the trait `Sized` is not implemented for `A` note: required because it appears within the type `Foo` --> $DIR/extern-types-unsized.rs:9:8 | LL | struct Foo { | ^^^ +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/extern-types-unsized.rs:19:17 + | +LL | fn assert_sized() {} + | ^ required by this bound in `assert_sized` help: consider relaxing the implicit `Sized` restriction | LL | fn assert_sized() {} @@ -38,19 +40,20 @@ LL | fn assert_sized() {} error[E0277]: the size for values of type `A` cannot be known at compilation time --> $DIR/extern-types-unsized.rs:28:5 | -LL | fn assert_sized() {} - | - required by this bound in `assert_sized` -... LL | assert_sized::>(); | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation = help: within `Bar`, the trait `Sized` is not implemented for `A` note: required because it appears within the type `Bar` --> $DIR/extern-types-unsized.rs:14:8 | LL | struct Bar { | ^^^ +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/extern-types-unsized.rs:19:17 + | +LL | fn assert_sized() {} + | ^ required by this bound in `assert_sized` help: consider relaxing the implicit `Sized` restriction | LL | fn assert_sized() {} @@ -59,13 +62,9 @@ LL | fn assert_sized() {} error[E0277]: the size for values of type `A` cannot be known at compilation time --> $DIR/extern-types-unsized.rs:31:5 | -LL | fn assert_sized() {} - | - required by this bound in `assert_sized` -... LL | assert_sized::>>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation = help: within `Bar>`, the trait `Sized` is not implemented for `A` note: required because it appears within the type `Bar` --> $DIR/extern-types-unsized.rs:14:8 @@ -77,6 +76,11 @@ note: required because it appears within the type `Bar>` | LL | struct Bar { | ^^^ +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/extern-types-unsized.rs:19:17 + | +LL | fn assert_sized() {} + | ^ required by this bound in `assert_sized` help: consider relaxing the implicit `Sized` restriction | LL | fn assert_sized() {} diff --git a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr index aadd91f5bd700..418bb9487f8b2 100644 --- a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr +++ b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr @@ -1,14 +1,15 @@ error[E0277]: the size for values of type `[()]` cannot be known at compilation time --> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:19:6 | -LL | trait Tsized {} - | - required by this bound in `Tsized` -LL | LL | impl Tsized for () {} | ^^^^^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[()]` +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:17:14 + | +LL | trait Tsized {} + | ^ required by this bound in `Tsized` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-10412.stderr b/src/test/ui/issues/issue-10412.stderr index 3f1aded5bc523..3f96fce8687f8 100644 --- a/src/test/ui/issues/issue-10412.stderr +++ b/src/test/ui/issues/issue-10412.stderr @@ -49,14 +49,15 @@ LL | impl<'self> Serializable for &'self str { error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/issue-10412.rs:6:13 | -LL | trait Serializable<'self, T> { - | - required by this bound in `Serializable` -... LL | impl<'self> Serializable for &'self str { | ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `str` +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/issue-10412.rs:1:27 + | +LL | trait Serializable<'self, T> { + | ^ required by this bound in `Serializable` help: consider relaxing the implicit `Sized` restriction | LL | trait Serializable<'self, T: ?Sized> { diff --git a/src/test/ui/issues/issue-18919.stderr b/src/test/ui/issues/issue-18919.stderr index 9240ae331be45..1ee899f96a863 100644 --- a/src/test/ui/issues/issue-18919.stderr +++ b/src/test/ui/issues/issue-18919.stderr @@ -3,12 +3,13 @@ error[E0277]: the size for values of type `dyn for<'r> Fn(&'r isize) -> isize` c | LL | fn ho_func(f: Option) { | ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time -... -LL | enum Option { - | - required by this bound in `Option` | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `dyn for<'r> Fn(&'r isize) -> isize` +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/issue-18919.rs:7:13 + | +LL | enum Option { + | ^ required by this bound in `Option` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/issue-18919.rs:7:13 | diff --git a/src/test/ui/issues/issue-20433.stderr b/src/test/ui/issues/issue-20433.stderr index bfeed2806b2c5..e2080057cc398 100644 --- a/src/test/ui/issues/issue-20433.stderr +++ b/src/test/ui/issues/issue-20433.stderr @@ -3,14 +3,13 @@ error[E0277]: the size for values of type `[i32]` cannot be known at compilation | LL | fn iceman(c: Vec<[i32]>) {} | ^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | -LL | pub struct Vec { - | - required by this bound in `Vec` - | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[i32]` +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | +LL | pub struct Vec { + | ^ required by this bound in `Vec` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-23281.stderr b/src/test/ui/issues/issue-23281.stderr index c8389974447af..46a1a08a92ebc 100644 --- a/src/test/ui/issues/issue-23281.stderr +++ b/src/test/ui/issues/issue-23281.stderr @@ -3,12 +3,13 @@ error[E0277]: the size for values of type `(dyn Fn() + 'static)` cannot be known | LL | pub fn function(funs: Vec ()>) {} | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time -... -LL | struct Vec { - | - required by this bound in `Vec` | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `(dyn Fn() + 'static)` +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/issue-23281.rs:8:12 + | +LL | struct Vec { + | ^ required by this bound in `Vec` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/issue-23281.rs:8:12 | diff --git a/src/test/ui/issues/issue-60283.stderr b/src/test/ui/issues/issue-60283.stderr index c25e324a10ace..2648cd2e17bf3 100644 --- a/src/test/ui/issues/issue-60283.stderr +++ b/src/test/ui/issues/issue-60283.stderr @@ -18,14 +18,13 @@ error[E0277]: the size for values of type `<() as Trait<'_>>::Item` cannot be kn | LL | foo((), drop) | ^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL | -LL | pub fn drop(_x: T) {} - | - required by this bound in `std::mem::drop` - | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `<() as Trait<'_>>::Item` +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | +LL | pub fn drop(_x: T) {} + | ^ required by this bound in `std::mem::drop` help: consider further restricting the associated type | LL | fn main() where <() as Trait<'_>>::Item: Sized { diff --git a/src/test/ui/mir/issue-80742.stderr b/src/test/ui/mir/issue-80742.stderr index f26df5254225d..b4c4d2208af75 100644 --- a/src/test/ui/mir/issue-80742.stderr +++ b/src/test/ui/mir/issue-80742.stderr @@ -52,14 +52,15 @@ LL | [u8; size_of::() + 1]: , error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time --> $DIR/issue-80742.rs:31:15 | -LL | struct Inline - | - required by this bound in `Inline` -... LL | let dst = Inline::::new(0); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `dyn Debug` +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/issue-80742.rs:13:15 + | +LL | struct Inline + | ^ required by this bound in `Inline` help: consider relaxing the implicit `Sized` restriction | LL | struct Inline diff --git a/src/test/ui/range/range-1.stderr b/src/test/ui/range/range-1.stderr index 77450cc75c226..0ebee0b6e5252 100644 --- a/src/test/ui/range/range-1.stderr +++ b/src/test/ui/range/range-1.stderr @@ -19,14 +19,13 @@ error[E0277]: the size for values of type `[{integer}]` cannot be known at compi | LL | let range = *arr..; | ^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/ops/range.rs:LL:COL | -LL | pub struct RangeFrom { - | --- required by this bound in `RangeFrom` - | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[{integer}]` +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/core/src/ops/range.rs:LL:COL + | +LL | pub struct RangeFrom { + | ^^^ required by this bound in `RangeFrom` error: aborting due to 3 previous errors diff --git a/src/test/ui/substs-ppaux.normal.stderr b/src/test/ui/substs-ppaux.normal.stderr index cb95654c723ed..2eb49fc853e86 100644 --- a/src/test/ui/substs-ppaux.normal.stderr +++ b/src/test/ui/substs-ppaux.normal.stderr @@ -73,19 +73,20 @@ LL | let x: () = foo::<'static>(); error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/substs-ppaux.rs:49:5 | -LL | fn bar<'a, T>() where T: 'a {} - | -- required by this bound in `Foo::bar` -... LL | >::bar; | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `str` note: required because of the requirements on the impl of `Foo<'_, '_, u8>` for `str` --> $DIR/substs-ppaux.rs:11:17 | LL | impl<'a,'b,T,S> Foo<'a, 'b, S> for T {} | ^^^^^^^^^^^^^^ ^ +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/substs-ppaux.rs:7:30 + | +LL | fn bar<'a, T>() where T: 'a {} + | ^^ required by this bound in `Foo::bar` error: aborting due to 5 previous errors diff --git a/src/test/ui/substs-ppaux.verbose.stderr b/src/test/ui/substs-ppaux.verbose.stderr index dff0c9bdff2e8..1e24247ee4ae5 100644 --- a/src/test/ui/substs-ppaux.verbose.stderr +++ b/src/test/ui/substs-ppaux.verbose.stderr @@ -73,19 +73,20 @@ LL | let x: () = foo::<'static>(); error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/substs-ppaux.rs:49:5 | -LL | fn bar<'a, T>() where T: 'a {} - | -- required by this bound in `Foo::bar` -... LL | >::bar; | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `str` note: required because of the requirements on the impl of `Foo<'_#0r, '_#1r, u8>` for `str` --> $DIR/substs-ppaux.rs:11:17 | LL | impl<'a,'b,T,S> Foo<'a, 'b, S> for T {} | ^^^^^^^^^^^^^^ ^ +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/substs-ppaux.rs:7:30 + | +LL | fn bar<'a, T>() where T: 'a {} + | ^^ required by this bound in `Foo::bar` error: aborting due to 5 previous errors diff --git a/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr b/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr index f86a223093708..849c27cb56da2 100644 --- a/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr +++ b/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr @@ -1,15 +1,16 @@ error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/adt-param-with-implicit-sized-bound.rs:25:9 | -LL | struct X(T); - | - required by this bound in `X` -... LL | struct Struct5{ | - this type parameter needs to be `std::marker::Sized` LL | _t: X, | ^^^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/adt-param-with-implicit-sized-bound.rs:18:10 + | +LL | struct X(T); + | ^ required by this bound in `X` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/adt-param-with-implicit-sized-bound.rs:18:10 | diff --git a/src/test/ui/traits/bad-sized.stderr b/src/test/ui/traits/bad-sized.stderr index c1c3d1b9f6d51..492b7f2ad495a 100644 --- a/src/test/ui/traits/bad-sized.stderr +++ b/src/test/ui/traits/bad-sized.stderr @@ -14,14 +14,13 @@ error[E0277]: the size for values of type `dyn Trait` cannot be known at compila | LL | let x: Vec = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | -LL | pub struct Vec { - | - required by this bound in `Vec` - | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `dyn Trait` +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | +LL | pub struct Vec { + | ^ required by this bound in `Vec` error[E0277]: the size for values of type `dyn Trait` cannot be known at compilation time --> $DIR/bad-sized.rs:4:37 @@ -37,14 +36,13 @@ error[E0277]: the size for values of type `dyn Trait` cannot be known at compila | LL | let x: Vec = Vec::new(); | ^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | -LL | pub struct Vec { - | - required by this bound in `Vec` - | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `dyn Trait` +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + | +LL | pub struct Vec { + | ^ required by this bound in `Vec` error: aborting due to 4 previous errors diff --git a/src/test/ui/traits/issue-65673.stderr b/src/test/ui/traits/issue-65673.stderr index 056c7e7223b0d..d03282d03d55d 100644 --- a/src/test/ui/traits/issue-65673.stderr +++ b/src/test/ui/traits/issue-65673.stderr @@ -1,14 +1,15 @@ error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time --> $DIR/issue-65673.rs:9:16 | -LL | type Ctx; - | --------- required by this bound in `WithType::Ctx` -... LL | type Ctx = dyn Alias; | ^^^^^^^^^^^^ doesn't have a size known at compile-time | - = note: associated types introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `(dyn Trait + 'static)` +note: associated types introduce an implicit `Sized` obligation + --> $DIR/issue-65673.rs:4:5 + | +LL | type Ctx; + | ^^^^^^^^^ required by this bound in `WithType::Ctx` help: consider relaxing the `Sized` obligation | LL | type Ctx: ?Sized; diff --git a/src/test/ui/traits/suggest-where-clause.stderr b/src/test/ui/traits/suggest-where-clause.stderr index e1855b3d137ef..f95ebb5ef4987 100644 --- a/src/test/ui/traits/suggest-where-clause.stderr +++ b/src/test/ui/traits/suggest-where-clause.stderr @@ -6,13 +6,12 @@ LL | fn check() { LL | // suggest a where-clause, if needed LL | mem::size_of::(); | ^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL | -LL | pub const fn size_of() -> usize { - | - required by this bound in `std::mem::size_of` +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | - = note: type parameters introduce an implicit `Sized` obligation +LL | pub const fn size_of() -> usize { + | ^ required by this bound in `std::mem::size_of` error[E0277]: the size for values of type `U` cannot be known at compilation time --> $DIR/suggest-where-clause.rs:10:5 @@ -22,18 +21,17 @@ LL | fn check() { ... LL | mem::size_of::>(); | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL - | -LL | pub const fn size_of() -> usize { - | - required by this bound in `std::mem::size_of` | - = note: type parameters introduce an implicit `Sized` obligation note: required because it appears within the type `Misc` --> $DIR/suggest-where-clause.rs:3:8 | LL | struct Misc(T); | ^^^^ +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | +LL | pub const fn size_of() -> usize { + | ^ required by this bound in `std::mem::size_of` error[E0277]: the trait bound `u64: From` is not satisfied --> $DIR/suggest-where-clause.rs:15:5 @@ -72,28 +70,26 @@ error[E0277]: the size for values of type `[T]` cannot be known at compilation t | LL | mem::size_of::<[T]>(); | ^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL - | -LL | pub const fn size_of() -> usize { - | - required by this bound in `std::mem::size_of` | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[T]` +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | +LL | pub const fn size_of() -> usize { + | ^ required by this bound in `std::mem::size_of` error[E0277]: the size for values of type `[&U]` cannot be known at compilation time --> $DIR/suggest-where-clause.rs:31:5 | LL | mem::size_of::<[&U]>(); | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL | -LL | pub const fn size_of() -> usize { - | - required by this bound in `std::mem::size_of` - | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[&U]` +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | +LL | pub const fn size_of() -> usize { + | ^ required by this bound in `std::mem::size_of` error: aborting due to 7 previous errors diff --git a/src/test/ui/unsized/unsized-bare-typaram.stderr b/src/test/ui/unsized/unsized-bare-typaram.stderr index f945ae16f567e..0722b6fb834e6 100644 --- a/src/test/ui/unsized/unsized-bare-typaram.stderr +++ b/src/test/ui/unsized/unsized-bare-typaram.stderr @@ -1,14 +1,16 @@ error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/unsized-bare-typaram.rs:2:29 | -LL | fn bar() { } - | - required by this bound in `bar` LL | fn foo() { bar::() } | - ^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | - = note: type parameters introduce an implicit `Sized` obligation +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized-bare-typaram.rs:1:8 + | +LL | fn bar() { } + | ^ required by this bound in `bar` error: aborting due to previous error diff --git a/src/test/ui/unsized/unsized-enum.stderr b/src/test/ui/unsized/unsized-enum.stderr index 90ff343b8b3d0..1ac8d9094eb84 100644 --- a/src/test/ui/unsized/unsized-enum.stderr +++ b/src/test/ui/unsized/unsized-enum.stderr @@ -1,15 +1,16 @@ error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/unsized-enum.rs:6:36 | -LL | enum Foo { FooSome(U), FooNone } - | - required by this bound in `Foo` -LL | fn foo1() { not_sized::>() } // Hunky dory. LL | fn foo2() { not_sized::>() } | - ^^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | - = note: type parameters introduce an implicit `Sized` obligation +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized-enum.rs:4:10 + | +LL | enum Foo { FooSome(U), FooNone } + | ^ required by this bound in `Foo` help: you could relax the implicit `Sized` bound on `U` if it were used through indirection like `&U` or `Box` --> $DIR/unsized-enum.rs:4:10 | diff --git a/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr b/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr index f883d218a1576..deaec463be323 100644 --- a/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr +++ b/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr @@ -1,15 +1,16 @@ error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized-inherent-impl-self-type.rs:7:17 | -LL | struct S5(Y); - | - required by this bound in `S5` -LL | LL | impl S5 { | - ^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | - = note: type parameters introduce an implicit `Sized` obligation +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized-inherent-impl-self-type.rs:5:11 + | +LL | struct S5(Y); + | ^ required by this bound in `S5` help: you could relax the implicit `Sized` bound on `Y` if it were used through indirection like `&Y` or `Box` --> $DIR/unsized-inherent-impl-self-type.rs:5:11 | diff --git a/src/test/ui/unsized/unsized-struct.stderr b/src/test/ui/unsized/unsized-struct.stderr index 8b56002ea2537..1d5ca414a6810 100644 --- a/src/test/ui/unsized/unsized-struct.stderr +++ b/src/test/ui/unsized/unsized-struct.stderr @@ -1,15 +1,16 @@ error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/unsized-struct.rs:6:36 | -LL | struct Foo { data: T } - | - required by this bound in `Foo` -LL | fn foo1() { not_sized::>() } // Hunky dory. LL | fn foo2() { not_sized::>() } | - ^^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | - = note: type parameters introduce an implicit `Sized` obligation +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized-struct.rs:4:12 + | +LL | struct Foo { data: T } + | ^ required by this bound in `Foo` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/unsized-struct.rs:4:12 | @@ -21,20 +22,21 @@ LL | struct Foo { data: T } error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/unsized-struct.rs:13:24 | -LL | fn is_sized() { } - | - required by this bound in `is_sized` -... LL | fn bar2() { is_sized::>() } | - ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | - = note: type parameters introduce an implicit `Sized` obligation note: required because it appears within the type `Bar` --> $DIR/unsized-struct.rs:11:8 | LL | struct Bar { data: T } | ^^^ +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized-struct.rs:1:13 + | +LL | fn is_sized() { } + | ^ required by this bound in `is_sized` error: aborting due to 2 previous errors diff --git a/src/test/ui/unsized/unsized-trait-impl-self-type.stderr b/src/test/ui/unsized/unsized-trait-impl-self-type.stderr index e91b586446d4c..f7153507a1af3 100644 --- a/src/test/ui/unsized/unsized-trait-impl-self-type.stderr +++ b/src/test/ui/unsized/unsized-trait-impl-self-type.stderr @@ -1,15 +1,16 @@ error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized-trait-impl-self-type.rs:10:27 | -LL | struct S5(Y); - | - required by this bound in `S5` -LL | LL | impl T3 for S5 { | - ^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | - = note: type parameters introduce an implicit `Sized` obligation +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized-trait-impl-self-type.rs:8:11 + | +LL | struct S5(Y); + | ^ required by this bound in `S5` help: you could relax the implicit `Sized` bound on `Y` if it were used through indirection like `&Y` or `Box` --> $DIR/unsized-trait-impl-self-type.rs:8:11 | diff --git a/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr b/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr index ec42784d162d9..bfa51995227fe 100644 --- a/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr +++ b/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr @@ -1,15 +1,16 @@ error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized-trait-impl-trait-arg.rs:8:17 | -LL | trait T2 { - | - required by this bound in `T2` -... LL | impl T2 for S4 { | - ^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | - = note: type parameters introduce an implicit `Sized` obligation +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized-trait-impl-trait-arg.rs:4:10 + | +LL | trait T2 { + | ^ required by this bound in `T2` help: consider relaxing the implicit `Sized` restriction | LL | trait T2 { diff --git a/src/test/ui/unsized/unsized3.stderr b/src/test/ui/unsized/unsized3.stderr index 86fd9b8f208e3..ffdcd0b6a371b 100644 --- a/src/test/ui/unsized/unsized3.stderr +++ b/src/test/ui/unsized/unsized3.stderr @@ -5,11 +5,12 @@ LL | fn f1(x: &X) { | - this type parameter needs to be `std::marker::Sized` LL | f2::(x); | ^ doesn't have a size known at compile-time -... -LL | fn f2(x: &X) { - | - required by this bound in `f2` | - = note: type parameters introduce an implicit `Sized` obligation +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized3.rs:10:7 + | +LL | fn f2(x: &X) { + | ^ required by this bound in `f2` help: consider relaxing the implicit `Sized` restriction | LL | fn f2(x: &X) { @@ -22,11 +23,12 @@ LL | fn f3(x: &X) { | - this type parameter needs to be `std::marker::Sized` LL | f4::(x); | ^ doesn't have a size known at compile-time -... -LL | fn f4(x: &X) { - | - required by this bound in `f4` | - = note: type parameters introduce an implicit `Sized` obligation +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized3.rs:21:7 + | +LL | fn f4(x: &X) { + | ^ required by this bound in `f4` help: consider relaxing the implicit `Sized` restriction | LL | fn f4(x: &X) { @@ -35,20 +37,21 @@ LL | fn f4(x: &X) { error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized3.rs:33:8 | -LL | fn f5(x: &Y) {} - | - required by this bound in `f5` -... LL | fn f8(x1: &S, x2: &S) { | - this type parameter needs to be `std::marker::Sized` LL | f5(x1); | ^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation note: required because it appears within the type `S` --> $DIR/unsized3.rs:28:8 | LL | struct S { | ^ +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized3.rs:24:7 + | +LL | fn f5(x: &Y) {} + | ^ required by this bound in `f5` help: consider relaxing the implicit `Sized` restriction | LL | fn f5(x: &Y) {} @@ -88,21 +91,22 @@ LL | struct S { error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized3.rs:45:8 | -LL | fn f5(x: &Y) {} - | - required by this bound in `f5` -... LL | fn f10(x1: Box>) { | - this type parameter needs to be `std::marker::Sized` LL | f5(&(32, *x1)); | ^^^^^^^^^^ doesn't have a size known at compile-time | - = note: type parameters introduce an implicit `Sized` obligation note: required because it appears within the type `S` --> $DIR/unsized3.rs:28:8 | LL | struct S { | ^ = note: required because it appears within the type `({integer}, S)` +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized3.rs:24:7 + | +LL | fn f5(x: &Y) {} + | ^ required by this bound in `f5` help: consider relaxing the implicit `Sized` restriction | LL | fn f5(x: &Y) {} diff --git a/src/test/ui/unsized/unsized7.stderr b/src/test/ui/unsized/unsized7.stderr index 072dcdca92cf5..6a36161c039f4 100644 --- a/src/test/ui/unsized/unsized7.stderr +++ b/src/test/ui/unsized/unsized7.stderr @@ -1,15 +1,16 @@ error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized7.rs:12:21 | -LL | trait T1 { - | - required by this bound in `T1` -... LL | impl T1 for S3 { | - ^^^^^ doesn't have a size known at compile-time | | | this type parameter needs to be `std::marker::Sized` | - = note: type parameters introduce an implicit `Sized` obligation +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/unsized7.rs:7:10 + | +LL | trait T1 { + | ^ required by this bound in `T1` help: consider relaxing the implicit `Sized` restriction | LL | trait T1 { diff --git a/src/test/ui/wf/wf-fn-where-clause.stderr b/src/test/ui/wf/wf-fn-where-clause.stderr index 3337dce440a36..5c1fe444c9ab1 100644 --- a/src/test/ui/wf/wf-fn-where-clause.stderr +++ b/src/test/ui/wf/wf-fn-where-clause.stderr @@ -17,12 +17,13 @@ error[E0277]: the size for values of type `(dyn Copy + 'static)` cannot be known | LL | fn bar() where Vec:, {} | ^^^^^^^^^^^^^ doesn't have a size known at compile-time -... -LL | struct Vec { - | - required by this bound in `Vec` | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `(dyn Copy + 'static)` +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/wf-fn-where-clause.rs:16:12 + | +LL | struct Vec { + | ^ required by this bound in `Vec` help: you could relax the implicit `Sized` bound on `T` if it were used through indirection like `&T` or `Box` --> $DIR/wf-fn-where-clause.rs:16:12 | diff --git a/src/test/ui/wf/wf-impl-self-type.stderr b/src/test/ui/wf/wf-impl-self-type.stderr index e13deb422459a..88a9ff2774197 100644 --- a/src/test/ui/wf/wf-impl-self-type.stderr +++ b/src/test/ui/wf/wf-impl-self-type.stderr @@ -3,14 +3,13 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation | LL | impl Foo for Option<[u8]> {} | ^^^^^^^^^^^^ doesn't have a size known at compile-time - | - ::: $SRC_DIR/core/src/option.rs:LL:COL | -LL | pub enum Option { - | - required by this bound in `Option` - | - = note: type parameters introduce an implicit `Sized` obligation = help: the trait `Sized` is not implemented for `[u8]` +note: type parameters introduce an implicit `Sized` obligation + --> $SRC_DIR/core/src/option.rs:LL:COL + | +LL | pub enum Option { + | ^ required by this bound in `Option` error: aborting due to previous error From 6dab5973acca11ede3ca032e62244d551126b288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 2 Jun 2021 17:09:54 -0700 Subject: [PATCH 08/11] Fix rustdoc --- src/librustdoc/clean/auto_trait.rs | 4 ++-- src/librustdoc/clean/mod.rs | 8 ++++---- src/librustdoc/clean/simplify.rs | 2 +- src/tools/clippy/clippy_lints/src/future_not_send.rs | 2 +- .../clippy/clippy_lints/src/needless_pass_by_value.rs | 2 +- .../clippy/clippy_lints/src/unit_return_expecting_ord.rs | 2 +- src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs | 2 +- src/tools/clippy/clippy_utils/src/ty.rs | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index a3f63ea1046e3..cfea393c657dd 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -316,7 +316,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { let bound_predicate = pred.kind(); let tcx = self.cx.tcx; let regions = match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(poly_trait_pred, _) => { + ty::PredicateKind::Trait(poly_trait_pred, _, _) => { tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred)) } ty::PredicateKind::Projection(poly_proj_pred) => { @@ -465,7 +465,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { .filter(|p| { !orig_bounds.contains(p) || match p.kind().skip_binder() { - ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait, + ty::PredicateKind::Trait(pred, _, _) => pred.def_id() == sized_trait, _ => false, } }) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d1c18821ea644..1d36868977ded 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -346,7 +346,7 @@ impl<'a> Clean> for ty::Predicate<'a> { fn clean(&self, cx: &mut DocContext<'_>) -> Option { let bound_predicate = self.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(pred, _) => Some(bound_predicate.rebind(pred).clean(cx)), + ty::PredicateKind::Trait(pred, _, _) => Some(bound_predicate.rebind(pred).clean(cx)), ty::PredicateKind::RegionOutlives(pred) => pred.clean(cx), ty::PredicateKind::TypeOutlives(pred) => pred.clean(cx), ty::PredicateKind::Projection(pred) => Some(pred.clean(cx)), @@ -633,7 +633,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, ty::GenericPredicates<'tcx let param_idx = (|| { let bound_p = p.kind(); match bound_p.skip_binder() { - ty::PredicateKind::Trait(pred, _constness) => { + ty::PredicateKind::Trait(pred, _constness, _) => { if let ty::Param(param) = pred.self_ty().kind() { return Some(param.index); } @@ -1566,8 +1566,8 @@ impl<'tcx> Clean for Ty<'tcx> { .filter_map(|bound| { let bound_predicate = bound.kind(); let trait_ref = match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(tr, _constness) => { - bound_predicate.rebind(tr.trait_ref) + ty::PredicateKind::Trait(pred, _constness, _) => { + bound_predicate.rebind(pred.trait_ref) } ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => { if let Some(r) = reg.clean(cx) { diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index d4d0a8ce24c7b..567ffb64fb45e 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -129,7 +129,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId) .predicates .iter() .filter_map(|(pred, _)| { - if let ty::PredicateKind::Trait(pred, _) = pred.kind().skip_binder() { + if let ty::PredicateKind::Trait(pred, _, _) = pred.kind().skip_binder() { if pred.trait_ref.self_ty() == self_ty { Some(pred.def_id()) } else { None } } else { None diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index 515b8887453b9..45525e4e38ca1 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -94,7 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { cx.tcx.infer_ctxt().enter(|infcx| { for FulfillmentError { obligation, .. } in send_errors { infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred, _) = obligation.predicate.kind().skip_binder() { + if let Trait(trait_pred, _, _) = obligation.predicate.kind().skip_binder() { db.note(&format!( "`{}` doesn't implement `{}`", trait_pred.self_ty(), diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index e33a33e238633..7fd3ef48fc369 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { .filter_map(|obligation| { // Note that we do not want to deal with qualified predicates here. match obligation.predicate.kind().no_bound_vars() { - Some(ty::PredicateKind::Trait(pred, _)) if pred.def_id() != sized_trait => Some(pred), + Some(ty::PredicateKind::Trait(pred, _, _)) if pred.def_id() != sized_trait => Some(pred), _ => None, } }) diff --git a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs index 1c420a5042721..eae07ac92fb26 100644 --- a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs +++ b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs @@ -43,7 +43,7 @@ fn get_trait_predicates_for_trait_id<'tcx>( let mut preds = Vec::new(); for (pred, _) in generics.predicates { if_chain! { - if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind().skip_binder(); + if let PredicateKind::Trait(poly_trait_pred, _, _) = pred.kind().skip_binder(); let trait_pred = cx.tcx.erase_late_bound_regions(pred.kind().rebind(poly_trait_pred)); if let Some(trait_def_id) = trait_id; if trait_def_id == trait_pred.trait_ref.def_id; diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 0e6ead675c247..36e690852a0af 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -36,7 +36,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv: Option<&Ru ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate), ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate), ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate), - ty::PredicateKind::Trait(pred, _) => { + ty::PredicateKind::Trait(pred, _, _) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index a92d3be5d3cf2..a1b3a310fd360 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -152,7 +152,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { ty::Tuple(substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { - if let ty::PredicateKind::Trait(trait_predicate, _) = predicate.kind().skip_binder() { + if let ty::PredicateKind::Trait(trait_predicate, _, _) = predicate.kind().skip_binder() { if must_use_attr(cx.tcx.get_attrs(trait_predicate.trait_ref.def_id)).is_some() { return true; } From 6fdf73ff695305429440fdbd50afc2762ee1a06a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 3 Jun 2021 06:58:58 -0700 Subject: [PATCH 09/11] Fix rebase --- src/test/ui/suggestions/issue-84973-blacklist.stderr | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/ui/suggestions/issue-84973-blacklist.stderr b/src/test/ui/suggestions/issue-84973-blacklist.stderr index f1e6ef883ae90..1328f7b7e84c2 100644 --- a/src/test/ui/suggestions/issue-84973-blacklist.stderr +++ b/src/test/ui/suggestions/issue-84973-blacklist.stderr @@ -30,13 +30,15 @@ LL | f_unpin(static || { yield; }); error[E0277]: the size for values of type `dyn Fn()` cannot be known at compilation time --> $DIR/issue-84973-blacklist.rs:22:13 | -LL | fn f_sized(t: T) {} - | - required by this bound in `f_sized` -... LL | f_sized(*ref_cl); | ^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `dyn Fn()` +note: type parameters introduce an implicit `Sized` obligation + --> $DIR/issue-84973-blacklist.rs:9:12 + | +LL | fn f_sized(t: T) {} + | ^ required by this bound in `f_sized` error[E0277]: `Rc<{integer}>` cannot be sent between threads safely --> $DIR/issue-84973-blacklist.rs:28:12 From f33886720db245f91b4690e73fa952e1e8b683ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 3 Jun 2021 19:10:05 -0700 Subject: [PATCH 10/11] Suggest removal of `?Sized` bound when appropriate --- compiler/rustc_ast_lowering/src/item.rs | 15 +- compiler/rustc_infer/src/traits/engine.rs | 8 +- compiler/rustc_infer/src/traits/util.rs | 2 +- compiler/rustc_middle/src/traits/mod.rs | 3 + compiler/rustc_middle/src/ty/diagnostics.rs | 116 ++++++++ .../src/traits/error_reporting/mod.rs | 77 +----- .../error_reporting/on_unimplemented.rs | 3 +- .../src/traits/error_reporting/suggestions.rs | 23 +- .../rustc_trait_selection/src/traits/wf.rs | 8 +- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 8 +- compiler/rustc_typeck/src/collect.rs | 4 +- .../ui/associated-types/defaults-wf.stderr | 2 +- ...with-supertraits-needing-sized-self.stderr | 2 +- .../const-argument-if-length.full.stderr | 9 + .../const-argument-if-length.min.stderr | 4 + .../dst/dst-object-from-unsized-type.stderr | 8 + src/test/ui/dst/dst-sized-trait-param.stderr | 2 +- .../ui/extern/extern-types-unsized.stderr | 8 +- .../projection-bound-cycle-generic.stderr | 9 +- .../projection-bound-cycle.stderr | 9 +- ...e-param-can-reference-self-in-trait.stderr | 2 +- src/test/ui/issues/issue-10412.stderr | 2 +- src/test/ui/issues/issue-18919.stderr | 2 +- src/test/ui/issues/issue-20433.stderr | 2 +- src/test/ui/issues/issue-23281.stderr | 2 +- src/test/ui/issues/issue-27060-2.stderr | 4 + src/test/ui/issues/issue-60283.stderr | 2 +- src/test/ui/mir/issue-80742.stderr | 2 +- src/test/ui/range/range-1.stderr | 2 +- src/test/ui/str/str-mut-idx.stderr | 8 +- src/test/ui/substs-ppaux.normal.stderr | 8 +- src/test/ui/substs-ppaux.verbose.stderr | 8 +- ...adt-param-with-implicit-sized-bound.stderr | 6 +- .../suggestions/issue-84973-blacklist.stderr | 2 +- src/test/ui/trait-bounds/unsized-bound.rs | 32 +++ src/test/ui/trait-bounds/unsized-bound.stderr | 254 ++++++++++++++++++ src/test/ui/traits/bad-sized.stderr | 4 +- src/test/ui/traits/issue-65673.stderr | 12 +- .../mutual-recursion-issue-75860.stderr | 10 +- .../ui/traits/suggest-where-clause.stderr | 16 +- src/test/ui/union/union-sized-field.stderr | 12 + .../ui/unsized/unsized-bare-typaram.stderr | 6 +- src/test/ui/unsized/unsized-enum.stderr | 6 +- src/test/ui/unsized/unsized-enum2.stderr | 16 ++ src/test/ui/unsized/unsized-fn-arg.fixed | 2 +- src/test/ui/unsized/unsized-fn-arg.stderr | 4 + .../unsized-inherent-impl-self-type.stderr | 6 +- src/test/ui/unsized/unsized-struct.stderr | 12 +- .../unsized-trait-impl-self-type.stderr | 6 +- .../unsized-trait-impl-trait-arg.stderr | 6 +- src/test/ui/unsized/unsized3.stderr | 36 ++- src/test/ui/unsized/unsized5.stderr | 16 ++ src/test/ui/unsized/unsized6.stderr | 52 ++++ src/test/ui/unsized/unsized7.stderr | 6 +- src/test/ui/wf/wf-fn-where-clause.stderr | 2 +- src/test/ui/wf/wf-impl-self-type.stderr | 2 +- 56 files changed, 715 insertions(+), 175 deletions(-) create mode 100644 src/test/ui/trait-bounds/unsized-bound.rs create mode 100644 src/test/ui/trait-bounds/unsized-bound.stderr diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 292643d6d7510..8736ebb8aa179 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1477,15 +1477,12 @@ impl<'hir> LoweringContext<'_, 'hir> { ImplTraitContext::disallowed(), ), bounded_ty: this.lower_ty(bounded_ty, ImplTraitContext::disallowed()), - bounds: this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| { - match *bound { - // Ignore `?Trait` bounds. - // They were copied into type parameters already. - GenericBound::Trait(_, TraitBoundModifier::Maybe) => None, - _ => Some( - this.lower_param_bound(bound, ImplTraitContext::disallowed()), - ), - } + bounds: this.arena.alloc_from_iter(bounds.iter().map(|bound| { + // We used to ignore `?Trait` bounds, as they were copied into type + // parameters already, but we need to keep them around only for + // diagnostics when we suggest removal of `?Sized` bounds. See + // `suggest_constraining_type_param`. + this.lower_param_bound(bound, ImplTraitContext::disallowed()) })), span, }) diff --git a/compiler/rustc_infer/src/traits/engine.rs b/compiler/rustc_infer/src/traits/engine.rs index 2710debea9478..cde9b82df503b 100644 --- a/compiler/rustc_infer/src/traits/engine.rs +++ b/compiler/rustc_infer/src/traits/engine.rs @@ -27,14 +27,10 @@ pub trait TraitEngine<'tcx>: 'tcx { cause: ObligationCause<'tcx>, ) { let trait_ref = ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) }; + let predicate = trait_ref.without_const().to_predicate(infcx.tcx); self.register_predicate_obligation( infcx, - Obligation { - cause, - recursion_depth: 0, - param_env, - predicate: trait_ref.without_const().to_predicate(infcx.tcx), - }, + Obligation { cause, recursion_depth: 0, param_env, predicate }, ); } diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index ead2f03ec400a..fe6db395a8e87 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -124,7 +124,7 @@ impl Elaborator<'tcx> { let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(data, ..) => { + ty::PredicateKind::Trait(data, _, _) => { // Get predicates declared on the trait. let predicates = tcx.super_predicates_of(data.def_id()); diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index c9b73c682098b..de560e31eb458 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -195,6 +195,9 @@ pub enum ObligationCauseCode<'tcx> { /// Like `ItemObligation`, but with extra detail on the source of the obligation. BindingObligation(DefId, Span), + /// Like `ItemObligation`, but with extra detail on the source of the obligation. + ImplicitSizedObligation(DefId, Span), + /// A type like `&'a T` is WF only if `T: 'a`. ReferenceOutlivesReferent(Ty<'tcx>), diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 982c8a354b4ab..b02f8847e337a 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -2,6 +2,7 @@ use crate::ty::TyKind::*; use crate::ty::{InferTy, TyCtxt, TyS}; +use rustc_data_structures::fx::FxHashSet; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -130,6 +131,121 @@ pub fn suggest_constraining_type_param( if def_id == tcx.lang_items().sized_trait() { // Type parameters are already `Sized` by default. err.span_label(param.span, &format!("this type parameter needs to be `{}`", constraint)); + // See if there's a `?Sized` bound that can be removed to suggest that. + match param.bounds { + [] => {} + bounds => { + // First look at the `where` clause because we can have `where T: ?Sized`, but that + // `?Sized` bound is *also* included in the `GenericParam` as a bound, which breaks + // the spans. Hence the somewhat involved logic that follows. + let mut where_unsized_bounds = FxHashSet::default(); + for (where_pos, predicate) in generics.where_clause.predicates.iter().enumerate() { + match predicate { + WherePredicate::BoundPredicate(WhereBoundPredicate { + bounded_ty: + hir::Ty { + kind: + hir::TyKind::Path(hir::QPath::Resolved( + None, + hir::Path { + segments: [segment], + res: + hir::def::Res::Def(hir::def::DefKind::TyParam, _), + .. + }, + )), + .. + }, + bounds, + span, + .. + }) if segment.ident.as_str() == param_name => { + for (pos, bound) in bounds.iter().enumerate() { + match bound { + hir::GenericBound::Trait( + poly, + hir::TraitBoundModifier::Maybe, + ) if poly.trait_ref.trait_def_id() == def_id => { + let sp = match ( + bounds.len(), + pos, + generics.where_clause.predicates.len(), + where_pos, + ) { + // where T: ?Sized + // ^^^^^^^^^^^^^^^ + (1, _, 1, _) => generics.where_clause.span, + // where Foo: Bar, T: ?Sized, + // ^^^^^^^^^^^ + (1, _, len, pos) if pos == len - 1 => { + generics.where_clause.predicates[pos - 1] + .span() + .shrink_to_hi() + .to(*span) + } + // where T: ?Sized, Foo: Bar, + // ^^^^^^^^^^^ + (1, _, _, pos) => span.until( + generics.where_clause.predicates[pos + 1].span(), + ), + // where T: ?Sized + Bar, Foo: Bar, + // ^^^^^^^^^ + (_, 0, _, _) => { + bound.span().to(bounds[1].span().shrink_to_lo()) + } + // where T: Bar + ?Sized, Foo: Bar, + // ^^^^^^^^^ + (_, pos, _, _) => bounds[pos - 1] + .span() + .shrink_to_hi() + .to(bound.span()), + }; + where_unsized_bounds.insert(bound.span()); + err.span_suggestion_verbose( + sp, + "consider removing the `?Sized` bound to make the \ + type parameter `Sized`", + String::new(), + Applicability::MaybeIncorrect, + ); + } + _ => {} + } + } + } + _ => {} + } + } + for (pos, bound) in bounds.iter().enumerate() { + match bound { + hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) + if poly.trait_ref.trait_def_id() == def_id + && !where_unsized_bounds.contains(&bound.span()) => + { + let sp = match (bounds.len(), pos) { + // T: ?Sized, + // ^^^^^^^^ + (1, _) => param.span.shrink_to_hi().to(bound.span()), + // T: ?Sized + Bar, + // ^^^^^^^^^ + (_, 0) => bound.span().to(bounds[1].span().shrink_to_lo()), + // T: Bar + ?Sized, + // ^^^^^^^^^ + (_, pos) => bounds[pos - 1].span().shrink_to_hi().to(bound.span()), + }; + err.span_suggestion_verbose( + sp, + "consider removing the `?Sized` bound to make the type parameter \ + `Sized`", + String::new(), + Applicability::MaybeIncorrect, + ); + } + _ => {} + } + } + } + } return true; } let mut suggest_restrict = |span| { 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 d6b9b9df6b83f..34b41b8d9a252 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -202,7 +202,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &obligation.cause.code, &mut vec![], &mut Default::default(), - None, ); err.emit(); @@ -233,7 +232,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) { let tcx = self.tcx; let span = obligation.cause.span; - let mut obligation_note = None; let mut err = match *error { SelectionError::Unimplemented => { @@ -261,7 +259,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let bound_predicate = obligation.predicate.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(trait_predicate, _, implicit) => { + ty::PredicateKind::Trait(trait_predicate, _, _) => { let trait_predicate = bound_predicate.rebind(trait_predicate); let trait_predicate = self.resolve_vars_if_possible(trait_predicate); @@ -313,61 +311,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { post_message, )) ); - if let ty::ImplicitTraitPredicate::Yes = implicit { - if let ObligationCauseCode::BindingObligation(item_def_id, _) = - obligation.cause.code.peel_derives() - { - match self.tcx.hir().get_if_local(*item_def_id) { - Some(hir::Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Type(bounds, ty), - ident, - .. - })) => { - obligation_note = Some( - "associated types introduce an implicit `Sized` \ - obligation", - ); - match (bounds, ty) { - ([], None) => { - err.span_suggestion_verbose( - ident.span.shrink_to_hi(), - "consider relaxing the `Sized` obligation", - ": ?Sized".to_string(), - Applicability::MaybeIncorrect, - ); - } - ([.., bound], None) => { - err.span_suggestion_verbose( - bound.span().shrink_to_hi(), - "consider relaxing the `Sized` obligation", - " + ?Sized".to_string(), - Applicability::MaybeIncorrect, - ); - } - _ => {} - } - } - Some(hir::Node::ImplItem(hir::ImplItem { - kind: hir::ImplItemKind::TyAlias(_), - .. - })) => { - obligation_note = Some( - "associated types on `impl` blocks for types, have an \ - implicit mandatory `Sized` obligation; associated \ - types from `trait`s can be relaxed to `?Sized`", - ); - } - _ => { - // This is (likely?) a type parameter. The suggestion is handled - // in `rustc_middle/src/ty/diagnostics.rs`. - obligation_note = Some( - "type parameters introduce an implicit `Sized` \ - obligation", - ); - } - } - } - } if is_try_conversion { let none_error = self @@ -425,7 +368,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { points_at_arg, have_alt_message, ) { - self.note_obligation_cause(&mut err, obligation, obligation_note); + self.note_obligation_cause(&mut err, obligation); err.emit(); return; } @@ -854,7 +797,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } }; - self.note_obligation_cause(&mut err, obligation, obligation_note); + self.note_obligation_cause(&mut err, obligation); self.point_at_returns_when_relevant(&mut err, &obligation); err.emit(); @@ -1137,7 +1080,6 @@ trait InferCtxtPrivExt<'tcx> { &self, err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, - note: Option<&str>, ); fn suggest_unsized_bound_if_applicable( @@ -1287,6 +1229,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { obligation.cause.code.peel_derives(), ObligationCauseCode::ItemObligation(_) | ObligationCauseCode::BindingObligation(_, _) + | ObligationCauseCode::ImplicitSizedObligation(_, _) | ObligationCauseCode::ObjectCastObligation(_) | ObligationCauseCode::OpaqueType ); @@ -1358,7 +1301,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { _ => None, }; self.note_type_err(&mut diag, &obligation.cause, secondary_span, values, err, true); - self.note_obligation_cause(&mut diag, obligation, None); + self.note_obligation_cause(&mut diag, obligation); diag.emit(); } }); @@ -1651,7 +1594,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id()); } else if let ( Ok(ref snippet), - ObligationCauseCode::BindingObligation(ref def_id, _), + ObligationCauseCode::BindingObligation(ref def_id, _) + | ObligationCauseCode::ImplicitSizedObligation(ref def_id, _), ) = (self.tcx.sess.source_map().span_to_snippet(span), &obligation.cause.code) { @@ -1767,7 +1711,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { err } }; - self.note_obligation_cause(&mut err, obligation, None); + self.note_obligation_cause(&mut err, obligation); err.emit(); } @@ -1831,7 +1775,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { &self, err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, - note: Option<&str>, ) { // First, attempt to add note to this error with an async-await-specific // message, and fall back to regular note otherwise. @@ -1842,7 +1785,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { &obligation.cause.code, &mut vec![], &mut Default::default(), - note, ); self.suggest_unsized_bound_if_applicable(err, obligation); } @@ -1858,7 +1800,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { { ( ty::PredicateKind::Trait(pred, _, _), - &ObligationCauseCode::BindingObligation(item_def_id, span), + &ObligationCauseCode::BindingObligation(item_def_id, span) + | &ObligationCauseCode::ImplicitSizedObligation(item_def_id, span), ) => (pred, item_def_id, span), _ => return, }; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index 0ca0245a203d1..04478d60e7c47 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -142,7 +142,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } if let ObligationCauseCode::ItemObligation(item) - | ObligationCauseCode::BindingObligation(item, _) = obligation.cause.code + | ObligationCauseCode::BindingObligation(item, _) + | ObligationCauseCode::ImplicitSizedObligation(item, _) = obligation.cause.code { // FIXME: maybe also have some way of handling methods // from other traits? That would require name resolution, 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 51e72c1161901..4944301990ecd 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -162,7 +162,6 @@ pub trait InferCtxtExt<'tcx> { cause_code: &ObligationCauseCode<'tcx>, obligated_types: &mut Vec<&ty::TyS<'tcx>>, seen_requirements: &mut FxHashSet, - note: Option<&str>, ) where T: fmt::Display; @@ -791,8 +790,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } else { return try_borrowing(new_mut_trait_ref, expected_trait_ref, true, &[]); } - } else if let ObligationCauseCode::BindingObligation(_, _) - | ObligationCauseCode::ItemObligation(_) = &obligation.cause.code + } else if let ObligationCauseCode::BindingObligation(..) + | ObligationCauseCode::ItemObligation(_) + | ObligationCauseCode::ImplicitSizedObligation(..) = &obligation.cause.code { if try_borrowing( ty::TraitRef::new(trait_ref.def_id, imm_substs), @@ -1873,7 +1873,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { next_code.unwrap(), &mut Vec::new(), &mut Default::default(), - None, ); } @@ -1884,7 +1883,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { cause_code: &ObligationCauseCode<'tcx>, obligated_types: &mut Vec<&ty::TyS<'tcx>>, seen_requirements: &mut FxHashSet, - note: Option<&str>, ) where T: fmt::Display, { @@ -1934,6 +1932,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err.note(&msg); } } + ObligationCauseCode::ImplicitSizedObligation(item_def_id, span) => { + let item_name = tcx.def_path_str(item_def_id); + let mut sp: MultiSpan = span.into(); + sp.push_span_label(span, format!("required by this bound in `{}`", item_name)); + err.span_note(sp, "type parameters have an implicit `Sized` obligation"); + } ObligationCauseCode::BindingObligation(item_def_id, span) => { let item_name = tcx.def_path_str(item_def_id); let msg = format!("required by this bound in `{}`", item_name); @@ -1949,13 +1953,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } } if span != DUMMY_SP { - if let Some(note) = note { - let mut sp: MultiSpan = span.into(); - sp.push_span_label(span, msg); - err.span_note(sp, note); - } else { err.span_label(span, &msg); - } } else { err.note(&msg); } @@ -2157,7 +2155,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &data.parent_code, obligated_types, seen_requirements, - note, ) }); } @@ -2228,7 +2225,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &data.parent_code, obligated_types, seen_requirements, - note, ) }); } @@ -2243,7 +2239,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &data.parent_code, obligated_types, seen_requirements, - note, ) }); } diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 145468c42efda..b1ec5f056accd 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -694,7 +694,13 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { iter::zip(iter::zip(predicates.predicates, predicates.spans), origins.into_iter().rev()) .map(|((pred, span), origin_def_id)| { - let cause = self.cause(traits::BindingObligation(origin_def_id, span)); + let code = match pred.kind().skip_binder() { + ty::PredicateKind::Trait(_, _, ty::ImplicitTraitPredicate::Yes) => { + traits::ImplicitSizedObligation(origin_def_id, span) + } + _ => traits::BindingObligation(origin_def_id, span), + }; + let cause = self.cause(code); traits::Obligation::with_depth(cause, self.recursion_depth, self.param_env, pred) }) .filter(|pred| !pred.has_escaping_bound_vars()) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index c38fd79740c58..37150fbd7491b 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -1556,7 +1556,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { // This makes the error point at the bound, but we want to point at the argument if let Some(span) = spans.get(i) { - obligation.cause.make_mut().code = traits::BindingObligation(def_id, *span); + let code = match obligation.predicate.kind().skip_binder() { + ty::PredicateKind::Trait(_, _, ty::ImplicitTraitPredicate::Yes) => { + traits::ImplicitSizedObligation(def_id, *span) + } + _ => ObligationCauseCode::BindingObligation(def_id, *span), + }; + obligation.cause.make_mut().code = code; } self.register_predicate(obligation); } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index a7177274c33f3..6b0748705748b 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -2134,7 +2134,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP let constness = match modifier { hir::TraitBoundModifier::MaybeConst => hir::Constness::NotConst, hir::TraitBoundModifier::None => constness, - hir::TraitBoundModifier::Maybe => bug!("this wasn't handled"), + // We ignore `where T: ?Sized`, it is already part of + // type parameter `T`. + hir::TraitBoundModifier::Maybe => continue, }; let mut bounds = Bounds::default(); diff --git a/src/test/ui/associated-types/defaults-wf.stderr b/src/test/ui/associated-types/defaults-wf.stderr index 4a0ddb33ba9d8..5ae9320866ce7 100644 --- a/src/test/ui/associated-types/defaults-wf.stderr +++ b/src/test/ui/associated-types/defaults-wf.stderr @@ -5,7 +5,7 @@ LL | type Ty = Vec<[u8]>; | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | LL | pub struct Vec { diff --git a/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr b/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr index d43c9d387fcd8..dbf417eded995 100644 --- a/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr +++ b/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr @@ -4,7 +4,7 @@ error[E0277]: the size for values of type `Self` cannot be known at compilation LL | trait ArithmeticOps: Add + Sub + Mul + Div {} | ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/core/src/ops/arith.rs:LL:COL | LL | pub trait Add { diff --git a/src/test/ui/const-generics/const-argument-if-length.full.stderr b/src/test/ui/const-generics/const-argument-if-length.full.stderr index c6088e665a232..a9f1d0eb65718 100644 --- a/src/test/ui/const-generics/const-argument-if-length.full.stderr +++ b/src/test/ui/const-generics/const-argument-if-length.full.stderr @@ -10,6 +10,11 @@ LL | if std::mem::size_of::() == 0 { | LL | pub const fn size_of() -> usize { | - required by this bound in `std::mem::size_of` + | +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | pub const fn is_zst() -> usize { + | -- error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/const-argument-if-length.rs:16:12 @@ -21,6 +26,10 @@ LL | value: T, | = note: only the last field of a struct may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | pub struct AtLeastByte { + | -- help: borrowed types always have a statically known size | LL | value: &T, diff --git a/src/test/ui/const-generics/const-argument-if-length.min.stderr b/src/test/ui/const-generics/const-argument-if-length.min.stderr index bc06e8d7fb123..173a14716635d 100644 --- a/src/test/ui/const-generics/const-argument-if-length.min.stderr +++ b/src/test/ui/const-generics/const-argument-if-length.min.stderr @@ -17,6 +17,10 @@ LL | value: T, | = note: only the last field of a struct may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | pub struct AtLeastByte { + | -- help: borrowed types always have a statically known size | LL | value: &T, 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 2d12265df98ed..6c57dd9316fbd 100644 --- a/src/test/ui/dst/dst-object-from-unsized-type.stderr +++ b/src/test/ui/dst/dst-object-from-unsized-type.stderr @@ -7,6 +7,10 @@ LL | let u: &dyn Foo = t; | ^ doesn't have a size known at compile-time | = 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) { + | -- error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/dst-object-from-unsized-type.rs:13:23 @@ -17,6 +21,10 @@ LL | let v: &dyn Foo = t as &dyn Foo; | ^ doesn't have a size known at compile-time | = 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) { + | -- error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/dst-object-from-unsized-type.rs:18:28 diff --git a/src/test/ui/dst/dst-sized-trait-param.stderr b/src/test/ui/dst/dst-sized-trait-param.stderr index 80b2c7e57ba40..566a7c3ba94da 100644 --- a/src/test/ui/dst/dst-sized-trait-param.stderr +++ b/src/test/ui/dst/dst-sized-trait-param.stderr @@ -5,7 +5,7 @@ LL | impl Foo<[isize]> for usize { } | ^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[isize]` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/dst-sized-trait-param.rs:5:11 | LL | trait Foo : Sized { fn take(self, x: &T) { } } // Note: T is sized diff --git a/src/test/ui/extern/extern-types-unsized.stderr b/src/test/ui/extern/extern-types-unsized.stderr index 848ad6f6605d4..b4d10add6719d 100644 --- a/src/test/ui/extern/extern-types-unsized.stderr +++ b/src/test/ui/extern/extern-types-unsized.stderr @@ -5,7 +5,7 @@ LL | assert_sized::(); | ^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `A` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/extern-types-unsized.rs:19:17 | LL | fn assert_sized() {} @@ -27,7 +27,7 @@ note: required because it appears within the type `Foo` | LL | struct Foo { | ^^^ -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/extern-types-unsized.rs:19:17 | LL | fn assert_sized() {} @@ -49,7 +49,7 @@ note: required because it appears within the type `Bar` | LL | struct Bar { | ^^^ -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/extern-types-unsized.rs:19:17 | LL | fn assert_sized() {} @@ -76,7 +76,7 @@ note: required because it appears within the type `Bar>` | LL | struct Bar { | ^^^ -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/extern-types-unsized.rs:19:17 | LL | fn assert_sized() {} diff --git a/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr b/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr index d27e46f6836df..c326e40a77bbe 100644 --- a/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr +++ b/src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr @@ -10,11 +10,14 @@ LL | #![feature(generic_associated_types)] error[E0275]: overflow evaluating the requirement `::Item: Sized` --> $DIR/projection-bound-cycle-generic.rs:45:5 | -LL | struct OnlySized where T: Sized { f: T } - | - required by this bound in `OnlySized` -... LL | type Assoc = OnlySized<::Item>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/projection-bound-cycle-generic.rs:29:18 + | +LL | struct OnlySized where T: Sized { f: T } + | ^ required by this bound in `OnlySized` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/generic-associated-types/projection-bound-cycle.stderr b/src/test/ui/generic-associated-types/projection-bound-cycle.stderr index 400b664f97ca9..a19e679930dc4 100644 --- a/src/test/ui/generic-associated-types/projection-bound-cycle.stderr +++ b/src/test/ui/generic-associated-types/projection-bound-cycle.stderr @@ -10,11 +10,14 @@ LL | #![feature(generic_associated_types)] error[E0275]: overflow evaluating the requirement `::Item: Sized` --> $DIR/projection-bound-cycle.rs:47:5 | -LL | struct OnlySized where T: Sized { f: T } - | - required by this bound in `OnlySized` -... LL | type Assoc = OnlySized<::Item>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/projection-bound-cycle.rs:31:18 + | +LL | struct OnlySized where T: Sized { f: T } + | ^ required by this bound in `OnlySized` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr index 418bb9487f8b2..96d1e535d0ab6 100644 --- a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr +++ b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr @@ -5,7 +5,7 @@ LL | impl Tsized for () {} | ^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[()]` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:17:14 | LL | trait Tsized {} diff --git a/src/test/ui/issues/issue-10412.stderr b/src/test/ui/issues/issue-10412.stderr index 3f96fce8687f8..148096fbecdc1 100644 --- a/src/test/ui/issues/issue-10412.stderr +++ b/src/test/ui/issues/issue-10412.stderr @@ -53,7 +53,7 @@ LL | impl<'self> Serializable for &'self str { | ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/issue-10412.rs:1:27 | LL | trait Serializable<'self, T> { diff --git a/src/test/ui/issues/issue-18919.stderr b/src/test/ui/issues/issue-18919.stderr index 1ee899f96a863..11342e26948c5 100644 --- a/src/test/ui/issues/issue-18919.stderr +++ b/src/test/ui/issues/issue-18919.stderr @@ -5,7 +5,7 @@ LL | fn ho_func(f: Option) { | ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `dyn for<'r> Fn(&'r isize) -> isize` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/issue-18919.rs:7:13 | LL | enum Option { diff --git a/src/test/ui/issues/issue-20433.stderr b/src/test/ui/issues/issue-20433.stderr index e2080057cc398..5a28f0233a15f 100644 --- a/src/test/ui/issues/issue-20433.stderr +++ b/src/test/ui/issues/issue-20433.stderr @@ -5,7 +5,7 @@ LL | fn iceman(c: Vec<[i32]>) {} | ^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[i32]` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | LL | pub struct Vec { diff --git a/src/test/ui/issues/issue-23281.stderr b/src/test/ui/issues/issue-23281.stderr index 46a1a08a92ebc..69f687df68238 100644 --- a/src/test/ui/issues/issue-23281.stderr +++ b/src/test/ui/issues/issue-23281.stderr @@ -5,7 +5,7 @@ LL | pub fn function(funs: Vec ()>) {} | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `(dyn Fn() + 'static)` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/issue-23281.rs:8:12 | LL | struct Vec { diff --git a/src/test/ui/issues/issue-27060-2.stderr b/src/test/ui/issues/issue-27060-2.stderr index 5dbcc96e87488..64e061a89b410 100644 --- a/src/test/ui/issues/issue-27060-2.stderr +++ b/src/test/ui/issues/issue-27060-2.stderr @@ -8,6 +8,10 @@ LL | data: T, | = note: the last field of a packed struct may only have a dynamically sized type if it does not need drop to be run = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | pub struct Bad { + | -- help: borrowed types always have a statically known size | LL | data: &T, diff --git a/src/test/ui/issues/issue-60283.stderr b/src/test/ui/issues/issue-60283.stderr index 2648cd2e17bf3..51a8618d1dca2 100644 --- a/src/test/ui/issues/issue-60283.stderr +++ b/src/test/ui/issues/issue-60283.stderr @@ -20,7 +20,7 @@ LL | foo((), drop) | ^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `<() as Trait<'_>>::Item` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | LL | pub fn drop(_x: T) {} diff --git a/src/test/ui/mir/issue-80742.stderr b/src/test/ui/mir/issue-80742.stderr index b4c4d2208af75..59c376b5d7614 100644 --- a/src/test/ui/mir/issue-80742.stderr +++ b/src/test/ui/mir/issue-80742.stderr @@ -56,7 +56,7 @@ LL | let dst = Inline::::new(0); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `dyn Debug` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/issue-80742.rs:13:15 | LL | struct Inline diff --git a/src/test/ui/range/range-1.stderr b/src/test/ui/range/range-1.stderr index 0ebee0b6e5252..758e5424efe89 100644 --- a/src/test/ui/range/range-1.stderr +++ b/src/test/ui/range/range-1.stderr @@ -21,7 +21,7 @@ LL | let range = *arr..; | ^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[{integer}]` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/core/src/ops/range.rs:LL:COL | LL | pub struct RangeFrom { diff --git a/src/test/ui/str/str-mut-idx.stderr b/src/test/ui/str/str-mut-idx.stderr index 405542820a394..9297e1d55f542 100644 --- a/src/test/ui/str/str-mut-idx.stderr +++ b/src/test/ui/str/str-mut-idx.stderr @@ -1,13 +1,15 @@ error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/str-mut-idx.rs:4:15 | -LL | fn bot() -> T { loop {} } - | - required by this bound in `bot` -... LL | s[1..2] = bot(); | ^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` +note: type parameters have an implicit `Sized` obligation + --> $DIR/str-mut-idx.rs:1:8 + | +LL | fn bot() -> T { loop {} } + | ^ required by this bound in `bot` help: consider relaxing the implicit `Sized` restriction | LL | fn bot() -> T { loop {} } diff --git a/src/test/ui/substs-ppaux.normal.stderr b/src/test/ui/substs-ppaux.normal.stderr index 2eb49fc853e86..5bbf4225812b6 100644 --- a/src/test/ui/substs-ppaux.normal.stderr +++ b/src/test/ui/substs-ppaux.normal.stderr @@ -73,6 +73,9 @@ LL | let x: () = foo::<'static>(); error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/substs-ppaux.rs:49:5 | +LL | fn bar<'a, T>() where T: 'a {} + | -- required by this bound in `Foo::bar` +... LL | >::bar; | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | @@ -82,11 +85,6 @@ note: required because of the requirements on the impl of `Foo<'_, '_, u8>` for | LL | impl<'a,'b,T,S> Foo<'a, 'b, S> for T {} | ^^^^^^^^^^^^^^ ^ -note: type parameters introduce an implicit `Sized` obligation - --> $DIR/substs-ppaux.rs:7:30 - | -LL | fn bar<'a, T>() where T: 'a {} - | ^^ required by this bound in `Foo::bar` error: aborting due to 5 previous errors diff --git a/src/test/ui/substs-ppaux.verbose.stderr b/src/test/ui/substs-ppaux.verbose.stderr index 1e24247ee4ae5..20d7655337448 100644 --- a/src/test/ui/substs-ppaux.verbose.stderr +++ b/src/test/ui/substs-ppaux.verbose.stderr @@ -73,6 +73,9 @@ LL | let x: () = foo::<'static>(); error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/substs-ppaux.rs:49:5 | +LL | fn bar<'a, T>() where T: 'a {} + | -- required by this bound in `Foo::bar` +... LL | >::bar; | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | @@ -82,11 +85,6 @@ note: required because of the requirements on the impl of `Foo<'_#0r, '_#1r, u8> | LL | impl<'a,'b,T,S> Foo<'a, 'b, S> for T {} | ^^^^^^^^^^^^^^ ^ -note: type parameters introduce an implicit `Sized` obligation - --> $DIR/substs-ppaux.rs:7:30 - | -LL | fn bar<'a, T>() where T: 'a {} - | ^^ required by this bound in `Foo::bar` error: aborting due to 5 previous errors diff --git a/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr b/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr index 849c27cb56da2..7d7e4bed89cdf 100644 --- a/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr +++ b/src/test/ui/suggestions/adt-param-with-implicit-sized-bound.stderr @@ -6,7 +6,7 @@ LL | struct Struct5{ LL | _t: X, | ^^^^ doesn't have a size known at compile-time | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/adt-param-with-implicit-sized-bound.rs:18:10 | LL | struct X(T); @@ -18,6 +18,10 @@ LL | struct X(T); | ^ - ...if indirection were used here: `Box` | | | this could be changed to `T: ?Sized`... +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | struct Struct5{ + | -- error[E0277]: the size for values of type `Self` cannot be known at compilation time --> $DIR/adt-param-with-implicit-sized-bound.rs:2:19 diff --git a/src/test/ui/suggestions/issue-84973-blacklist.stderr b/src/test/ui/suggestions/issue-84973-blacklist.stderr index 1328f7b7e84c2..21b568f1f9292 100644 --- a/src/test/ui/suggestions/issue-84973-blacklist.stderr +++ b/src/test/ui/suggestions/issue-84973-blacklist.stderr @@ -34,7 +34,7 @@ LL | f_sized(*ref_cl); | ^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `dyn Fn()` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/issue-84973-blacklist.rs:9:12 | LL | fn f_sized(t: T) {} diff --git a/src/test/ui/trait-bounds/unsized-bound.rs b/src/test/ui/trait-bounds/unsized-bound.rs new file mode 100644 index 0000000000000..035b8ef1bdebc --- /dev/null +++ b/src/test/ui/trait-bounds/unsized-bound.rs @@ -0,0 +1,32 @@ +trait Trait {} +impl Trait<(A, B)> for (A, B) where A: ?Sized, B: ?Sized, {} +//~^ ERROR E0277 +//~| ERROR E0277 +impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} +//~^ ERROR E0277 +//~| ERROR E0277 +//~| ERROR E0277 +trait Trait2 {} +impl Trait2<(A, B)> for (A, B) {} +//~^ ERROR E0277 +//~| ERROR E0277 +trait Trait3 {} +impl Trait3 for A where A: ?Sized {} +//~^ ERROR E0277 +trait Trait4 {} +impl Trait4 for A {} +//~^ ERROR E0277 +trait Trait5 {} +impl Trait5 for X where X: ?Sized {} +//~^ ERROR E0277 +trait Trait6 {} +impl Trait6 for X {} +//~^ ERROR E0277 +trait Trait7 {} +impl Trait7 for X where Y: ?Sized {} +//~^ ERROR E0277 +trait Trait8 {} +impl Trait8 for X {} +//~^ ERROR E0277 + +fn main() {} diff --git a/src/test/ui/trait-bounds/unsized-bound.stderr b/src/test/ui/trait-bounds/unsized-bound.stderr new file mode 100644 index 0000000000000..dae66b56043c5 --- /dev/null +++ b/src/test/ui/trait-bounds/unsized-bound.stderr @@ -0,0 +1,254 @@ +error[E0277]: the size for values of type `B` cannot be known at compilation time + --> $DIR/unsized-bound.rs:2:12 + | +LL | impl Trait<(A, B)> for (A, B) where A: ?Sized, B: ?Sized, {} + | - ^^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: required because it appears within the type `(A, B)` +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:1:13 + | +LL | trait Trait {} + | ^ required by this bound in `Trait` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait<(A, B)> for (A, B) where A: ?Sized, {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `A` cannot be known at compilation time + --> $DIR/unsized-bound.rs:2:30 + | +LL | impl Trait<(A, B)> for (A, B) where A: ?Sized, B: ?Sized, {} + | - ^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait<(A, B)> for (A, B) where B: ?Sized, {} + | -- + +error[E0277]: the size for values of type `C` cannot be known at compilation time + --> $DIR/unsized-bound.rs:5:31 + | +LL | impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} + | - ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: required because it appears within the type `(A, B, C)` +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:1:13 + | +LL | trait Trait {} + | ^ required by this bound in `Trait` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `A` cannot be known at compilation time + --> $DIR/unsized-bound.rs:5:52 + | +LL | impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} + | - ^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait<(A, B, C)> for (A, B, C) {} + | -- + +error[E0277]: the size for values of type `B` cannot be known at compilation time + --> $DIR/unsized-bound.rs:5:52 + | +LL | impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} + | - ^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait<(A, B, C)> for (A, B, C) where A: ?Sized, {} + | -- + +error[E0277]: the size for values of type `B` cannot be known at compilation time + --> $DIR/unsized-bound.rs:10:28 + | +LL | impl Trait2<(A, B)> for (A, B) {} + | - ^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: required because it appears within the type `(A, B)` +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:9:14 + | +LL | trait Trait2 {} + | ^ required by this bound in `Trait2` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait2<(A, B)> for (A, B) {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait2 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `A` cannot be known at compilation time + --> $DIR/unsized-bound.rs:10:47 + | +LL | impl Trait2<(A, B)> for (A, B) {} + | - ^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | + = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait2<(A, B)> for (A, B) {} + | -- + +error[E0277]: the size for values of type `A` cannot be known at compilation time + --> $DIR/unsized-bound.rs:14:9 + | +LL | trait Trait3 {} + | - required by this bound in `Trait3` +LL | impl Trait3 for A where A: ?Sized {} + | - ^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait3 for A {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait3 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `A` cannot be known at compilation time + --> $DIR/unsized-bound.rs:17:17 + | +LL | trait Trait4 {} + | - required by this bound in `Trait4` +LL | impl Trait4 for A {} + | - ^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait4 for A {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait4 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized-bound.rs:20:12 + | +LL | impl Trait5 for X where X: ?Sized {} + | - ^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:19:14 + | +LL | trait Trait5 {} + | ^ required by this bound in `Trait5` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait5 for X {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait5 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `X` cannot be known at compilation time + --> $DIR/unsized-bound.rs:23:20 + | +LL | impl Trait6 for X {} + | - ^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:22:14 + | +LL | trait Trait6 {} + | ^ required by this bound in `Trait6` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait6 for X {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait6 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `Y` cannot be known at compilation time + --> $DIR/unsized-bound.rs:26:12 + | +LL | impl Trait7 for X where Y: ?Sized {} + | - ^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:25:17 + | +LL | trait Trait7 {} + | ^ required by this bound in `Trait7` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait7 for X {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait7 {} + | ^^^^^^^^ + +error[E0277]: the size for values of type `Y` cannot be known at compilation time + --> $DIR/unsized-bound.rs:29:20 + | +LL | impl Trait8 for X {} + | - ^^^^^^^^^^^^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `std::marker::Sized` + | +note: type parameters have an implicit `Sized` obligation + --> $DIR/unsized-bound.rs:28:17 + | +LL | trait Trait8 {} + | ^ required by this bound in `Trait8` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl Trait8 for X {} + | -- +help: consider relaxing the implicit `Sized` restriction + | +LL | trait Trait8 {} + | ^^^^^^^^ + +error: aborting due to 13 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/traits/bad-sized.stderr b/src/test/ui/traits/bad-sized.stderr index 492b7f2ad495a..b3937095f7770 100644 --- a/src/test/ui/traits/bad-sized.stderr +++ b/src/test/ui/traits/bad-sized.stderr @@ -16,7 +16,7 @@ LL | let x: Vec = Vec::new(); | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `dyn Trait` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | LL | pub struct Vec { @@ -38,7 +38,7 @@ LL | let x: Vec = Vec::new(); | ^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `dyn Trait` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | LL | pub struct Vec { diff --git a/src/test/ui/traits/issue-65673.stderr b/src/test/ui/traits/issue-65673.stderr index d03282d03d55d..6f9bb3edfe047 100644 --- a/src/test/ui/traits/issue-65673.stderr +++ b/src/test/ui/traits/issue-65673.stderr @@ -1,19 +1,13 @@ error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time --> $DIR/issue-65673.rs:9:16 | +LL | type Ctx; + | --------- required by this bound in `WithType::Ctx` +... LL | type Ctx = dyn Alias; | ^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `(dyn Trait + 'static)` -note: associated types introduce an implicit `Sized` obligation - --> $DIR/issue-65673.rs:4:5 - | -LL | type Ctx; - | ^^^^^^^^^ required by this bound in `WithType::Ctx` -help: consider relaxing the `Sized` obligation - | -LL | type Ctx: ?Sized; - | ^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/traits/mutual-recursion-issue-75860.stderr b/src/test/ui/traits/mutual-recursion-issue-75860.stderr index cf867ef78c3b1..484d5f814a100 100644 --- a/src/test/ui/traits/mutual-recursion-issue-75860.stderr +++ b/src/test/ui/traits/mutual-recursion-issue-75860.stderr @@ -3,13 +3,13 @@ error[E0275]: overflow evaluating the requirement `Option<_>: Sized` | LL | iso(left, right) | ^^^ - | - ::: $SRC_DIR/core/src/option.rs:LL:COL - | -LL | pub enum Option { - | - required by this bound in `Option` | = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`mutual_recursion_issue_75860`) +note: type parameters have an implicit `Sized` obligation + --> $SRC_DIR/core/src/option.rs:LL:COL + | +LL | pub enum Option { + | ^ required by this bound in `Option` error: aborting due to previous error diff --git a/src/test/ui/traits/suggest-where-clause.stderr b/src/test/ui/traits/suggest-where-clause.stderr index f95ebb5ef4987..79748c3c2d349 100644 --- a/src/test/ui/traits/suggest-where-clause.stderr +++ b/src/test/ui/traits/suggest-where-clause.stderr @@ -7,11 +7,15 @@ LL | // suggest a where-clause, if needed LL | mem::size_of::(); | ^ doesn't have a size known at compile-time | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | LL | pub const fn size_of() -> usize { | ^ required by this bound in `std::mem::size_of` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn check() { + | -- error[E0277]: the size for values of type `U` cannot be known at compilation time --> $DIR/suggest-where-clause.rs:10:5 @@ -27,11 +31,15 @@ note: required because it appears within the type `Misc` | LL | struct Misc(T); | ^^^^ -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | LL | pub const fn size_of() -> usize { | ^ required by this bound in `std::mem::size_of` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn check() { + | -- error[E0277]: the trait bound `u64: From` is not satisfied --> $DIR/suggest-where-clause.rs:15:5 @@ -72,7 +80,7 @@ LL | mem::size_of::<[T]>(); | ^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[T]` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | LL | pub const fn size_of() -> usize { @@ -85,7 +93,7 @@ LL | mem::size_of::<[&U]>(); | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[&U]` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/core/src/mem/mod.rs:LL:COL | LL | pub const fn size_of() -> usize { diff --git a/src/test/ui/union/union-sized-field.stderr b/src/test/ui/union/union-sized-field.stderr index b916bbe8ad10a..ef86c624e9b19 100644 --- a/src/test/ui/union/union-sized-field.stderr +++ b/src/test/ui/union/union-sized-field.stderr @@ -8,6 +8,10 @@ LL | value: T, | = note: no field of a union may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | union Foo { + | -- help: borrowed types always have a statically known size | LL | value: &T, @@ -27,6 +31,10 @@ LL | value: T, | = note: only the last field of a struct may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | struct Foo2 { + | -- help: borrowed types always have a statically known size | LL | value: &T, @@ -46,6 +54,10 @@ LL | Value(T), | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum Foo3 { + | -- help: borrowed types always have a statically known size | LL | Value(&T), diff --git a/src/test/ui/unsized/unsized-bare-typaram.stderr b/src/test/ui/unsized/unsized-bare-typaram.stderr index 0722b6fb834e6..800194737ed3f 100644 --- a/src/test/ui/unsized/unsized-bare-typaram.stderr +++ b/src/test/ui/unsized/unsized-bare-typaram.stderr @@ -6,11 +6,15 @@ LL | fn foo() { bar::() } | | | this type parameter needs to be `std::marker::Sized` | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/unsized-bare-typaram.rs:1:8 | LL | fn bar() { } | ^ required by this bound in `bar` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn foo() { bar::() } + | -- error: aborting due to previous error diff --git a/src/test/ui/unsized/unsized-enum.stderr b/src/test/ui/unsized/unsized-enum.stderr index 1ac8d9094eb84..d67459eaf980b 100644 --- a/src/test/ui/unsized/unsized-enum.stderr +++ b/src/test/ui/unsized/unsized-enum.stderr @@ -6,7 +6,7 @@ LL | fn foo2() { not_sized::>() } | | | this type parameter needs to be `std::marker::Sized` | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/unsized-enum.rs:4:10 | LL | enum Foo { FooSome(U), FooNone } @@ -18,6 +18,10 @@ LL | enum Foo { FooSome(U), FooNone } | ^ - ...if indirection were used here: `Box` | | | this could be changed to `U: ?Sized`... +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn foo2() { not_sized::>() } + | -- error: aborting due to previous error diff --git a/src/test/ui/unsized/unsized-enum2.stderr b/src/test/ui/unsized/unsized-enum2.stderr index 1b6c85858159d..b9a03d904af4d 100644 --- a/src/test/ui/unsized/unsized-enum2.stderr +++ b/src/test/ui/unsized/unsized-enum2.stderr @@ -9,6 +9,10 @@ LL | VA(W), | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum E { + | -- help: borrowed types always have a statically known size | LL | VA(&W), @@ -29,6 +33,10 @@ LL | VB{x: X}, | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum E { + | -- help: borrowed types always have a statically known size | LL | VB{x: &X}, @@ -49,6 +57,10 @@ LL | VC(isize, Y), | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum E { + | -- help: borrowed types always have a statically known size | LL | VC(isize, &Y), @@ -69,6 +81,10 @@ LL | VD{u: isize, x: Z}, | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum E { + | -- help: borrowed types always have a statically known size | LL | VD{u: isize, x: &Z}, diff --git a/src/test/ui/unsized/unsized-fn-arg.fixed b/src/test/ui/unsized/unsized-fn-arg.fixed index 2c686c6c2b271..fd9b159a48138 100644 --- a/src/test/ui/unsized/unsized-fn-arg.fixed +++ b/src/test/ui/unsized/unsized-fn-arg.fixed @@ -2,5 +2,5 @@ #![crate_type="lib"] #![allow(unused)] -fn f(t: &T) {} +fn f(t: &T) {} //~^ ERROR the size for values of type `T` cannot be known at compilation time diff --git a/src/test/ui/unsized/unsized-fn-arg.stderr b/src/test/ui/unsized/unsized-fn-arg.stderr index 6b802ddf542d5..acb8a598d2c8a 100644 --- a/src/test/ui/unsized/unsized-fn-arg.stderr +++ b/src/test/ui/unsized/unsized-fn-arg.stderr @@ -7,6 +7,10 @@ LL | fn f(t: T) {} | this type parameter needs to be `std::marker::Sized` | = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f(t: T) {} + | -- help: function arguments must have a statically known size, borrowed types always have a known size | LL | fn f(t: &T) {} diff --git a/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr b/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr index deaec463be323..42bc4c434911f 100644 --- a/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr +++ b/src/test/ui/unsized/unsized-inherent-impl-self-type.stderr @@ -6,7 +6,7 @@ LL | impl S5 { | | | this type parameter needs to be `std::marker::Sized` | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/unsized-inherent-impl-self-type.rs:5:11 | LL | struct S5(Y); @@ -18,6 +18,10 @@ LL | struct S5(Y); | ^ - ...if indirection were used here: `Box` | | | this could be changed to `Y: ?Sized`... +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl S5 { + | -- error: aborting due to previous error diff --git a/src/test/ui/unsized/unsized-struct.stderr b/src/test/ui/unsized/unsized-struct.stderr index 1d5ca414a6810..a5c0184143409 100644 --- a/src/test/ui/unsized/unsized-struct.stderr +++ b/src/test/ui/unsized/unsized-struct.stderr @@ -6,7 +6,7 @@ LL | fn foo2() { not_sized::>() } | | | this type parameter needs to be `std::marker::Sized` | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/unsized-struct.rs:4:12 | LL | struct Foo { data: T } @@ -18,6 +18,10 @@ LL | struct Foo { data: T } | ^ - ...if indirection were used here: `Box` | | | this could be changed to `T: ?Sized`... +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn foo2() { not_sized::>() } + | -- error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/unsized-struct.rs:13:24 @@ -32,11 +36,15 @@ note: required because it appears within the type `Bar` | LL | struct Bar { data: T } | ^^^ -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/unsized-struct.rs:1:13 | LL | fn is_sized() { } | ^ required by this bound in `is_sized` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn bar2() { is_sized::>() } + | -- error: aborting due to 2 previous errors diff --git a/src/test/ui/unsized/unsized-trait-impl-self-type.stderr b/src/test/ui/unsized/unsized-trait-impl-self-type.stderr index f7153507a1af3..4d2f0c0c1487b 100644 --- a/src/test/ui/unsized/unsized-trait-impl-self-type.stderr +++ b/src/test/ui/unsized/unsized-trait-impl-self-type.stderr @@ -6,7 +6,7 @@ LL | impl T3 for S5 { | | | this type parameter needs to be `std::marker::Sized` | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/unsized-trait-impl-self-type.rs:8:11 | LL | struct S5(Y); @@ -18,6 +18,10 @@ LL | struct S5(Y); | ^ - ...if indirection were used here: `Box` | | | this could be changed to `Y: ?Sized`... +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl T3 for S5 { + | -- error: aborting due to previous error diff --git a/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr b/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr index bfa51995227fe..5f792be56222a 100644 --- a/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr +++ b/src/test/ui/unsized/unsized-trait-impl-trait-arg.stderr @@ -6,11 +6,15 @@ LL | impl T2 for S4 { | | | this type parameter needs to be `std::marker::Sized` | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/unsized-trait-impl-trait-arg.rs:4:10 | LL | trait T2 { | ^ required by this bound in `T2` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl T2 for S4 { + | -- help: consider relaxing the implicit `Sized` restriction | LL | trait T2 { diff --git a/src/test/ui/unsized/unsized3.stderr b/src/test/ui/unsized/unsized3.stderr index ffdcd0b6a371b..fd64ca1b1aab1 100644 --- a/src/test/ui/unsized/unsized3.stderr +++ b/src/test/ui/unsized/unsized3.stderr @@ -6,11 +6,15 @@ LL | fn f1(x: &X) { LL | f2::(x); | ^ doesn't have a size known at compile-time | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/unsized3.rs:10:7 | LL | fn f2(x: &X) { | ^ required by this bound in `f2` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f1(x: &X) { + | -- help: consider relaxing the implicit `Sized` restriction | LL | fn f2(x: &X) { @@ -24,11 +28,15 @@ LL | fn f3(x: &X) { LL | f4::(x); | ^ doesn't have a size known at compile-time | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/unsized3.rs:21:7 | LL | fn f4(x: &X) { | ^ required by this bound in `f4` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f3(x: &X) { + | -- help: consider relaxing the implicit `Sized` restriction | LL | fn f4(x: &X) { @@ -47,11 +55,15 @@ note: required because it appears within the type `S` | LL | struct S { | ^ -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/unsized3.rs:24:7 | LL | fn f5(x: &Y) {} | ^ required by this bound in `f5` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f8(x1: &S, x2: &S) { + | -- help: consider relaxing the implicit `Sized` restriction | LL | fn f5(x: &Y) {} @@ -71,6 +83,10 @@ note: required because it appears within the type `S` LL | struct S { | ^ = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f9(x1: Box>) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized3.rs:45:9 @@ -87,10 +103,17 @@ LL | struct S { | ^ = note: required because it appears within the type `({integer}, S)` = note: tuples must have a statically known size to be initialized +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f10(x1: Box>) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized3.rs:45:8 | +LL | fn f5(x: &Y) {} + | - required by this bound in `f5` +... LL | fn f10(x1: Box>) { | - this type parameter needs to be `std::marker::Sized` LL | f5(&(32, *x1)); @@ -102,11 +125,10 @@ note: required because it appears within the type `S` LL | struct S { | ^ = note: required because it appears within the type `({integer}, S)` -note: type parameters introduce an implicit `Sized` obligation - --> $DIR/unsized3.rs:24:7 +help: consider removing the `?Sized` bound to make the type parameter `Sized` | -LL | fn f5(x: &Y) {} - | ^ required by this bound in `f5` +LL | fn f10(x1: Box>) { + | -- help: consider relaxing the implicit `Sized` restriction | LL | fn f5(x: &Y) {} diff --git a/src/test/ui/unsized/unsized5.stderr b/src/test/ui/unsized/unsized5.stderr index 0bfd4565529aa..6e5b355642932 100644 --- a/src/test/ui/unsized/unsized5.stderr +++ b/src/test/ui/unsized/unsized5.stderr @@ -8,6 +8,10 @@ LL | f1: X, | = note: only the last field of a struct may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | struct S1 { + | -- help: borrowed types always have a statically known size | LL | f1: &X, @@ -28,6 +32,10 @@ LL | g: X, | = note: only the last field of a struct may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | struct S2 { + | -- help: borrowed types always have a statically known size | LL | g: &X, @@ -83,6 +91,10 @@ LL | V1(X, isize), | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum E { + | -- help: borrowed types always have a statically known size | LL | V1(&X, isize), @@ -102,6 +114,10 @@ LL | V2{f1: X, f: isize}, | = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | enum F { + | -- help: borrowed types always have a statically known size | LL | V2{f1: &X, f: isize}, diff --git a/src/test/ui/unsized/unsized6.stderr b/src/test/ui/unsized/unsized6.stderr index 8e5734dffb145..5eff89d971fbb 100644 --- a/src/test/ui/unsized/unsized6.stderr +++ b/src/test/ui/unsized/unsized6.stderr @@ -9,6 +9,10 @@ LL | let y: Y; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f1(x: &X) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:7:12 @@ -20,6 +24,10 @@ LL | let _: (isize, (X, isize)); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f1(x: &X) { + | -- error[E0277]: the size for values of type `Z` cannot be known at compilation time --> $DIR/unsized6.rs:11:12 @@ -31,6 +39,10 @@ LL | let y: (isize, (Z, usize)); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f1(x: &X) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:15:9 @@ -42,6 +54,10 @@ LL | let y: X; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f2(x: &X) { + | -- error[E0277]: the size for values of type `Y` cannot be known at compilation time --> $DIR/unsized6.rs:17:12 @@ -53,6 +69,10 @@ LL | let y: (isize, (Y, isize)); | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = note: only the last element of a tuple may have a dynamically sized type +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f2(x: &X) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:22:9 @@ -64,6 +84,10 @@ LL | let y: X = *x1; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f3(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:24:9 @@ -76,6 +100,10 @@ LL | let y = *x2; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f3(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:26:10 @@ -88,6 +116,10 @@ LL | let (y, z) = (*x3, 4); | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f3(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:30:9 @@ -99,6 +131,10 @@ LL | let y: X = *x1; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f4(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:32:9 @@ -111,6 +147,10 @@ LL | let y = *x2; | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f4(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:34:10 @@ -123,6 +163,10 @@ LL | let (y, z) = (*x3, 4); | = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn f4(x1: Box, x2: Box, x3: Box) { + | -- error[E0277]: the size for values of type `X` cannot be known at compilation time --> $DIR/unsized6.rs:38:18 @@ -133,6 +177,10 @@ LL | fn g1(x: X) {} | this type parameter needs to be `std::marker::Sized` | = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn g1(x: X) {} + | -- help: function arguments must have a statically known size, borrowed types always have a known size | LL | fn g1(x: &X) {} @@ -147,6 +195,10 @@ LL | fn g2(x: X) {} | this type parameter needs to be `std::marker::Sized` | = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | fn g2(x: X) {} + | -- help: function arguments must have a statically known size, borrowed types always have a known size | LL | fn g2(x: &X) {} diff --git a/src/test/ui/unsized/unsized7.stderr b/src/test/ui/unsized/unsized7.stderr index 6a36161c039f4..0512e47d9f1a0 100644 --- a/src/test/ui/unsized/unsized7.stderr +++ b/src/test/ui/unsized/unsized7.stderr @@ -6,11 +6,15 @@ LL | impl T1 for S3 { | | | this type parameter needs to be `std::marker::Sized` | -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/unsized7.rs:7:10 | LL | trait T1 { | ^ required by this bound in `T1` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL | impl T1 for S3 { + | -- help: consider relaxing the implicit `Sized` restriction | LL | trait T1 { diff --git a/src/test/ui/wf/wf-fn-where-clause.stderr b/src/test/ui/wf/wf-fn-where-clause.stderr index 5c1fe444c9ab1..42a29dd5a6ee9 100644 --- a/src/test/ui/wf/wf-fn-where-clause.stderr +++ b/src/test/ui/wf/wf-fn-where-clause.stderr @@ -19,7 +19,7 @@ LL | fn bar() where Vec:, {} | ^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `(dyn Copy + 'static)` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $DIR/wf-fn-where-clause.rs:16:12 | LL | struct Vec { diff --git a/src/test/ui/wf/wf-impl-self-type.stderr b/src/test/ui/wf/wf-impl-self-type.stderr index 88a9ff2774197..fc31cd2cfe094 100644 --- a/src/test/ui/wf/wf-impl-self-type.stderr +++ b/src/test/ui/wf/wf-impl-self-type.stderr @@ -5,7 +5,7 @@ LL | impl Foo for Option<[u8]> {} | ^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[u8]` -note: type parameters introduce an implicit `Sized` obligation +note: type parameters have an implicit `Sized` obligation --> $SRC_DIR/core/src/option.rs:LL:COL | LL | pub enum Option { From 3956224f0c8ea4bcbe1c87d79471491c2f59a1cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 10 Jun 2021 19:59:31 -0700 Subject: [PATCH 11/11] Account for associated types in `Sized` bound error --- .../src/traits/error_reporting/suggestions.rs | 56 ++++++++++++++++++- .../rustc_typeck/src/check/compare_method.rs | 15 ++++- .../ui/associated-types/issue-63593.stderr | 14 +++-- .../issue-74816.stderr | 14 +++-- src/test/ui/traits/issue-65673.stderr | 12 +++- 5 files changed, 94 insertions(+), 17 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 4944301990ecd..106248abc40ba 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1935,8 +1935,58 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ObligationCauseCode::ImplicitSizedObligation(item_def_id, span) => { let item_name = tcx.def_path_str(item_def_id); let mut sp: MultiSpan = span.into(); - sp.push_span_label(span, format!("required by this bound in `{}`", item_name)); - err.span_note(sp, "type parameters have an implicit `Sized` obligation"); + match self.tcx.hir().get_if_local(item_def_id) { + Some(hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Type(bounds, _), + ident, + .. + })) => { + sp.push_span_label( + span, + format!("required by associated type `{}`", item_name), + ); + err.span_note(sp, "associated types have an implicit `Sized` obligation"); + + let sized_trait = self.tcx.lang_items().sized_trait(); + if bounds.len() == 0 { + err.span_suggestion_verbose( + ident.span.shrink_to_hi(), + "consider relaxing the `Sized` obligation", + ": ?Sized".to_string(), + Applicability::MaybeIncorrect, + ); + } else if bounds.iter().all(|bound| { + bound.trait_ref().and_then(|tr| tr.trait_def_id()) != sized_trait + }) { + err.span_suggestion_verbose( + bounds.iter().last().unwrap().span().shrink_to_hi(), + "consider relaxing the `Sized` obligation", + " + ?Sized".to_string(), + Applicability::MaybeIncorrect, + ); + } + } + Some(hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::TyAlias(_), + .. + })) => { + let msg = "associated types on `impl` blocks for types, have an implicit \ + mandatory `Sized` obligation; associated types from `trait`s can be \ + relaxed to `?Sized`"; + sp.push_span_label( + span, + format!("required by associated type `{}`", item_name), + ); + err.span_note(sp, msg); + } + _ => { + sp.push_span_label( + span, + format!("required by this bound in `{}`", item_name), + ); + err.span_note(sp, "type parameters have an implicit `Sized` obligation"); + } + } } ObligationCauseCode::BindingObligation(item_def_id, span) => { let item_name = tcx.def_path_str(item_def_id); @@ -1953,7 +2003,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } } if span != DUMMY_SP { - err.span_label(span, &msg); + err.span_label(span, &msg); } else { err.note(&msg); } diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 0d5b3ad8dbb3f..c63fe09ca66fc 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -1239,11 +1239,16 @@ pub fn check_type_bounds<'tcx>( let impl_ty_hir_id = tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local()); let normalize_cause = traits::ObligationCause::misc(impl_ty_span, impl_ty_hir_id); - let mk_cause = |span| { + let mk_cause = |bound, span| { ObligationCause::new( impl_ty_span, impl_ty_hir_id, - ObligationCauseCode::BindingObligation(trait_ty.def_id, span), + match bound { + ty::PredicateKind::Trait(_, _, ty::ImplicitTraitPredicate::Yes) => { + traits::ImplicitSizedObligation(trait_ty.def_id, span) + } + _ => ObligationCauseCode::BindingObligation(trait_ty.def_id, span), + }, ) }; @@ -1254,7 +1259,11 @@ pub fn check_type_bounds<'tcx>( let concrete_ty_bound = bound.subst(tcx, rebased_substs); debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound); - traits::Obligation::new(mk_cause(span), param_env, concrete_ty_bound) + traits::Obligation::new( + mk_cause(bound.kind().skip_binder(), span), + param_env, + concrete_ty_bound, + ) }) .collect(); debug!("check_type_bounds: item_bounds={:?}", obligations); diff --git a/src/test/ui/associated-types/issue-63593.stderr b/src/test/ui/associated-types/issue-63593.stderr index d4654c7d5ace0..325d3e1ed272b 100644 --- a/src/test/ui/associated-types/issue-63593.stderr +++ b/src/test/ui/associated-types/issue-63593.stderr @@ -2,15 +2,21 @@ error[E0277]: the size for values of type `Self` cannot be known at compilation --> $DIR/issue-63593.rs:9:17 | LL | type This = Self; - | ------------^^^^- - | | | - | | doesn't have a size known at compile-time - | required by this bound in `MyTrait::This` + | ^^^^ doesn't have a size known at compile-time | +note: associated types have an implicit `Sized` obligation + --> $DIR/issue-63593.rs:9:5 + | +LL | type This = Self; + | ^^^^^^^^^^^^^^^^^ required by associated type `MyTrait::This` help: consider further restricting `Self` | LL | trait MyTrait: Sized { | ^^^^^^^ +help: consider relaxing the `Sized` obligation + | +LL | type This: ?Sized = Self; + | ^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/generic-associated-types/issue-74816.stderr b/src/test/ui/generic-associated-types/issue-74816.stderr index ecafbfc6f0c2f..a08c51323c000 100644 --- a/src/test/ui/generic-associated-types/issue-74816.stderr +++ b/src/test/ui/generic-associated-types/issue-74816.stderr @@ -15,15 +15,21 @@ error[E0277]: the size for values of type `Self` cannot be known at compilation --> $DIR/issue-74816.rs:10:31 | LL | type Associated: Trait1 = Self; - | --------------------------^^^^- - | | | - | | doesn't have a size known at compile-time - | required by this bound in `Trait2::Associated` + | ^^^^ doesn't have a size known at compile-time | +note: associated types have an implicit `Sized` obligation + --> $DIR/issue-74816.rs:10:5 + | +LL | type Associated: Trait1 = Self; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by associated type `Trait2::Associated` help: consider further restricting `Self` | LL | trait Trait2: Sized { | ^^^^^^^ +help: consider relaxing the `Sized` obligation + | +LL | type Associated: Trait1 + ?Sized = Self; + | ^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/traits/issue-65673.stderr b/src/test/ui/traits/issue-65673.stderr index 6f9bb3edfe047..7dd432bae688c 100644 --- a/src/test/ui/traits/issue-65673.stderr +++ b/src/test/ui/traits/issue-65673.stderr @@ -1,13 +1,19 @@ error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time --> $DIR/issue-65673.rs:9:16 | -LL | type Ctx; - | --------- required by this bound in `WithType::Ctx` -... LL | type Ctx = dyn Alias; | ^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `(dyn Trait + 'static)` +note: associated types have an implicit `Sized` obligation + --> $DIR/issue-65673.rs:4:5 + | +LL | type Ctx; + | ^^^^^^^^^ required by associated type `WithType::Ctx` +help: consider relaxing the `Sized` obligation + | +LL | type Ctx: ?Sized; + | ^^^^^^^^ error: aborting due to previous error