]> git.lizzy.rs Git - rust.git/commitdiff
Only point at impl self ty in WF if trait predicate shares self ty
authorMichael Goulet <michael@errs.io>
Thu, 12 Jan 2023 20:28:57 +0000 (20:28 +0000)
committerMichael Goulet <michael@errs.io>
Thu, 12 Jan 2023 22:25:30 +0000 (22:25 +0000)
16 files changed:
compiler/rustc_hir_analysis/src/check/wfcheck.rs
tests/ui/associated-types/hr-associated-type-bound-param-6.stderr
tests/ui/associated-types/hr-associated-type-projection-1.stderr
tests/ui/builtin-superkinds/builtin-superkinds-self-type.stderr
tests/ui/const-generics/issues/issue-67185-2.stderr
tests/ui/dst/dst-sized-trait-param.stderr
tests/ui/fn/implied-bounds-unnorm-associated-type-5.stderr
tests/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr
tests/ui/issues/issue-10412.stderr
tests/ui/overloaded/overloaded-calls-nontuple.stderr
tests/ui/specialization/defaultimpl/specialization-wfcheck.stderr
tests/ui/static/static-lifetime.stderr
tests/ui/trait-bounds/unsized-bound.stderr
tests/ui/traits/bound/on-structs-and-enums-in-impls.stderr
tests/ui/unsized/unsized-trait-impl-trait-arg.stderr
tests/ui/unsized/unsized7.stderr

index 9bd49f5e053bef3680ed0f6acaf1eeb886731be4..92fd4625ee83574dbe515e06928cfe2373b5878a 100644 (file)
@@ -1267,14 +1267,21 @@ fn check_impl<'tcx>(
                     },
                     polarity: ty::ImplPolarity::Positive,
                 };
-                let obligations = traits::wf::trait_obligations(
+                let mut obligations = traits::wf::trait_obligations(
                     wfcx.infcx,
                     wfcx.param_env,
                     wfcx.body_id,
                     &trait_pred,
-                    ast_self_ty.span,
+                    ast_trait_ref.path.span,
                     item,
                 );
+                for obligation in &mut obligations {
+                    if let Some(pred) = obligation.predicate.to_opt_poly_trait_pred()
+                        && pred.self_ty().skip_binder() == trait_ref.self_ty()
+                    {
+                        obligation.cause.span = ast_self_ty.span;
+                    }
+                }
                 debug!(?obligations);
                 wfcx.register_obligations(obligations);
             }
index a07a634b28a263a99d68c755a20c42a2a04511a1..bd6e627a3d0d577f43fbc1f76769991681a52ff5 100644 (file)
@@ -1,8 +1,8 @@
 error[E0277]: the trait bound `for<'b> T: X<'b, T>` is not satisfied
-  --> $DIR/hr-associated-type-bound-param-6.rs:12:25
+  --> $DIR/hr-associated-type-bound-param-6.rs:12:12
    |
 LL | impl<S, T> X<'_, T> for (S,) {
-   |                         ^^^^ the trait `for<'b> X<'b, T>` is not implemented for `T`
+   |            ^^^^^^^^ the trait `for<'b> X<'b, T>` is not implemented for `T`
    |
 help: consider restricting type parameter `T`
    |
index ad83a5ca88c3e5294e56af9cb54923d131b65a7b..a65f84ae58eadd479dffcd1d22aac7e643993330 100644 (file)
@@ -1,8 +1,8 @@
 error[E0271]: type mismatch resolving `<T as Deref>::Target == T`
-  --> $DIR/hr-associated-type-projection-1.rs:13:55
+  --> $DIR/hr-associated-type-projection-1.rs:13:33
    |
 LL | impl<T: Copy + std::ops::Deref> UnsafeCopy<'_, T> for T {
-   |      - this type parameter                            ^ expected type parameter `T`, found associated type
+   |      - this type parameter      ^^^^^^^^^^^^^^^^^ expected type parameter `T`, found associated type
    |
    = note: expected type parameter `T`
              found associated type `<T as Deref>::Target`
index e51fab0dcea5452148a19f92e7481be7a35aec4d..e2b177b951cc9a2c2bda0f492468fc4e97faa295 100644 (file)
@@ -1,8 +1,8 @@
 error[E0310]: the parameter type `T` may not live long enough
-  --> $DIR/builtin-superkinds-self-type.rs:10:24
+  --> $DIR/builtin-superkinds-self-type.rs:10:16
    |
 LL | impl <T: Sync> Foo for T { }
-   |                        ^ ...so that the type `T` will meet its required lifetime bounds...
+   |                ^^^ ...so that the type `T` will meet its required lifetime bounds...
    |
 note: ...that is required by this bound
   --> $DIR/builtin-superkinds-self-type.rs:6:24
