]> git.lizzy.rs Git - rust.git/commitdiff
Point to the value instead of the TAIT declaration for obligation failures
authorOli Scherer <github35764891676564198441@oli-obk.de>
Fri, 30 Jul 2021 14:51:40 +0000 (14:51 +0000)
committerOli Scherer <github35764891676564198441@oli-obk.de>
Fri, 6 Aug 2021 10:42:05 +0000 (10:42 +0000)
15 files changed:
compiler/rustc_trait_selection/src/opaque_types.rs
src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs
src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr
src/test/ui/impl-trait/issue-55872-1.rs
src/test/ui/impl-trait/issue-55872-1.stderr
src/test/ui/impl-trait/issue-55872-2.rs
src/test/ui/impl-trait/issue-55872-2.stderr
src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs
src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr
src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.rs
src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr
src/test/ui/type-alias-impl-trait/issue-60371.rs
src/test/ui/type-alias-impl-trait/issue-60371.stderr
src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs
src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr

index c24e738a7df030f8c832690c73cd2cb26f6cbc0c..f7ed5cd6bd1ff24498174cb99011bc4ac293da28 100644 (file)
@@ -965,10 +965,10 @@ fn fold_opaque_ty(
             debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty);
             return opaque_defn.concrete_ty;
         }
-        let span = tcx.def_span(def_id);
-        debug!("fold_opaque_ty {:?} {:?}", self.value_span, span);
-        let ty_var = infcx
-            .next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span });
+        let ty_var = infcx.next_ty_var(TypeVariableOrigin {
+            kind: TypeVariableOriginKind::TypeInference,
+            span: self.value_span,
+        });
 
         // Make sure that we are in fact defining the *entire* type
         // (e.g., `type Foo<T: Bound> = impl Bar;` needs to be
@@ -993,16 +993,12 @@ fn fold_opaque_ty(
         }
 
         debug!("instantiate_opaque_types: ty_var={:?}", ty_var);
-        self.compute_opaque_type_obligations(opaque_type_key, span);
+        self.compute_opaque_type_obligations(opaque_type_key);
 
         ty_var
     }
 
