Skip to content

Commit c046d62

Browse files
committed
Use a more accurate span on assoc types WF checks
1 parent eaf6f46 commit c046d62

17 files changed

+52
-50
lines changed

compiler/rustc_typeck/src/check/wfcheck.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,13 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
194194
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
195195
let trait_item = tcx.hir().expect_trait_item(hir_id);
196196

197-
let method_sig = match trait_item.kind {
198-
hir::TraitItemKind::Fn(ref sig, _) => Some(sig),
199-
_ => None,
197+
let (method_sig, span) = match trait_item.kind {
198+
hir::TraitItemKind::Fn(ref sig, _) => (Some(sig), trait_item.span),
199+
hir::TraitItemKind::Type(_bounds, Some(ty)) => (None, ty.span),
200+
_ => (None, trait_item.span),
200201
};
201202
check_object_unsafe_self_trait_by_name(tcx, &trait_item);
202-
check_associated_item(tcx, trait_item.hir_id(), trait_item.span, method_sig);
203+
check_associated_item(tcx, trait_item.hir_id(), span, method_sig);
203204
}
204205

205206
fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
@@ -268,12 +269,13 @@ pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
268269
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
269270
let impl_item = tcx.hir().expect_impl_item(hir_id);
270271

271-
let method_sig = match impl_item.kind {
272-
hir::ImplItemKind::Fn(ref sig, _) => Some(sig),
273-
_ => None,
272+
let (method_sig, span) = match impl_item.kind {
273+
hir::ImplItemKind::Fn(ref sig, _) => (Some(sig), impl_item.span),
274+
hir::ImplItemKind::TyAlias(ty) => (None, ty.span),
275+
_ => (None, impl_item.span),
274276
};
275277

276-
check_associated_item(tcx, impl_item.hir_id(), impl_item.span, method_sig);
278+
check_associated_item(tcx, impl_item.hir_id(), span, method_sig);
277279
}
278280

279281
fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {

src/test/ui/associated-types/defaults-cyclic-fail-1.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B == _`
2-
--> $DIR/defaults-cyclic-fail-1.rs:26:5
2+
--> $DIR/defaults-cyclic-fail-1.rs:26:14
33
|
44
LL | type A = Box<Self::B>;
5-
| ^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^
66

77
error[E0275]: overflow evaluating the requirement `<usize as Tr>::A == _`
8-
--> $DIR/defaults-cyclic-fail-1.rs:32:5
8+
--> $DIR/defaults-cyclic-fail-1.rs:32:14
99
|
1010
LL | type B = &'static Self::A;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^
1212

1313
error: aborting due to 2 previous errors
1414

src/test/ui/associated-types/defaults-cyclic-fail-2.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B == _`
2-
--> $DIR/defaults-cyclic-fail-2.rs:27:5
2+
--> $DIR/defaults-cyclic-fail-2.rs:27:14
33
|
44
LL | type A = Box<Self::B>;
5-
| ^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^
66

77
error[E0275]: overflow evaluating the requirement `<usize as Tr>::A == _`
8-
--> $DIR/defaults-cyclic-fail-2.rs:33:5
8+
--> $DIR/defaults-cyclic-fail-2.rs:33:14
99
|
1010
LL | type B = &'static Self::A;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^
1212

1313
error: aborting due to 2 previous errors
1414

src/test/ui/generic-associated-types/projection-bound-cycle-generic.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0275]: overflow evaluating the requirement `<T as Foo>::Item: Sized`
2-
--> $DIR/projection-bound-cycle-generic.rs:44:5
2+
--> $DIR/projection-bound-cycle-generic.rs:44:18
33
|
44
LL | struct OnlySized<T> where T: Sized { f: T }
55
| - required by this bound in `OnlySized`
66
...
77
LL | type Assoc = OnlySized<<T as Foo>::Item>;
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
99

1010
error: aborting due to previous error
1111

src/test/ui/generic-associated-types/projection-bound-cycle.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0275]: overflow evaluating the requirement `<T as Foo>::Item: Sized`
2-
--> $DIR/projection-bound-cycle.rs:46:5
2+
--> $DIR/projection-bound-cycle.rs:46:18
33
|
44
LL | struct OnlySized<T> where T: Sized { f: T }
55
| - required by this bound in `OnlySized`
66
...
77
LL | type Assoc = OnlySized<<T as Foo>::Item>;
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
99

1010
error: aborting due to previous error
1111

src/test/ui/issues/issue-21946.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0275]: overflow evaluating the requirement `<FooStruct as Foo>::A == _`
2-
--> $DIR/issue-21946.rs:8:5
2+
--> $DIR/issue-21946.rs:8:14
33
|
44
LL | type A = <FooStruct as Foo>::A;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^
66

77
error: aborting due to previous error
88

src/test/ui/issues/issue-23122-1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0275]: overflow evaluating the requirement `<GetNext<T> as Next>::Next == _`
2-
--> $DIR/issue-23122-1.rs:10:5
2+
--> $DIR/issue-23122-1.rs:10:17
33
|
44
LL | type Next = <GetNext<T> as Next>::Next;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error: aborting due to previous error
88

src/test/ui/issues/issue-23122-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0275]: overflow evaluating the requirement `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<T as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next: Sized`
2-
--> $DIR/issue-23122-2.rs:9:5
2+
--> $DIR/issue-23122-2.rs:9:17
33
|
44
LL | type Next = <GetNext<T::Next> as Next>::Next;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`issue_23122_2`)
88
note: required because of the requirements on the impl of `Next` for `GetNext<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<T as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next>`

src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-region-rev.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0491]: in type `&'a Foo<'b>`, reference has a longer lifetime than the data it references
2-
--> $DIR/regions-outlives-nominal-type-region-rev.rs:17:9
2+
--> $DIR/regions-outlives-nominal-type-region-rev.rs:17:20
33
|
44
LL | type Out = &'a Foo<'b>;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^
66
|
77
note: the pointer is valid for the lifetime `'a` as defined on the impl at 16:10
88
--> $DIR/regions-outlives-nominal-type-region-rev.rs:16:10

src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-region.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0491]: in type `&'a Foo<'b>`, reference has a longer lifetime than the data it references
2-
--> $DIR/regions-outlives-nominal-type-region.rs:17:9
2+
--> $DIR/regions-outlives-nominal-type-region.rs:17:20
33
|
44
LL | type Out = &'a Foo<'b>;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^
66
|
77
note: the pointer is valid for the lifetime `'a` as defined on the impl at 16:10
88
--> $DIR/regions-outlives-nominal-type-region.rs:16:10

0 commit comments

Comments
 (0)