Skip to content

Commit 5924c25

Browse files
Only point at impl self ty in WF if trait predicate shares self ty
1 parent 2aabb0f commit 5924c25

16 files changed

+45
-38
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1267,14 +1267,21 @@ fn check_impl<'tcx>(
12671267
},
12681268
polarity: ty::ImplPolarity::Positive,
12691269
};
1270-
let obligations = traits::wf::trait_obligations(
1270+
let mut obligations = traits::wf::trait_obligations(
12711271
wfcx.infcx,
12721272
wfcx.param_env,
12731273
wfcx.body_id,
12741274
&trait_pred,
1275-
ast_self_ty.span,
1275+
ast_trait_ref.path.span,
12761276
item,
12771277
);
1278+
for obligation in &mut obligations {
1279+
if let Some(pred) = obligation.predicate.to_opt_poly_trait_pred()
1280+
&& pred.self_ty().skip_binder() == trait_ref.self_ty()
1281+
{
1282+
obligation.cause.span = ast_self_ty.span;
1283+
}
1284+
}
12781285
debug!(?obligations);
12791286
wfcx.register_obligations(obligations);
12801287
}

tests/ui/associated-types/hr-associated-type-bound-param-6.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `for<'b> T: X<'b, T>` is not satisfied
2-
--> $DIR/hr-associated-type-bound-param-6.rs:12:25
2+
--> $DIR/hr-associated-type-bound-param-6.rs:12:12
33
|
44
LL | impl<S, T> X<'_, T> for (S,) {
5-
| ^^^^ the trait `for<'b> X<'b, T>` is not implemented for `T`
5+
| ^^^^^^^^ the trait `for<'b> X<'b, T>` is not implemented for `T`
66
|
77
help: consider restricting type parameter `T`
88
|

tests/ui/associated-types/hr-associated-type-projection-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0271]: type mismatch resolving `<T as Deref>::Target == T`
2-
--> $DIR/hr-associated-type-projection-1.rs:13:55
2+
--> $DIR/hr-associated-type-projection-1.rs:13:33
33
|
44
LL | impl<T: Copy + std::ops::Deref> UnsafeCopy<'_, T> for T {
5-
| - this type parameter ^ expected type parameter `T`, found associated type
5+
| - this type parameter ^^^^^^^^^^^^^^^^^ expected type parameter `T`, found associated type
66
|
77
= note: expected type parameter `T`
88
found associated type `<T as Deref>::Target`

tests/ui/builtin-superkinds/builtin-superkinds-self-type.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0310]: the parameter type `T` may not live long enough
2-
--> $DIR/builtin-superkinds-self-type.rs:10:24
2+
--> $DIR/builtin-superkinds-self-type.rs:10:16
33
|
44
LL | impl <T: Sync> Foo for T { }
5-
| ^ ...so that the type `T` will meet its required lifetime bounds...
5+
| ^^^ ...so that the type `T` will meet its required lifetime bounds...
66
|
77
note: ...that is required by this bound
88
--> $DIR/builtin-superkinds-self-type.rs:6:24

tests/ui/const-generics/issues/issue-67185-2.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ LL | [<u8 as Baz>::Quaks; 2]: Bar,
2323
= help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
2424

2525
error[E0277]: the trait bound `[u16; 3]: Bar` is not satisfied
26-
--> $DIR/issue-67185-2.rs:21:14
26+
--> $DIR/issue-67185-2.rs:21:6
2727
|
2828
LL | impl Foo for FooImpl {}
29-
| ^^^^^^^ the trait `Bar` is not implemented for `[u16; 3]`
29+
| ^^^ the trait `Bar` is not implemented for `[u16; 3]`
3030
|
3131
= help: the following other types implement trait `Bar`:
3232
[[u16; 3]; 3]
@@ -41,10 +41,10 @@ LL | <u8 as Baz>::Quaks: Bar,
4141
| ^^^ required by this bound in `Foo`
4242

4343
error[E0277]: the trait bound `[[u16; 3]; 2]: Bar` is not satisfied
44-
--> $DIR/issue-67185-2.rs:21:14
44+
--> $DIR/issue-67185-2.rs:21:6
4545
|
4646
LL | impl Foo for FooImpl {}
47-
| ^^^^^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]`
47+
| ^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]`
4848
|
4949
= help: the following other types implement trait `Bar`:
5050
[[u16; 3]; 3]

tests/ui/dst/dst-sized-trait-param.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `[isize]` cannot be known at compilation time
2-
--> $DIR/dst-sized-trait-param.rs:7:23
2+
--> $DIR/dst-sized-trait-param.rs:7:6
33
|
44
LL | impl Foo<[isize]> for usize { }
5-
| ^^^^^ doesn't have a size known at compile-time
5+
| ^^^^^^^^^^^^ doesn't have a size known at compile-time
66
|
77
= help: the trait `Sized` is not implemented for `[isize]`
88
note: required by a bound in `Foo`

tests/ui/fn/implied-bounds-unnorm-associated-type-5.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0309]: the parameter type `T` may not live long enough
2-
--> $DIR/implied-bounds-unnorm-associated-type-5.rs:6:27
2+
--> $DIR/implied-bounds-unnorm-associated-type-5.rs:6:13
33
|
44
LL | impl<'a, T> Trait<'a> for T {
5-
| ^ ...so that the type `T` will meet its required lifetime bounds...
5+
| ^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
66
|
77
note: ...that is required by this bound
88
--> $DIR/implied-bounds-unnorm-associated-type-5.rs:1:18

tests/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `[()]` cannot be known at compilation time
2-
--> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:19:17
2+
--> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:19:6
33
|
44
LL | impl Tsized for () {}
5-
| ^^ doesn't have a size known at compile-time
5+
| ^^^^^^ doesn't have a size known at compile-time
66
|
77
= help: the trait `Sized` is not implemented for `[()]`
88
note: required by a bound in `Tsized`

tests/ui/issues/issue-10412.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ LL | impl<'self> Serializable<'_, str> for &'self str {
5353
| +++
5454

5555
error[E0277]: the size for values of type `str` cannot be known at compilation time
56-
--> $DIR/issue-10412.rs:7:35
56+
--> $DIR/issue-10412.rs:7:13
5757
|
5858
LL | impl<'self> Serializable<str> for &'self str {
59-
| ^^^^^^^^^^ doesn't have a size known at compile-time
59+
| ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
6060
|
6161
= help: the trait `Sized` is not implemented for `str`
6262
note: required by a bound in `Serializable`

tests/ui/overloaded/overloaded-calls-nontuple.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error[E0059]: type parameter to bare `FnMut` trait must be a tuple
2-
--> $DIR/overloaded-calls-nontuple.rs:10:23
2+
--> $DIR/overloaded-calls-nontuple.rs:10:6
33
|
44
LL | impl FnMut<isize> for S {
5-
| ^ the trait `Tuple` is not implemented for `isize`
5+
| ^^^^^^^^^^^^ the trait `Tuple` is not implemented for `isize`
66
|
77
note: required by a bound in `FnMut`
88
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
99

1010
error[E0059]: type parameter to bare `FnOnce` trait must be a tuple
11-
--> $DIR/overloaded-calls-nontuple.rs:18:24
11+
--> $DIR/overloaded-calls-nontuple.rs:18:6
1212
|
1313
LL | impl FnOnce<isize> for S {
14-
| ^ the trait `Tuple` is not implemented for `isize`
14+
| ^^^^^^^^^^^^^ the trait `Tuple` is not implemented for `isize`
1515
|
1616
note: required by a bound in `FnOnce`
1717
--> $SRC_DIR/core/src/ops/function.rs:LL:COL

tests/ui/specialization/defaultimpl/specialization-wfcheck.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ LL | #![feature(specialization)]
99
= note: `#[warn(incomplete_features)]` on by default
1010

1111
error[E0277]: the trait bound `U: Eq` is not satisfied
12-
--> $DIR/specialization-wfcheck.rs:7:37
12+
--> $DIR/specialization-wfcheck.rs:7:17
1313
|
1414
LL | default impl<U> Foo<'static, U> for () {}
15-
| ^^ the trait `Eq` is not implemented for `U`
15+
| ^^^^^^^^^^^^^^^ the trait `Eq` is not implemented for `U`
1616
|
1717
note: required by a bound in `Foo`
1818
--> $DIR/specialization-wfcheck.rs:5:18

tests/ui/static/static-lifetime.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0478]: lifetime bound not satisfied
2-
--> $DIR/static-lifetime.rs:3:34
2+
--> $DIR/static-lifetime.rs:3:20
33
|
44
LL | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^
66
|
77
note: lifetime parameter instantiated with the lifetime `'a` as defined here
88
--> $DIR/static-lifetime.rs:3:6

tests/ui/trait-bounds/unsized-bound.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ LL | trait Trait6<A: ?Sized, B> {}
223223
| ++++++++
224224

225225
error[E0277]: the size for values of type `Y` cannot be known at compilation time
226-
--> $DIR/unsized-bound.rs:26:29
226+
--> $DIR/unsized-bound.rs:26:12
227227
|
228228
LL | impl<X, Y> Trait7<X, Y> for X where Y: ?Sized {}
229-
| - ^ doesn't have a size known at compile-time
229+
| - ^^^^^^^^^^^^ doesn't have a size known at compile-time
230230
| |
231231
| this type parameter needs to be `std::marker::Sized`
232232
|
@@ -246,10 +246,10 @@ LL | trait Trait7<A, B: ?Sized> {}
246246
| ++++++++
247247

248248
error[E0277]: the size for values of type `Y` cannot be known at compilation time
249-
--> $DIR/unsized-bound.rs:29:37
249+
--> $DIR/unsized-bound.rs:29:20
250250
|
251251
LL | impl<X, Y: ?Sized> Trait8<X, Y> for X {}
252-
| - ^ doesn't have a size known at compile-time
252+
| - ^^^^^^^^^^^^ doesn't have a size known at compile-time
253253
| |
254254
| this type parameter needs to be `std::marker::Sized`
255255
|

tests/ui/traits/bound/on-structs-and-enums-in-impls.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `u16: Trait` is not satisfied
2-
--> $DIR/on-structs-and-enums-in-impls.rs:20:30
2+
--> $DIR/on-structs-and-enums-in-impls.rs:20:6
33
|
44
LL | impl PolyTrait<Foo<u16>> for Struct {
5-
| ^^^^^^ the trait `Trait` is not implemented for `u16`
5+
| ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `u16`
66
|
77
note: required by a bound in `Foo`
88
--> $DIR/on-structs-and-enums-in-impls.rs:3:14

tests/ui/unsized/unsized-trait-impl-trait-arg.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `X` cannot be known at compilation time
2-
--> $DIR/unsized-trait-impl-trait-arg.rs:8:27
2+
--> $DIR/unsized-trait-impl-trait-arg.rs:8:17
33
|
44
LL | impl<X: ?Sized> T2<X> for S4<X> {
5-
| - ^^^^^ doesn't have a size known at compile-time
5+
| - ^^^^^ doesn't have a size known at compile-time
66
| |
77
| this type parameter needs to be `std::marker::Sized`
88
|

tests/ui/unsized/unsized7.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the size for values of type `X` cannot be known at compilation time
2-
--> $DIR/unsized7.rs:12:31
2+
--> $DIR/unsized7.rs:12:21
33
|
44
LL | impl<X: ?Sized + T> T1<X> for S3<X> {
5-
| - ^^^^^ doesn't have a size known at compile-time
5+
| - ^^^^^ doesn't have a size known at compile-time
66
| |
77
| this type parameter needs to be `std::marker::Sized`
88
|

0 commit comments

Comments
 (0)