Skip to content

Commit b63cea3

Browse files
committed
Point at RHS of associated type in obligation span
1 parent da86509 commit b63cea3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+172
-202
lines changed

compiler/rustc_typeck/src/check/check.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,15 +790,15 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
790790
let abi = sig.header.abi;
791791
fn_maybe_err(tcx, item.ident.span, abi);
792792
}
793-
hir::TraitItemKind::Type(.., Some(_default)) => {
793+
hir::TraitItemKind::Type(.., Some(default)) => {
794794
let assoc_item = tcx.associated_item(item.def_id);
795795
let trait_substs =
796796
InternalSubsts::identity_for_item(tcx, it.def_id.to_def_id());
797797
let _: Result<_, rustc_errors::ErrorReported> = check_type_bounds(
798798
tcx,
799799
assoc_item,
800800
assoc_item,
801-
item.span,
801+
default.span,
802802
ty::TraitRef { def_id: it.def_id.to_def_id(), substs: trait_substs },
803803
);
804804
}
@@ -1047,12 +1047,12 @@ pub(super) fn check_impl_items_against_trait<'tcx>(
10471047
opt_trait_span,
10481048
);
10491049
}
1050-
hir::ImplItemKind::TyAlias(_) => {
1050+
hir::ImplItemKind::TyAlias(impl_ty) => {
10511051
let opt_trait_span = tcx.hir().span_if_local(ty_trait_item.def_id);
10521052
compare_ty_impl(
10531053
tcx,
10541054
&ty_impl_item,
1055-
impl_item.span,
1055+
impl_ty.span,
10561056
&ty_trait_item,
10571057
impl_trait_ref,
10581058
opt_trait_span,

src/test/ui/associated-types/defaults-suitability.stderr

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
error[E0277]: the trait bound `NotClone: Clone` is not satisfied
2-
--> $DIR/defaults-suitability.rs:13:5
2+
--> $DIR/defaults-suitability.rs:13:22
33
|
44
LL | type Ty: Clone = NotClone;
5-
| ^^^^^^^^^-----^^^^^^^^^^^^
6-
| | |
7-
| | required by this bound in `Tr::Ty`
8-
| the trait `Clone` is not implemented for `NotClone`
5+
| ----- ^^^^^^^^ the trait `Clone` is not implemented for `NotClone`
6+
| |
7+
| required by this bound in `Tr::Ty`
98

109
error[E0277]: the trait bound `NotClone: Clone` is not satisfied
11-
--> $DIR/defaults-suitability.rs:22:5
10+
--> $DIR/defaults-suitability.rs:22:15
1211
|
1312
LL | Self::Ty: Clone,
1413
| ----- required by this bound in `Tr2::Ty`
1514
LL | {
1615
LL | type Ty = NotClone;
17-
| ^^^^^--^^^^^^^^^^^^
18-
| | |
19-
| | required by a bound in this
20-
| the trait `Clone` is not implemented for `NotClone`
16+
| -- ^^^^^^^^ the trait `Clone` is not implemented for `NotClone`
17+
| |
18+
| required by a bound in this
2119

2220
error[E0277]: the trait bound `T: Clone` is not satisfied
23-
--> $DIR/defaults-suitability.rs:28:5
21+
--> $DIR/defaults-suitability.rs:28:23
2422
|
2523
LL | type Bar: Clone = Vec<T>;
26-
| ^^^^^^^^^^-----^^^^^^^^^^
27-
| | |
28-
| | required by this bound in `Foo::Bar`
29-
| the trait `Clone` is not implemented for `T`
24+
| ----- ^^^^^^ the trait `Clone` is not implemented for `T`
25+
| |
26+
| required by this bound in `Foo::Bar`
3027
|
3128
= note: required because of the requirements on the impl of `Clone` for `Vec<T>`
3229
help: consider restricting type parameter `T`
@@ -35,34 +32,31 @@ LL | trait Foo<T: std::clone::Clone> {
3532
| ^^^^^^^^^^^^^^^^^^^
3633

3734
error[E0277]: the trait bound `(): Foo<Self>` is not satisfied
38-
--> $DIR/defaults-suitability.rs:34:5
35+
--> $DIR/defaults-suitability.rs:34:29
3936
|
4037
LL | type Assoc: Foo<Self> = ();
41-
| ^^^^^^^^^^^^---------^^^^^^
42-
| | |
43-
| | required by this bound in `Bar::Assoc`
44-
| the trait `Foo<Self>` is not implemented for `()`
38+
| --------- ^^ the trait `Foo<Self>` is not implemented for `()`
39+
| |
40+
| required by this bound in `Bar::Assoc`
4541

4642
error[E0277]: the trait bound `NotClone: IsU8<NotClone>` is not satisfied
47-
--> $DIR/defaults-suitability.rs:56:5
43+
--> $DIR/defaults-suitability.rs:56:18
4844
|
4945
LL | Self::Assoc: IsU8<Self::Assoc>,
5046
| ----------------- required by this bound in `D::Assoc`
5147
...
5248
LL | type Assoc = NotClone;
53-
| ^^^^^-----^^^^^^^^^^^^
54-
| | |
55-
| | required by a bound in this
56-
| the trait `IsU8<NotClone>` is not implemented for `NotClone`
49+
| ----- ^^^^^^^^ the trait `IsU8<NotClone>` is not implemented for `NotClone`
50+
| |
51+
| required by a bound in this
5752

5853
error[E0277]: the trait bound `<Self as Foo2<T>>::Baz: Clone` is not satisfied
59-
--> $DIR/defaults-suitability.rs:65:5
54+
--> $DIR/defaults-suitability.rs:65:23
6055
|
6156
LL | type Bar: Clone = Vec<Self::Baz>;
62-
| ^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^
63-
| | |
64-
| | required by this bound in `Foo2::Bar`
65-
| the trait `Clone` is not implemented for `<Self as Foo2<T>>::Baz`
57+
| ----- ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `<Self as Foo2<T>>::Baz`
58+
| |
59+
| required by this bound in `Foo2::Bar`
6660
|
6761
= note: required because of the requirements on the impl of `Clone` for `Vec<<Self as Foo2<T>>::Baz>`
6862
help: consider further restricting the associated type
@@ -71,13 +65,12 @@ LL | trait Foo2<T> where <Self as Foo2<T>>::Baz: Clone {
7165
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7266

7367
error[E0277]: the trait bound `<Self as Foo25<T>>::Baz: Clone` is not satisfied
74-
--> $DIR/defaults-suitability.rs:74:5
68+
--> $DIR/defaults-suitability.rs:74:23
7569
|
7670
LL | type Bar: Clone = Vec<Self::Baz>;
77-
| ^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^
78-
| | |
79-
| | required by this bound in `Foo25::Bar`
80-
| the trait `Clone` is not implemented for `<Self as Foo25<T>>::Baz`
71+
| ----- ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `<Self as Foo25<T>>::Baz`
72+
| |
73+
| required by this bound in `Foo25::Bar`
8174
|
8275
= note: required because of the requirements on the impl of `Clone` for `Vec<<Self as Foo25<T>>::Baz>`
8376
help: consider further restricting the associated type
@@ -86,16 +79,15 @@ LL | trait Foo25<T: Clone> where <Self as Foo25<T>>::Baz: Clone {
8679
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8780

8881
error[E0277]: the trait bound `T: Clone` is not satisfied
89-
--> $DIR/defaults-suitability.rs:87:5
82+
--> $DIR/defaults-suitability.rs:87:16
9083
|
9184
LL | Self::Baz: Clone,
9285
| ----- required by this bound in `Foo3::Baz`
9386
...
9487
LL | type Baz = T;
95-
| ^^^^^---^^^^^
96-
| | |
97-
| | required by a bound in this
98-
| the trait `Clone` is not implemented for `T`
88+
| --- ^ the trait `Clone` is not implemented for `T`
89+
| |
90+
| required by a bound in this
9991
|
10092
help: consider further restricting type parameter `T`
10193
|

src/test/ui/associated-types/defaults-unsound-62211-1.stderr

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
error[E0277]: `Self` doesn't implement `std::fmt::Display`
2-
--> $DIR/defaults-unsound-62211-1.rs:20:5
2+
--> $DIR/defaults-unsound-62211-1.rs:20:96
33
|
44
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------^^^^^^^^
6-
| | |
7-
| | required by this bound in `UncheckedCopy::Output`
8-
| `Self` cannot be formatted with the default formatter
5+
| ------- ^^^^ `Self` cannot be formatted with the default formatter
6+
| |
7+
| required by this bound in `UncheckedCopy::Output`
98
|
109
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
1110
help: consider further restricting `Self`
@@ -14,41 +13,34 @@ LL | trait UncheckedCopy: Sized + std::fmt::Display {
1413
| ^^^^^^^^^^^^^^^^^^^
1514

1615
error[E0277]: cannot add-assign `&'static str` to `Self`
17-
--> $DIR/defaults-unsound-62211-1.rs:20:5
16+
--> $DIR/defaults-unsound-62211-1.rs:20:96
1817
|
1918
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21-
| | |
22-
| | required by this bound in `UncheckedCopy::Output`
23-
| no implementation for `Self += &'static str`
19+
| ----------------------- ^^^^ no implementation for `Self += &'static str`
20+
| |
21+
| required by this bound in `UncheckedCopy::Output`
2422
|
2523
help: consider further restricting `Self`
2624
|
2725
LL | trait UncheckedCopy: Sized + AddAssign<&'static str> {
2826
| ^^^^^^^^^^^^^^^^^^^^^^^^^
2927

3028
error[E0277]: the trait bound `Self: Deref` is not satisfied
31-
--> $DIR/defaults-unsound-62211-1.rs:20:5
29+
--> $DIR/defaults-unsound-62211-1.rs:20:96
3230
|
3331
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
34-
| ^^^^^^^^^^^^^^^^^^^^-------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35-
| | |
36-
| | required by this bound in `UncheckedCopy::Output`
37-
| the trait `Deref` is not implemented for `Self`
32+
| ------------------- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Deref` is not implemented for `Self`
3833
|
3934
help: consider further restricting `Self`
4035
|
4136
LL | trait UncheckedCopy: Sized + Deref {
4237
| ^^^^^^^
4338

4439
error[E0277]: the trait bound `Self: Copy` is not satisfied
45-
--> $DIR/defaults-unsound-62211-1.rs:20:5
40+
--> $DIR/defaults-unsound-62211-1.rs:20:96
4641
|
4742
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
48-
| ^^^^^^^^^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49-
| | |
50-
| | required by this bound in `UncheckedCopy::Output`
51-
| the trait `Copy` is not implemented for `Self`
43+
| ---- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Copy` is not implemented for `Self`
5244
|
5345
help: consider further restricting `Self`
5446
|

src/test/ui/associated-types/defaults-unsound-62211-2.stderr

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
error[E0277]: `Self` doesn't implement `std::fmt::Display`
2-
--> $DIR/defaults-unsound-62211-2.rs:20:5
2+
--> $DIR/defaults-unsound-62211-2.rs:20:96
33
|
44
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------^^^^^^^^
6-
| | |
7-
| | required by this bound in `UncheckedCopy::Output`
8-
| `Self` cannot be formatted with the default formatter
5+
| ------- ^^^^ `Self` cannot be formatted with the default formatter
6+
| |
7+
| required by this bound in `UncheckedCopy::Output`
98
|
109
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
1110
help: consider further restricting `Self`
@@ -14,41 +13,34 @@ LL | trait UncheckedCopy: Sized + std::fmt::Display {
1413
| ^^^^^^^^^^^^^^^^^^^
1514

1615
error[E0277]: cannot add-assign `&'static str` to `Self`
17-
--> $DIR/defaults-unsound-62211-2.rs:20:5
16+
--> $DIR/defaults-unsound-62211-2.rs:20:96
1817
|
1918
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21-
| | |
22-
| | required by this bound in `UncheckedCopy::Output`
23-
| no implementation for `Self += &'static str`
19+
| ----------------------- ^^^^ no implementation for `Self += &'static str`
20+
| |
21+
| required by this bound in `UncheckedCopy::Output`
2422
|
2523
help: consider further restricting `Self`
2624
|
2725
LL | trait UncheckedCopy: Sized + AddAssign<&'static str> {
2826
| ^^^^^^^^^^^^^^^^^^^^^^^^^
2927

3028
error[E0277]: the trait bound `Self: Deref` is not satisfied
31-
--> $DIR/defaults-unsound-62211-2.rs:20:5
29+
--> $DIR/defaults-unsound-62211-2.rs:20:96
3230
|
3331
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
34-
| ^^^^^^^^^^^^^^^^^^^^-------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35-
| | |
36-
| | required by this bound in `UncheckedCopy::Output`
37-
| the trait `Deref` is not implemented for `Self`
32+
| ------------------- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Deref` is not implemented for `Self`
3833
|
3934
help: consider further restricting `Self`
4035
|
4136
LL | trait UncheckedCopy: Sized + Deref {
4237
| ^^^^^^^
4338

4439
error[E0277]: the trait bound `Self: Copy` is not satisfied
45-
--> $DIR/defaults-unsound-62211-2.rs:20:5
40+
--> $DIR/defaults-unsound-62211-2.rs:20:96
4641
|
4742
LL | type Output: Copy + Deref<Target = str> + AddAssign<&'static str> + From<Self> + Display = Self;
48-
| ^^^^^^^^^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49-
| | |
50-
| | required by this bound in `UncheckedCopy::Output`
51-
| the trait `Copy` is not implemented for `Self`
43+
| ---- required by this bound in `UncheckedCopy::Output` ^^^^ the trait `Copy` is not implemented for `Self`
5244
|
5345
help: consider further restricting `Self`
5446
|

src/test/ui/associated-types/issue-43784-associated-type.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0277]: the trait bound `T: Copy` is not satisfied
2-
--> $DIR/issue-43784-associated-type.rs:14:5
2+
--> $DIR/issue-43784-associated-type.rs:14:18
33
|
44
LL | type Assoc: Partial<Self>;
55
| ------------- required by this bound in `Complete::Assoc`
66
...
77
LL | type Assoc = T;
8-
| ^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T`
8+
| ^ the trait `Copy` is not implemented for `T`
99
|
1010
help: consider restricting type parameter `T`
1111
|

src/test/ui/associated-types/issue-43924.stderr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
error[E0277]: the trait bound `(dyn ToString + 'static): Default` is not satisfied
2-
--> $DIR/issue-43924.rs:7:5
2+
--> $DIR/issue-43924.rs:7:45
33
|
44
LL | type Out: Default + ToString + ?Sized = dyn ToString;
5-
| ^^^^^^^^^^-------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
| | |
7-
| | required by this bound in `Foo::Out`
8-
| the trait `Default` is not implemented for `(dyn ToString + 'static)`
5+
| ------- ^^^^^^^^^^^^ the trait `Default` is not implemented for `(dyn ToString + 'static)`
6+
| |
7+
| required by this bound in `Foo::Out`
98

109
error[E0599]: no function or associated item named `default` found for trait object `(dyn ToString + 'static)` in the current scope
1110
--> $DIR/issue-43924.rs:14:39

src/test/ui/associated-types/issue-54108.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0277]: cannot add `<T as SubEncoder>::ActualSize` to `<T as SubEncoder>::ActualSize`
2-
--> $DIR/issue-54108.rs:19:5
2+
--> $DIR/issue-54108.rs:19:17
33
|
44
LL | type Size: Add<Output = Self::Size>;
55
| ------------------------ required by this bound in `Encoder::Size`
66
...
77
LL | type Size = <Self as SubEncoder>::ActualSize;
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `<T as SubEncoder>::ActualSize + <T as SubEncoder>::ActualSize`
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `<T as SubEncoder>::ActualSize + <T as SubEncoder>::ActualSize`
99
|
1010
= help: the trait `Add` is not implemented for `<T as SubEncoder>::ActualSize`
1111
help: consider further restricting the associated type

src/test/ui/associated-types/issue-63593.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
error[E0277]: the size for values of type `Self` cannot be known at compilation time
2-
--> $DIR/issue-63593.rs:9:5
2+
--> $DIR/issue-63593.rs:9:17
33
|
44
LL | type This = Self;
5-
| ^^^^^^^^^^^^^^^^^
6-
| |
7-
| doesn't have a size known at compile-time
5+
| ------------^^^^-
6+
| | |
7+
| | doesn't have a size known at compile-time
88
| required by this bound in `MyTrait::This`
99
|
1010
help: consider further restricting `Self`

src/test/ui/associated-types/issue-65774-1.stderr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
error[E0277]: the trait bound `T: MyDisplay` is not satisfied
2-
--> $DIR/issue-65774-1.rs:10:5
2+
--> $DIR/issue-65774-1.rs:10:33
33
|
44
LL | type MpuConfig: MyDisplay = T;
5-
| ^^^^^^^^^^^^^^^^---------^^^^^
6-
| | |
7-
| | required by this bound in `MPU::MpuConfig`
8-
| the trait `MyDisplay` is not implemented for `T`
5+
| --------- ^ the trait `MyDisplay` is not implemented for `T`
6+
| |
7+
| required by this bound in `MPU::MpuConfig`
98

109
error[E0277]: the trait bound `T: MyDisplay` is not satisfied
1110
--> $DIR/issue-65774-1.rs:44:76

src/test/ui/associated-types/issue-65774-2.stderr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
error[E0277]: the trait bound `T: MyDisplay` is not satisfied
2-
--> $DIR/issue-65774-2.rs:10:5
2+
--> $DIR/issue-65774-2.rs:10:33
33
|
44
LL | type MpuConfig: MyDisplay = T;
5-
| ^^^^^^^^^^^^^^^^---------^^^^^
6-
| | |
7-
| | required by this bound in `MPU::MpuConfig`
8-
| the trait `MyDisplay` is not implemented for `T`
5+
| --------- ^ the trait `MyDisplay` is not implemented for `T`
6+
| |
7+
| required by this bound in `MPU::MpuConfig`
98

109
error[E0277]: the trait bound `T: MyDisplay` is not satisfied
1110
--> $DIR/issue-65774-2.rs:39:25

0 commit comments

Comments
 (0)