index 7deb4b36fabf00b8f8beddc694b985583e036e99..c7be8e14a10d5889b440a92fb47a3b02c11fbe13 100644 (file)
@@ -23,10 +23,10 @@ LL |     [<u8 as Baz>::Quaks; 2]: Bar,
    = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
 
 error[E0277]: the trait bound `[u16; 3]: Bar` is not satisfied
-  --> $DIR/issue-67185-2.rs:21:14
+  --> $DIR/issue-67185-2.rs:21:6
    |
 LL | impl Foo for FooImpl {}
-   |              ^^^^^^^ the trait `Bar` is not implemented for `[u16; 3]`
+   |      ^^^ the trait `Bar` is not implemented for `[u16; 3]`
    |
    = help: the following other types implement trait `Bar`:
              [[u16; 3]; 3]
@@ -41,10 +41,10 @@ LL |     <u8 as Baz>::Quaks: Bar,
    |                         ^^^ required by this bound in `Foo`
 
 error[E0277]: the trait bound `[[u16; 3]; 2]: Bar` is not satisfied
-  --> $DIR/issue-67185-2.rs:21:14
+  --> $DIR/issue-67185-2.rs:21:6
    |
 LL | impl Foo for FooImpl {}
-   |              ^^^^^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]`
+   |      ^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]`
    |
    = help: the following other types implement trait `Bar`:
              [[u16; 3]; 3]
index 5dd517d4d9394f7f3a63ec95dea2adfc07afe4c9..60e9de90332cc381dff3058e401659ece13e34f4 100644 (file)
@@ -1,8 +1,8 @@
 error[E0277]: the size for values of type `[isize]` cannot be known at compilation time
-  --> $DIR/dst-sized-trait-param.rs:7:23
+  --> $DIR/dst-sized-trait-param.rs:7:6
    |
 LL | impl Foo<[isize]> for usize { }
-   |                       ^^^^^ 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 `[isize]`
 note: required by a bound in `Foo`
index 1a50eadb5f0ad1a310fd52c3ef10a09a0147a6f8..458756a3dcd9625a62a8393eb61e68c572de2446 100644 (file)
@@ -1,8 +1,8 @@
 error[E0309]: the parameter type `T` may not live long enough
-  --> $DIR/implied-bounds-unnorm-associated-type-5.rs:6:27
+  --> $DIR/implied-bounds-unnorm-associated-type-5.rs:6:13
    |
 LL | impl<'a, T> Trait<'a> for T {
-   |                           ^ ...so that the type `T` will meet its required lifetime bounds...
+   |             ^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
    |
 note: ...that is required by this bound
   --> $DIR/implied-bounds-unnorm-associated-type-5.rs:1:18
index 260a0ce6142ca51dfbd59bf21011c01ce6275b9a..6791182238c72d978041c2bb39edbdd1e69a6c5c 100644 (file)
@@ -1,8 +1,8 @@
 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:17
+  --> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:19:6
    |
 LL | impl Tsized for () {}
-   |                 ^^ 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 `[()]`
 note: required by a bound in `Tsized`
index ebaf87630fe7f49dfdd8f0cadfd1cc35d80275f7..46b9fd541adfa59f07df1d46b90611b4cd2594c1 100644 (file)
@@ -53,10 +53,10 @@ LL | impl<'self> Serializable<'_, str> for &'self str {
    |                          +++
 
 error[E0277]: the size for values of type `str` cannot be known at compilation time
-  --> $DIR/issue-10412.rs:7:35
+  --> $DIR/issue-10412.rs:7:13
    |
 LL | impl<'self> Serializable<str> for &'self str {
-   |                                   ^^^^^^^^^^ 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 `str`
 note: required by a bound in `Serializable`
index 8a17446130b67bf54659fabdd154f08da4002629..2e16007825935a159bf5d213f332dd096b54d483 100644 (file)
@@ -1,17 +1,17 @@
 error[E0059]: type parameter to bare `FnMut` trait must be a tuple
-  --> $DIR/overloaded-calls-nontuple.rs:10:23
+  --> $DIR/overloaded-calls-nontuple.rs:10:6
    |
 LL | impl FnMut<isize> for S {
-   |                       ^ the trait `Tuple` is not implemented for `isize`
+   |      ^^^^^^^^^^^^ the trait `Tuple` is not implemented for `isize`
    |
 note: required by a bound in `FnMut`
   --> $SRC_DIR/core/src/ops/function.rs:LL:COL
 
 error[E0059]: type parameter to bare `FnOnce` trait must be a tuple
-  --> $DIR/overloaded-calls-nontuple.rs:18:24
+  --> $DIR/overloaded-calls-nontuple.rs:18:6
    |
 LL | impl FnOnce<isize> for S {
-   |                        ^ the trait `Tuple` is not implemented for `isize`
+   |      ^^^^^^^^^^^^^ the trait `Tuple` is not implemented for `isize`
    |
 note: required by a bound in `FnOnce`
   --> $SRC_DIR/core/src/ops/function.rs:LL:COL
index 1d9014a264305e1c9e61ab6c093a2882d08005b0..e7801603493d2e77cdd69cdfa9531c9dab07630e 100644 (file)
@@ -9,10 +9,10 @@ LL | #![feature(specialization)]
    = note: `#[warn(incomplete_features)]` on by default
 
 error[E0277]: the trait bound `U: Eq` is not satisfied
-  --> $DIR/specialization-wfcheck.rs:7:37
+  --> $DIR/specialization-wfcheck.rs:7:17
    |
 LL | default impl<U> Foo<'static, U> for () {}
-   |                                     ^^ the trait `Eq` is not implemented for `U`
+   |                 ^^^^^^^^^^^^^^^ the trait `Eq` is not implemented for `U`
    |
 note: required by a bound in `Foo`
   --> $DIR/specialization-wfcheck.rs:5:18
index 4191ab054cb9eb86381d9a8910dfb25d252bceee..4af3370c799448eee1a2db4ff7841cfffbad12dd 100644 (file)
@@ -1,8 +1,8 @@
 error[E0478]: lifetime bound not satisfied
-  --> $DIR/static-lifetime.rs:3:34
+  --> $DIR/static-lifetime.rs:3:20
    |
 LL | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {}
-   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^
+   |                    ^^^^^^^^^
    |
 note: lifetime parameter instantiated with the lifetime `'a` as defined here
   --> $DIR/static-lifetime.rs:3:6
index f3c8464abeb53f54a17ea5955a3d2cb99b780755..da27ba1c58dbee7913b913838477ca5d751859c7 100644 (file)
@@ -223,10 +223,10 @@ LL | trait Trait6<A: ?Sized, B> {}
    |               ++++++++
 
 error[E0277]: the size for values of type `Y` cannot be known at compilation time
-  --> $DIR/unsized-bound.rs:26:29
+  --> $DIR/unsized-bound.rs:26:12
    |
 LL | impl<X, Y> Trait7<X, Y> for X where Y: ?Sized {}
-   |         -                   ^ doesn't have a size known at compile-time
+   |         -  ^^^^^^^^^^^^ doesn't have a size known at compile-time
    |         |
    |         this type parameter needs to be `std::marker::Sized`
    |
@@ -246,10 +246,10 @@ LL | trait Trait7<A, B: ?Sized> {}
    |                  ++++++++
 
 error[E0277]: the size for values of type `Y` cannot be known at compilation time
-  --> $DIR/unsized-bound.rs:29:37
+  --> $DIR/unsized-bound.rs:29:20
    |
 LL | impl<X, Y: ?Sized> Trait8<X, Y> for X {}
-   |         -                           ^ doesn't have a size known at compile-time
+   |         -          ^^^^^^^^^^^^ doesn't have a size known at compile-time
    |         |
    |         this type parameter needs to be `std::marker::Sized`
    |
index 903961b4be2b9bfeba161913e010b2f5ed7525b9..8a43742260bb2230a328a5460c93ae893575f724 100644 (file)
@@ -1,8 +1,8 @@
 error[E0277]: the trait bound `u16: Trait` is not satisfied
-  --> $DIR/on-structs-and-enums-in-impls.rs:20:30
+  --> $DIR/on-structs-and-enums-in-impls.rs:20:6
    |
 LL | impl PolyTrait<Foo<u16>> for Struct {
-   |                              ^^^^^^ the trait `Trait` is not implemented for `u16`
+   |      ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `u16`
    |
 note: required by a bound in `Foo`
   --> $DIR/on-structs-and-enums-in-impls.rs:3:14
index 5b24c571f6c9ea7c933a648589e2d93b1efe2837..f81487d5231ab514249c0222b0a85fc8aad3282a 100644 (file)
@@ -1,8 +1,8 @@
 error[E0277]: the size for values of type `X` cannot be known at compilation time
-  --> $DIR/unsized-trait-impl-trait-arg.rs:8:27
+  --> $DIR/unsized-trait-impl-trait-arg.rs:8:17
    |
 LL | impl<X: ?Sized> T2<X> for S4<X> {
-   |      -                    ^^^^^ doesn't have a size known at compile-time
+   |      -          ^^^^^ doesn't have a size known at compile-time
    |      |
    |      this type parameter needs to be `std::marker::Sized`
    |
index 1b62bb433146f02c119ffeb6a016bff0175e262b..1555b9df4f8d43b0f7381fc095d251b28f253d5a 100644 (file)
@@ -1,8 +1,8 @@
 error[E0277]: the size for values of type `X` cannot be known at compilation time
-  --> $DIR/unsized7.rs:12:31
+  --> $DIR/unsized7.rs:12:21
    |
 LL | impl<X: ?Sized + T> T1<X> for S3<X> {
-   |      -                        ^^^^^ doesn't have a size known at compile-time
+   |      -              ^^^^^ doesn't have a size known at compile-time
    |      |
    |      this type parameter needs to be `std::marker::Sized`
    |