Skip to content

Commit 3a515ae

Browse files
committed
Use a more accurate span on assoc types WF checks
1 parent eb2226b commit 3a515ae

18 files changed

+54
-52
lines changed

compiler/rustc_typeck/src/check/wfcheck.rs

+10-8
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

+4-4
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

+4-4
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

+2-2
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

+2-2
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

+2-2
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

+2-2
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

+2-2
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

+2-2
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

+2-2
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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0491]: in type `&'a Foo<&'b i32>`, reference has a longer lifetime than the data it references
2-
--> $DIR/regions-outlives-nominal-type-type-rev.rs:17:9
2+
--> $DIR/regions-outlives-nominal-type-type-rev.rs:17:20
33
|
44
LL | type Out = &'a Foo<&'b i32>;
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-type-rev.rs:16:10

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0491]: in type `&'a Foo<&'b i32>`, reference has a longer lifetime than the data it references
2-
--> $DIR/regions-outlives-nominal-type-type.rs:17:9
2+
--> $DIR/regions-outlives-nominal-type-type.rs:17:20
33
|
44
LL | type Out = &'a Foo<&'b i32>;
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-type.rs:16:10

src/test/ui/rfc-2093-infer-outlives/regions-struct-not-wf.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error[E0309]: the parameter type `T` may not live long enough
2-
--> $DIR/regions-struct-not-wf.rs:13:5
2+
--> $DIR/regions-struct-not-wf.rs:13:16
33
|
44
LL | impl<'a, T> Trait<'a, T> for usize {
55
| - help: consider adding an explicit lifetime bound...: `T: 'a`
66
LL | type Out = &'a T;
7-
| ^^^^^^^^^^^^^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
7+
| ^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
88

99
error[E0309]: the parameter type `T` may not live long enough
10-
--> $DIR/regions-struct-not-wf.rs:21:5
10+
--> $DIR/regions-struct-not-wf.rs:21:16
1111
|
1212
LL | impl<'a, T> Trait<'a, T> for u32 {
1313
| - help: consider adding an explicit lifetime bound...: `T: 'a`
1414
LL | type Out = RefOk<'a, T>;
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
15+
| ^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
1616
|
1717
note: ...that is required by this bound
1818
--> $DIR/regions-struct-not-wf.rs:16:20
@@ -21,10 +21,10 @@ LL | struct RefOk<'a, T:'a> {
2121
| ^^
2222

2323
error[E0491]: in type `&'a &'b T`, reference has a longer lifetime than the data it references
24-
--> $DIR/regions-struct-not-wf.rs:25:5
24+
--> $DIR/regions-struct-not-wf.rs:25:16
2525
|
2626
LL | type Out = &'a &'b T;
27-
| ^^^^^^^^^^^^^^^^^^^^^
27+
| ^^^^^^^^^
2828
|
2929
note: the pointer is valid for the lifetime `'a` as defined on the impl at 24:6
3030
--> $DIR/regions-struct-not-wf.rs:24:6

src/test/ui/specialization/issue-51892.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: unconstrained generic constant
2-
--> $DIR/issue-51892.rs:15:5
2+
--> $DIR/issue-51892.rs:15:17
33
|
44
LL | type Type = [u8; std::mem::size_of::<<T as Trait>::Type>()];
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: try adding a `where` bound using this expression: `where [(); std::mem::size_of::<<T as Trait>::Type>()]:`
88

src/test/ui/wf/hir-wf-check-erase-regions.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: `&T` is not an iterator
2-
--> $DIR/hir-wf-check-erase-regions.rs:7:5
2+
--> $DIR/hir-wf-check-erase-regions.rs:7:21
33
|
44
LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&T` is not an iterator
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&T` is not an iterator
66
|
77
::: $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL
88
|

src/test/ui/wf/wf-impl-associated-type-region.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
error[E0309]: the parameter type `T` may not live long enough
2-
--> $DIR/wf-impl-associated-type-region.rs:10:5
2+
--> $DIR/wf-impl-associated-type-region.rs:10:16
33
|
44
LL | impl<'a, T> Foo<'a> for T {
55
| - help: consider adding an explicit lifetime bound...: `T: 'a`
66
LL | type Bar = &'a T;
7-
| ^^^^^^^^^^^^^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
7+
| ^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
88

99
error: aborting due to previous error
1010

src/test/ui/wf/wf-outlives-ty-in-fn-or-trait.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error[E0309]: the parameter type `T` may not live long enough
2-
--> $DIR/wf-outlives-ty-in-fn-or-trait.rs:9:5
2+
--> $DIR/wf-outlives-ty-in-fn-or-trait.rs:9:16
33
|
44
LL | impl<'a, T> Trait<'a, T> for usize {
55
| - help: consider adding an explicit lifetime bound...: `T: 'a`
66
LL | type Out = &'a fn(T);
7-
| ^^^^^^^^^^^^^^^^^^^^^ ...so that the reference type `&'a fn(T)` does not outlive the data it points at
7+
| ^^^^^^^^^ ...so that the reference type `&'a fn(T)` does not outlive the data it points at
88

99
error[E0309]: the parameter type `T` may not live long enough
10-
--> $DIR/wf-outlives-ty-in-fn-or-trait.rs:19:5
10+
--> $DIR/wf-outlives-ty-in-fn-or-trait.rs:19:16
1111
|
1212
LL | impl<'a, T> Trait<'a, T> for u32 {
1313
| - help: consider adding an explicit lifetime bound...: `T: 'a`
1414
LL | type Out = &'a dyn Baz<T>;
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the reference type `&'a (dyn Baz<T> + 'a)` does not outlive the data it points at
15+
| ^^^^^^^^^^^^^^ ...so that the reference type `&'a (dyn Baz<T> + 'a)` does not outlive the data it points at
1616

1717
error: aborting due to 2 previous errors
1818

src/test/ui/wf/wf-trait-associated-type-region.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0309]: the associated type `<Self as SomeTrait<'a>>::Type1` may not live long enough
2-
--> $DIR/wf-trait-associated-type-region.rs:9:5
2+
--> $DIR/wf-trait-associated-type-region.rs:9:18
33
|
44
LL | type Type2 = &'a Self::Type1;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^
66
|
77
= help: consider adding an explicit lifetime bound `<Self as SomeTrait<'a>>::Type1: 'a`...
88
= note: ...so that the reference type `&'a <Self as SomeTrait<'a>>::Type1` does not outlive the data it points at

0 commit comments

Comments
 (0)