-    fn compute_opaque_type_obligations(
-        &mut self,
-        opaque_type_key: OpaqueTypeKey<'tcx>,
-        span: Span,
-    ) {
+    fn compute_opaque_type_obligations(&mut self, opaque_type_key: OpaqueTypeKey<'tcx>) {
         let infcx = self.infcx;
         let tcx = infcx.tcx;
         let OpaqueTypeKey { def_id, substs } = opaque_type_key;
@@ -1014,7 +1010,7 @@ fn compute_opaque_type_obligations(
 
         let param_env = tcx.param_env(def_id);
         let InferOk { value: bounds, obligations } = infcx.partially_normalize_associated_types_in(
-            ObligationCause::misc(span, self.body_id),
+            ObligationCause::misc(self.value_span, self.body_id),
             param_env,
             bounds,
         );
@@ -1038,7 +1034,8 @@ fn compute_opaque_type_obligations(
             // This also instantiates nested instances of `impl Trait`.
             let predicate = self.instantiate_opaque_types_in_map(predicate);
 
-            let cause = traits::ObligationCause::new(span, self.body_id, traits::OpaqueType);
+            let cause =
+                traits::ObligationCause::new(self.value_span, self.body_id, traits::OpaqueType);
 
             // Require that the predicate holds for the concrete type.
             debug!("instantiate_opaque_types: predicate={:?}", predicate);
index 7950dd3e99e29b11b14606560844698b27d16aa9..4c36289f47b857ac0e5c50ae4fa9df26d9dc7863 100644 (file)
@@ -28,9 +28,9 @@ impl Bar for AssocNoCopy {
 
 impl Thing for AssocNoCopy {
     type Out = Box<dyn Bar<Assoc: Copy>>;
-    //~^ ERROR the trait bound `String: Copy` is not satisfied
 
     fn func() -> Self::Out {
+        //~^ ERROR the trait bound `String: Copy` is not satisfied
         Box::new(AssocNoCopy)
     }
 }
index 0f1d35be0eb7a19c970be8f52f1de83e30c6dd7c..a32ab453152a0b4663c06788b189aaba8cd23431 100644 (file)
@@ -1,8 +1,8 @@
 error[E0277]: the trait bound `String: Copy` is not satisfied
-  --> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:30:28
+  --> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:32:18
    |
-LL |     type Out = Box<dyn Bar<Assoc: Copy>>;
-   |                            ^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
+LL |     fn func() -> Self::Out {
+   |                  ^^^^^^^^^ the trait `Copy` is not implemented for `String`
 
 error: aborting due to previous error
 
index 72a060abae3e77f7267dce6b001cf52f48004ddb..46188636475db0362549d659208bef75878f060a 100644 (file)
@@ -8,12 +8,12 @@ pub trait Bar {
 
 impl<S: Default> Bar for S {
     type E = impl Copy;
-    //~^ ERROR the trait bound `S: Copy` is not satisfied in `(S, T)` [E0277]
-    //~^^ ERROR the trait bound `T: Copy` is not satisfied in `(S, T)` [E0277]
 
     fn foo<T: Default>() -> Self::E {
         //~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
         //~| ERROR impl has stricter requirements than trait
+        //~| ERROR the trait bound `S: Copy` is not satisfied in `(S, T)` [E0277]
+        //~| ERROR the trait bound `T: Copy` is not satisfied in `(S, T)` [E0277]
         (S::default(), T::default())
     }
 }
index 6411c1b5d1ca2c080f27aa0b5dc4be1b204dea2a..56f5bff939fb7211e6bb511d8bf9defddf64ddfd 100644 (file)
@@ -1,5 +1,5 @@
 error[E0276]: impl has stricter requirements than trait
-  --> $DIR/issue-55872-1.rs:14:5
+  --> $DIR/issue-55872-1.rs:12:5
    |
 LL |     fn foo<T>() -> Self::E;
    |     ----------------------- definition of `foo` from trait
@@ -8,10 +8,10 @@ LL |     fn foo<T: Default>() -> Self::E {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: Default`
 
 error[E0277]: the trait bound `S: Copy` is not satisfied in `(S, T)`
-  --> $DIR/issue-55872-1.rs:10:14
+  --> $DIR/issue-55872-1.rs:12:29
    |
-LL |     type E = impl Copy;
-   |              ^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S`
+LL |     fn foo<T: Default>() -> Self::E {
+   |                             ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S`
    |
    = note: required because it appears within the type `(S, T)`
 help: consider further restricting this bound
@@ -20,10 +20,10 @@ LL | impl<S: Default + std::marker::Copy> Bar for S {
    |                 ^^^^^^^^^^^^^^^^^^^
 
 error[E0277]: the trait bound `T: Copy` is not satisfied in `(S, T)`
-  --> $DIR/issue-55872-1.rs:10:14
+  --> $DIR/issue-55872-1.rs:12:29
    |
-LL |     type E = impl Copy;
-   |              ^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T`
+LL |     fn foo<T: Default>() -> Self::E {
+   |                             ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T`
    |
    = note: required because it appears within the type `(S, T)`
 help: consider further restricting this bound
@@ -32,12 +32,14 @@ LL |     fn foo<T: Default + std::marker::Copy>() -> Self::E {
    |                       ^^^^^^^^^^^^^^^^^^^
 
 error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
-  --> $DIR/issue-55872-1.rs:14:37
+  --> $DIR/issue-55872-1.rs:12:37
    |
 LL |       fn foo<T: Default>() -> Self::E {
    |  _____________________________________^
 LL | |
 LL | |
+LL | |
+LL | |
 LL | |         (S::default(), T::default())
 LL | |     }
    | |_____^
index 6eda1dc62ec62895a1a8b197a2547ddee3283bb2..9546d01ac5c6895ea2c0560ab2bf255f94dff540 100644 (file)
@@ -11,9 +11,9 @@ pub trait Bar {
 
 impl<S> Bar for S {
     type E = impl std::marker::Copy;
-    //~^ ERROR the trait bound `impl Future: Copy` is not satisfied [E0277]
     fn foo<T>() -> Self::E {
         //~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
+        //~| ERROR the trait bound `impl Future: Copy` is not satisfied [E0277]
         async {}
     }
 }
index 58c5ee45051af2159fcfd9994ccc2ec5d69544cc..31b8fbd299c51ea9087e988a24a02940feb05aa1 100644 (file)
@@ -1,15 +1,16 @@
 error[E0277]: the trait bound `impl Future: Copy` is not satisfied
-  --> $DIR/issue-55872-2.rs:13:14
+  --> $DIR/issue-55872-2.rs:14:20
    |
-LL |     type E = impl std::marker::Copy;
-   |              ^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `impl Future`
+LL |     fn foo<T>() -> Self::E {
+   |                    ^^^^^^^ the trait `Copy` is not implemented for `impl Future`
 
 error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
-  --> $DIR/issue-55872-2.rs:15:28
+  --> $DIR/issue-55872-2.rs:14:28
    |
 LL |       fn foo<T>() -> Self::E {
    |  ____________________________^
 LL | |
+LL | |
 LL | |         async {}
 LL | |     }
    | |_____^
index 9c6b93b7ba0405c111e4cae57631b155e95ee03d..78d25e30e0382eba41de11a042664471784ca8a2 100644 (file)
@@ -7,9 +7,9 @@ fn main() {
 }
 
 type WrongGeneric<T> = impl 'static;
-//~^ ERROR the parameter type `T` may not live long enough
-//~| ERROR: at least one trait must be specified
+//~^ ERROR: at least one trait must be specified
 
 fn wrong_generic<T>(t: T) -> WrongGeneric<T> {
+    //~^ ERROR the parameter type `T` may not live long enough
     t
 }
index 18d8daa05e63d168fb413a3ca948c39316897749..568784372e5191db73218523175ccec67dafc72c 100644 (file)
@@ -19,13 +19,12 @@ LL | type WrongGeneric<T> = impl 'static;
            found opaque type `impl Sized`
 
 error[E0310]: the parameter type `T` may not live long enough
-  --> $DIR/generic_type_does_not_live_long_enough.rs:9:24
+  --> $DIR/generic_type_does_not_live_long_enough.rs:12:30
    |
-LL | type WrongGeneric<T> = impl 'static;
-   |                        ^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
-...
 LL | fn wrong_generic<T>(t: T) -> WrongGeneric<T> {
-   |                  - help: consider adding an explicit lifetime bound...: `T: 'static`
+   |                  -           ^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
+   |                  |
+   |                  help: consider adding an explicit lifetime bound...: `T: 'static`
 
 error: aborting due to 3 previous errors
 
index a55fbf9c48a5776a95728c8ca8a66535f22f227d..625e46b6bc0122b4ed5e1d74367e150e5e2595dc 100644 (file)
@@ -15,9 +15,9 @@ trait Foo {
 
 impl Foo for X {
     type Bar = impl Baz<Self, Self>;
-    //~^ ERROR implementation of `FnOnce` is not general enough
 
     fn bar(&self) -> Self::Bar {
+        //~^ ERROR implementation of `FnOnce` is not general enough
         |x| x
     }
 }
index f87beb66d995e6fbd31d11f627b0feeb5cd78893..54d237159d80b56fd0edb903825ec19682ab342e 100644 (file)
@@ -1,8 +1,8 @@
 error: implementation of `FnOnce` is not general enough
-  --> $DIR/issue-57611-trait-alias.rs:17:16
+  --> $DIR/issue-57611-trait-alias.rs:19:22
    |
-LL |     type Bar = impl Baz<Self, Self>;
-   |                ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
+LL |     fn bar(&self) -> Self::Bar {
+   |                      ^^^^^^^^^ implementation of `FnOnce` is not general enough
    |
    = note: closure with signature `fn(&'2 X) -> &X` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
    = note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
index 29301767d3d69154655835995456a6e6abd86910..37a2f28ce074fed466fbb7dcb3f4b95ef7a0a7cd 100644 (file)
@@ -8,9 +8,9 @@ trait Bug {
 
 impl Bug for &() {
     type Item = impl Bug; //~ ERROR `impl Trait` in type aliases is unstable
-    //~^ ERROR the trait bound `(): Bug` is not satisfied
 
     const FUN: fn() -> Self::Item = || ();
+    //~^ ERROR the trait bound `(): Bug` is not satisfied
 }
 
 fn main() {}
index 1e29ccd24b9a63a8382ebd94c2ffa7c6b0f9dc57..1710e07644d647e3b698b4fe60fbf10997c44952 100644 (file)
@@ -8,10 +8,10 @@ LL |     type Item = impl Bug;
    = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
 
 error[E0277]: the trait bound `(): Bug` is not satisfied
-  --> $DIR/issue-60371.rs:10:17
+  --> $DIR/issue-60371.rs:12:40
    |
-LL |     type Item = impl Bug;
-   |                 ^^^^^^^^ the trait `Bug` is not implemented for `()`
+LL |     const FUN: fn() -> Self::Item = || ();
+   |                                        ^ the trait `Bug` is not implemented for `()`
    |
    = help: the following implementations were found:
              <&() as Bug>
index 371dff475d1d787cd79fc49add979dd465335cba..da845e86147b7ffb620f880936aae59069a2095f 100644 (file)
@@ -5,9 +5,9 @@
 #![feature(type_alias_impl_trait)]
 
 type X<A, B> = impl Into<&'static A>;
-//~^ ERROR the trait bound `&'static B: From<&A>` is not satisfied
 
 fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
+    //~^ ERROR the trait bound `&'static B: From<&A>` is not satisfied
     (a, a)
 }
 
index 731c6e2788dde5e6b8206e90ef1caa0548013516..734f15a9283de9052516ccac0206f0992fb3076b 100644 (file)
@@ -1,8 +1,8 @@
 error[E0277]: the trait bound `&'static B: From<&A>` is not satisfied
-  --> $DIR/multiple-def-uses-in-one-fn.rs:7:16
+  --> $DIR/multiple-def-uses-in-one-fn.rs:9:45
    |
-LL | type X<A, B> = impl Into<&'static A>;
-   |                ^^^^^^^^^^^^^^^^^^^^^ the trait `From<&A>` is not implemented for `&'static B`
+LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
+   |                                             ^^^^^^^^^^^^^^^^^^ the trait `From<&A>` is not implemented for `&'static B`
    |
    = note: required because of the requirements on the impl of `Into<&'static B>` for `&A`
 help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement