mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-29 16:13:40 +00:00
Point to the value instead of the TAIT declaration for obligation failures
This commit is contained in:
parent
b2c1919a3d
commit
092e9ccd8a
@ -965,10 +965,10 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||
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 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||
}
|
||||
|
||||
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 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||
|
||||
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 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||
// 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);
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
@ -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 | | }
|
||||
| |_____^
|
||||
|
@ -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 {}
|
||||
}
|
||||
}
|
||||
|
@ -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 | | }
|
||||
| |_____^
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -15,9 +15,9 @@ struct X;
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -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`
|
||||
|
@ -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() {}
|
||||
|
@ -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>
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user