Skip to content

Commit 092e9cc

Browse files
committed
Point to the value instead of the TAIT declaration for obligation failures
1 parent b2c1919 commit 092e9cc

15 files changed

+49
-50
lines changed

compiler/rustc_trait_selection/src/opaque_types.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -965,10 +965,10 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
965965
debug!("instantiate_opaque_types: returning concrete ty {:?}", opaque_defn.concrete_ty);
966966
return opaque_defn.concrete_ty;
967967
}
968-
let span = tcx.def_span(def_id);
969-
debug!("fold_opaque_ty {:?} {:?}", self.value_span, span);
970-
let ty_var = infcx
971-
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span });
968+
let ty_var = infcx.next_ty_var(TypeVariableOrigin {
969+
kind: TypeVariableOriginKind::TypeInference,
970+
span: self.value_span,
971+
});
972972

973973
// Make sure that we are in fact defining the *entire* type
974974
// (e.g., `type Foo<T: Bound> = impl Bar;` needs to be
@@ -993,16 +993,12 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
993993
}
994994

995995
debug!("instantiate_opaque_types: ty_var={:?}", ty_var);
996-
self.compute_opaque_type_obligations(opaque_type_key, span);
996+
self.compute_opaque_type_obligations(opaque_type_key);
997997

998998
ty_var
999999
}
10001000

1001-
fn compute_opaque_type_obligations(
1002-
&mut self,
1003-
opaque_type_key: OpaqueTypeKey<'tcx>,
1004-
span: Span,
1005-
) {
1001+
fn compute_opaque_type_obligations(&mut self, opaque_type_key: OpaqueTypeKey<'tcx>) {
10061002
let infcx = self.infcx;
10071003
let tcx = infcx.tcx;
10081004
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
@@ -1014,7 +1010,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
10141010

10151011
let param_env = tcx.param_env(def_id);
10161012
let InferOk { value: bounds, obligations } = infcx.partially_normalize_associated_types_in(
1017-
ObligationCause::misc(span, self.body_id),
1013+
ObligationCause::misc(self.value_span, self.body_id),
10181014
param_env,
10191015
bounds,
10201016
);
@@ -1038,7 +1034,8 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
10381034
// This also instantiates nested instances of `impl Trait`.
10391035
let predicate = self.instantiate_opaque_types_in_map(predicate);
10401036

1041-
let cause = traits::ObligationCause::new(span, self.body_id, traits::OpaqueType);
1037+
let cause =
1038+
traits::ObligationCause::new(self.value_span, self.body_id, traits::OpaqueType);
10421039

10431040
// Require that the predicate holds for the concrete type.
10441041
debug!("instantiate_opaque_types: predicate={:?}", predicate);

src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ impl Bar for AssocNoCopy {
2828

2929
impl Thing for AssocNoCopy {
3030
type Out = Box<dyn Bar<Assoc: Copy>>;
31-
//~^ ERROR the trait bound `String: Copy` is not satisfied
3231

3332
fn func() -> Self::Out {
33+
//~^ ERROR the trait bound `String: Copy` is not satisfied
3434
Box::new(AssocNoCopy)
3535
}
3636
}

src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `String: Copy` is not satisfied
2-
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:30:28
2+
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:32:18
33
|
4-
LL | type Out = Box<dyn Bar<Assoc: Copy>>;
5-
| ^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
4+
LL | fn func() -> Self::Out {
5+
| ^^^^^^^^^ the trait `Copy` is not implemented for `String`
66

77
error: aborting due to previous error
88

src/test/ui/impl-trait/issue-55872-1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ pub trait Bar {
88

99
impl<S: Default> Bar for S {
1010
type E = impl Copy;
11-
//~^ ERROR the trait bound `S: Copy` is not satisfied in `(S, T)` [E0277]
12-
//~^^ ERROR the trait bound `T: Copy` is not satisfied in `(S, T)` [E0277]
1311

1412
fn foo<T: Default>() -> Self::E {
1513
//~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
1614
//~| ERROR impl has stricter requirements than trait
15+
//~| ERROR the trait bound `S: Copy` is not satisfied in `(S, T)` [E0277]
16+
//~| ERROR the trait bound `T: Copy` is not satisfied in `(S, T)` [E0277]
1717
(S::default(), T::default())
1818
}
1919
}

src/test/ui/impl-trait/issue-55872-1.stderr

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0276]: impl has stricter requirements than trait
2-
--> $DIR/issue-55872-1.rs:14:5
2+
--> $DIR/issue-55872-1.rs:12:5
33
|
44
LL | fn foo<T>() -> Self::E;
55
| ----------------------- definition of `foo` from trait
@@ -8,10 +8,10 @@ LL | fn foo<T: Default>() -> Self::E {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: Default`
99

1010
error[E0277]: the trait bound `S: Copy` is not satisfied in `(S, T)`
11-
--> $DIR/issue-55872-1.rs:10:14
11+
--> $DIR/issue-55872-1.rs:12:29
1212
|
13-
LL | type E = impl Copy;
14-
| ^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S`
13+
LL | fn foo<T: Default>() -> Self::E {
14+
| ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S`
1515
|
1616
= note: required because it appears within the type `(S, T)`
1717
help: consider further restricting this bound
@@ -20,10 +20,10 @@ LL | impl<S: Default + std::marker::Copy> Bar for S {
2020
| ^^^^^^^^^^^^^^^^^^^
2121

2222
error[E0277]: the trait bound `T: Copy` is not satisfied in `(S, T)`
23-
--> $DIR/issue-55872-1.rs:10:14
23+
--> $DIR/issue-55872-1.rs:12:29
2424
|
25-
LL | type E = impl Copy;
26-
| ^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T`
25+
LL | fn foo<T: Default>() -> Self::E {
26+
| ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T`
2727
|
2828
= note: required because it appears within the type `(S, T)`
2929
help: consider further restricting this bound
@@ -32,12 +32,14 @@ LL | fn foo<T: Default + std::marker::Copy>() -> Self::E {
3232
| ^^^^^^^^^^^^^^^^^^^
3333

3434
error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
35-
--> $DIR/issue-55872-1.rs:14:37
35+
--> $DIR/issue-55872-1.rs:12:37
3636
|
3737
LL | fn foo<T: Default>() -> Self::E {
3838
| _____________________________________^
3939
LL | |
4040
LL | |
41+
LL | |
42+
LL | |
4143
LL | | (S::default(), T::default())
4244
LL | | }
4345
| |_____^

src/test/ui/impl-trait/issue-55872-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ pub trait Bar {
1111

1212
impl<S> Bar for S {
1313
type E = impl std::marker::Copy;
14-
//~^ ERROR the trait bound `impl Future: Copy` is not satisfied [E0277]
1514
fn foo<T>() -> Self::E {
1615
//~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
16+
//~| ERROR the trait bound `impl Future: Copy` is not satisfied [E0277]
1717
async {}
1818
}
1919
}

src/test/ui/impl-trait/issue-55872-2.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
error[E0277]: the trait bound `impl Future: Copy` is not satisfied
2-
--> $DIR/issue-55872-2.rs:13:14
2+
--> $DIR/issue-55872-2.rs:14:20
33
|
4-
LL | type E = impl std::marker::Copy;
5-
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `impl Future`
4+
LL | fn foo<T>() -> Self::E {
5+
| ^^^^^^^ the trait `Copy` is not implemented for `impl Future`
66

77
error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
8-
--> $DIR/issue-55872-2.rs:15:28
8+
--> $DIR/issue-55872-2.rs:14:28
99
|
1010
LL | fn foo<T>() -> Self::E {
1111
| ____________________________^
1212
LL | |
13+
LL | |
1314
LL | | async {}
1415
LL | | }
1516
| |_____^

src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ fn main() {
77
}
88

99
type WrongGeneric<T> = impl 'static;
10-
//~^ ERROR the parameter type `T` may not live long enough
11-
//~| ERROR: at least one trait must be specified
10+
//~^ ERROR: at least one trait must be specified
1211

1312
fn wrong_generic<T>(t: T) -> WrongGeneric<T> {
13+
//~^ ERROR the parameter type `T` may not live long enough
1414
t
1515
}

src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ LL | type WrongGeneric<T> = impl 'static;
1919
found opaque type `impl Sized`
2020

2121
error[E0310]: the parameter type `T` may not live long enough
22-
--> $DIR/generic_type_does_not_live_long_enough.rs:9:24
22+
--> $DIR/generic_type_does_not_live_long_enough.rs:12:30
2323
|
24-
LL | type WrongGeneric<T> = impl 'static;
25-
| ^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
26-
...
2724
LL | fn wrong_generic<T>(t: T) -> WrongGeneric<T> {
28-
| - help: consider adding an explicit lifetime bound...: `T: 'static`
25+
| - ^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
26+
| |
27+
| help: consider adding an explicit lifetime bound...: `T: 'static`
2928

3029
error: aborting due to 3 previous errors
3130

src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ struct X;
1515

1616
impl Foo for X {
1717
type Bar = impl Baz<Self, Self>;
18-
//~^ ERROR implementation of `FnOnce` is not general enough
1918

2019
fn bar(&self) -> Self::Bar {
20+
//~^ ERROR implementation of `FnOnce` is not general enough
2121
|x| x
2222
}
2323
}

src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: implementation of `FnOnce` is not general enough
2-
--> $DIR/issue-57611-trait-alias.rs:17:16
2+
--> $DIR/issue-57611-trait-alias.rs:19:22
33
|
4-
LL | type Bar = impl Baz<Self, Self>;
5-
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
4+
LL | fn bar(&self) -> Self::Bar {
5+
| ^^^^^^^^^ implementation of `FnOnce` is not general enough
66
|
77
= note: closure with signature `fn(&'2 X) -> &X` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
88
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`

src/test/ui/type-alias-impl-trait/issue-60371.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ trait Bug {
88

99
impl Bug for &() {
1010
type Item = impl Bug; //~ ERROR `impl Trait` in type aliases is unstable
11-
//~^ ERROR the trait bound `(): Bug` is not satisfied
1211

1312
const FUN: fn() -> Self::Item = || ();
13+
//~^ ERROR the trait bound `(): Bug` is not satisfied
1414
}
1515

1616
fn main() {}

src/test/ui/type-alias-impl-trait/issue-60371.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | type Item = impl Bug;
88
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
99

1010
error[E0277]: the trait bound `(): Bug` is not satisfied
11-
--> $DIR/issue-60371.rs:10:17
11+
--> $DIR/issue-60371.rs:12:40
1212
|
13-
LL | type Item = impl Bug;
14-
| ^^^^^^^^ the trait `Bug` is not implemented for `()`
13+
LL | const FUN: fn() -> Self::Item = || ();
14+
| ^ the trait `Bug` is not implemented for `()`
1515
|
1616
= help: the following implementations were found:
1717
<&() as Bug>

src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#![feature(type_alias_impl_trait)]
66

77
type X<A, B> = impl Into<&'static A>;
8-
//~^ ERROR the trait bound `&'static B: From<&A>` is not satisfied
98

109
fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
10+
//~^ ERROR the trait bound `&'static B: From<&A>` is not satisfied
1111
(a, a)
1212
}
1313

src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `&'static B: From<&A>` is not satisfied
2-
--> $DIR/multiple-def-uses-in-one-fn.rs:7:16
2+
--> $DIR/multiple-def-uses-in-one-fn.rs:9:45
33
|
4-
LL | type X<A, B> = impl Into<&'static A>;
5-
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<&A>` is not implemented for `&'static B`
4+
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
5+
| ^^^^^^^^^^^^^^^^^^ the trait `From<&A>` is not implemented for `&'static B`
66
|
77
= note: required because of the requirements on the impl of `Into<&'static B>` for `&A`
88
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement

0 commit comments

Comments
 (0)