Skip to content

Commit 6166cd6

Browse files
committed
Avoid looking at HIR for trait and impl items
1 parent 70215df commit 6166cd6

22 files changed

+67
-79
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -328,23 +328,14 @@ fn check_trait_item<'tcx>(
328328
) -> Result<(), ErrorGuaranteed> {
329329
let def_id = trait_item.owner_id.def_id;
330330

331-
let span = match trait_item.kind {
332-
hir::TraitItemKind::Type(_bounds, Some(ty)) => ty.span,
333-
_ => trait_item.span,
334-
};
335-
336331
// Check that an item definition in a subtrait is shadowing a supertrait item.
337332
lint_item_shadowing_supertrait_item(tcx, def_id);
338333

339-
let mut res = check_associated_item(tcx, def_id, span);
334+
let mut res = check_associated_item(tcx, def_id);
340335

341336
if matches!(trait_item.kind, hir::TraitItemKind::Fn(..)) {
342337
for &assoc_ty_def_id in tcx.associated_types_for_impl_traits_in_associated_fn(def_id) {
343-
res = res.and(check_associated_item(
344-
tcx,
345-
assoc_ty_def_id.expect_local(),
346-
tcx.def_span(assoc_ty_def_id),
347-
));
338+
res = res.and(check_associated_item(tcx, assoc_ty_def_id.expect_local()));
348339
}
349340
}
350341
res
@@ -827,12 +818,7 @@ fn check_impl_item<'tcx>(
827818
tcx: TyCtxt<'tcx>,
828819
impl_item: &'tcx hir::ImplItem<'tcx>,
829820
) -> Result<(), ErrorGuaranteed> {
830-
let span = match impl_item.kind {
831-
// Constrain binding and overflow error spans to `<Ty>` in `type foo = <Ty>`.
832-
hir::ImplItemKind::Type(ty) if ty.span != DUMMY_SP => ty.span,
833-
_ => impl_item.span,
834-
};
835-
check_associated_item(tcx, impl_item.owner_id.def_id, span)
821+
check_associated_item(tcx, impl_item.owner_id.def_id)
836822
}
837823

838824
fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), ErrorGuaranteed> {
@@ -960,12 +946,8 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), Er
960946
}
961947
}
962948

963-
#[instrument(level = "debug", skip(tcx, span))]
964-
fn check_associated_item(
965-
tcx: TyCtxt<'_>,
966-
item_id: LocalDefId,
967-
span: Span,
968-
) -> Result<(), ErrorGuaranteed> {
949+
#[instrument(level = "debug", skip(tcx))]
950+
fn check_associated_item(tcx: TyCtxt<'_>, item_id: LocalDefId) -> Result<(), ErrorGuaranteed> {
969951
let loc = Some(WellFormedLoc::Ty(item_id));
970952
enter_wf_checking_ctxt(tcx, item_id, |wfcx| {
971953
let item = tcx.associated_item(item_id);
@@ -982,6 +964,8 @@ fn check_associated_item(
982964
}
983965
};
984966

967+
let span = tcx.def_span(item_id);
968+
985969
match item.kind {
986970
ty::AssocKind::Const { .. } => {
987971
let ty = tcx.type_of(item.def_id).instantiate_identity();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: overflow evaluating associated type `Carrier<'b>::Focus<i32>`
2-
--> $DIR/issue-111879-0.rs:9:25
2+
--> $DIR/issue-111879-0.rs:9:5
33
|
44
LL | pub type Focus<T> = &'a mut for<'b> fn(Carrier<'b>::Focus<i32>);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^
66

77
error: aborting due to 1 previous error
88

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: overflow evaluating associated type `T::This`
2-
--> $DIR/normalization-overflow.rs:9:17
2+
--> $DIR/normalization-overflow.rs:9:5
33
|
44
LL | type This = Self::This;
5-
| ^^^^^^^^^^
5+
| ^^^^^^^^^
66

77
error: aborting due to 1 previous error
88

tests/ui/associated-inherent-types/regionck-1.stderr

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
error[E0309]: the parameter type `T` may not live long enough
2-
--> $DIR/regionck-1.rs:9:30
2+
--> $DIR/regionck-1.rs:9:5
33
|
44
LL | type NoTyOutliv<'a, T> = &'a T;
5-
| -- ^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
6-
| |
7-
| the parameter type `T` must be valid for the lifetime `'a` as defined here...
5+
| ^^^^^^^^^^^^^^^^--^^^^
6+
| | |
7+
| | the parameter type `T` must be valid for the lifetime `'a` as defined here...
8+
| ...so that the reference type `&'a T` does not outlive the data it points at
89
|
910
help: consider adding an explicit lifetime bound
1011
|
1112
LL | type NoTyOutliv<'a, T: 'a> = &'a T;
1213
| ++++
1314

1415
error[E0491]: in type `&'a &'b ()`, reference has a longer lifetime than the data it references
15-
--> $DIR/regionck-1.rs:10:31
16+
--> $DIR/regionck-1.rs:10:5
1617
|
1718
LL | type NoReOutliv<'a, 'b> = &'a &'b ();
18-
| ^^^^^^^^^^
19+
| ^^^^^^^^^^^^^^^^^^^^^^^
1920
|
2021
note: the pointer is valid for the lifetime `'a` as defined here
2122
--> $DIR/regionck-1.rs:10:21

tests/ui/const-generics/issues/issue-71202.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | | const VALUE: bool = false;
77
... |
88
LL | | <IsCopy<T>>::VALUE
99
LL | | } as usize] = [];
10-
| |_____________________^
10+
| |_______________^
1111
|
1212
help: try adding a `where` bound
1313
|

tests/ui/generic-associated-types/bugs/issue-87735.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ LL | impl<'b, T, U> AsRef2 for Foo<T>
55
| ^ unconstrained type parameter
66

77
error[E0309]: the parameter type `U` may not live long enough
8-
--> $DIR/issue-87735.rs:34:21
8+
--> $DIR/issue-87735.rs:34:3
99
|
1010
LL | type Output<'a> = FooRef<'a, U> where Self: 'a;
11-
| -- ^^^^^^^^^^^^^ ...so that the type `U` will meet its required lifetime bounds...
12-
| |
13-
| the parameter type `U` must be valid for the lifetime `'a` as defined here...
11+
| ^^^^^^^^^^^^--^
12+
| | |
13+
| | the parameter type `U` must be valid for the lifetime `'a` as defined here...
14+
| ...so that the type `U` will meet its required lifetime bounds...
1415
|
1516
note: ...that is required by this bound
1617
--> $DIR/issue-87735.rs:23:22

tests/ui/generic-associated-types/bugs/issue-88526.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ LL | impl<'q, Q, I, F> A for TestB<Q, F>
55
| ^ unconstrained type parameter
66

77
error[E0309]: the parameter type `F` may not live long enough
8-
--> $DIR/issue-88526.rs:16:18
8+
--> $DIR/issue-88526.rs:16:5
99
|
1010
LL | type I<'a> = &'a F;
11-
| -- ^^^^^ ...so that the reference type `&'a F` does not outlive the data it points at
12-
| |
13-
| the parameter type `F` must be valid for the lifetime `'a` as defined here...
11+
| ^^^^^^^--^
12+
| | |
13+
| | the parameter type `F` must be valid for the lifetime `'a` as defined here...
14+
| ...so that the reference type `&'a F` does not outlive the data it points at
1415
|
1516
help: consider adding an explicit lifetime bound
1617
|

tests/ui/generic-associated-types/issue-84931.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ LL | type Item<'a> = &'a mut T where Self: 'a;
1818
| ++++++++++++++
1919

2020
error[E0309]: the parameter type `T` may not live long enough
21-
--> $DIR/issue-84931.rs:14:21
21+
--> $DIR/issue-84931.rs:14:5
2222
|
2323
LL | type Item<'a> = &'a mut T;
24-
| -- ^^^^^^^^^ ...so that the reference type `&'a mut T` does not outlive the data it points at
25-
| |
26-
| the parameter type `T` must be valid for the lifetime `'a` as defined here...
24+
| ^^^^^^^^^^--^
25+
| | |
26+
| | the parameter type `T` must be valid for the lifetime `'a` as defined here...
27+
| ...so that the reference type `&'a mut T` does not outlive the data it points at
2728
|
2829
help: consider adding an explicit lifetime bound
2930
|

tests/ui/generic-const-items/evaluatable-bounds.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unconstrained generic constant
22
--> $DIR/evaluatable-bounds.rs:14:5
33
|
44
LL | const ARRAY: [i32; Self::LEN];
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
help: try adding a `where` bound
88
|

tests/ui/higher-ranked/trait-bounds/normalize-under-binder/issue-89118.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ LL | Ctx<()>: for<'a> BufferUdpStateContext<&'a ()>;
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `EthernetWorker`
5454

5555
error[E0277]: the trait bound `for<'a> &'a (): BufferMut` is not satisfied
56-
--> $DIR/issue-89118.rs:22:20
56+
--> $DIR/issue-89118.rs:22:5
5757
|
5858
LL | type Handler = Ctx<C::Dispatcher>;
59-
| ^^^^^^^^^^^^^^^^^^ the trait `for<'a> BufferMut` is not implemented for `&'a ()`
59+
| ^^^^^^^^^^^^ the trait `for<'a> BufferMut` is not implemented for `&'a ()`
6060
|
6161
help: this trait has no implementations, consider adding one
6262
--> $DIR/issue-89118.rs:1:1

tests/ui/implied-bounds/impl-header-unnormalized-types.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 &'b ()`, reference has a longer lifetime than the data it references
2-
--> $DIR/impl-header-unnormalized-types.rs:15:18
2+
--> $DIR/impl-header-unnormalized-types.rs:15:5
33
|
44
LL | type Assoc = &'a &'b ();
5-
| ^^^^^^^^^^
5+
| ^^^^^^^^^^
66
|
77
note: the pointer is valid for the lifetime `'a` as defined here
88
--> $DIR/impl-header-unnormalized-types.rs:14:6

tests/ui/regions/lifetime-not-long-enough-suggestion-regression-test-124563.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0478]: lifetime bound not satisfied
2-
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:19:16
2+
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:19:5
33
|
44
LL | type Bar = BarImpl<'a, 'b, T>;
5-
| ^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^
66
|
77
note: lifetime parameter instantiated with the lifetime `'a` as defined here
88
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:14:6

tests/ui/rfcs/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:20
2+
--> $DIR/regions-outlives-nominal-type-region-rev.rs:17:9
33
|
44
LL | type Out = &'a Foo<'b>;
5-
| ^^^^^^^^^^^
5+
| ^^^^^^^^
66
|
77
note: the pointer is valid for the lifetime `'a` as defined here
88
--> $DIR/regions-outlives-nominal-type-region-rev.rs:16:10

tests/ui/rfcs/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:20
2+
--> $DIR/regions-outlives-nominal-type-region.rs:17:9
33
|
44
LL | type Out = &'a Foo<'b>;
5-
| ^^^^^^^^^^^
5+
| ^^^^^^^^
66
|
77
note: the pointer is valid for the lifetime `'a` as defined here
88
--> $DIR/regions-outlives-nominal-type-region.rs:16:10

tests/ui/rfcs/rfc-2093-infer-outlives/regions-outlives-nominal-type-type-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 i32>`, reference has a longer lifetime than the data it references
2-
--> $DIR/regions-outlives-nominal-type-type-rev.rs:17:20
2+
--> $DIR/regions-outlives-nominal-type-type-rev.rs:17:9
33
|
44
LL | type Out = &'a Foo<&'b i32>;
5-
| ^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^
66
|
77
note: the pointer is valid for the lifetime `'a` as defined here
88
--> $DIR/regions-outlives-nominal-type-type-rev.rs:16:10

tests/ui/rfcs/rfc-2093-infer-outlives/regions-outlives-nominal-type-type.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 i32>`, reference has a longer lifetime than the data it references
2-
--> $DIR/regions-outlives-nominal-type-type.rs:17:20
2+
--> $DIR/regions-outlives-nominal-type-type.rs:17:9
33
|
44
LL | type Out = &'a Foo<&'b i32>;
5-
| ^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^
66
|
77
note: the pointer is valid for the lifetime `'a` as defined here
88
--> $DIR/regions-outlives-nominal-type-type.rs:16:10

tests/ui/rfcs/rfc-2093-infer-outlives/regions-struct-not-wf.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error[E0309]: the parameter type `T` may not live long enough
2-
--> $DIR/regions-struct-not-wf.rs:13:16
2+
--> $DIR/regions-struct-not-wf.rs:13:5
33
|
44
LL | impl<'a, T> Trait<'a, T> for usize {
55
| -- the parameter type `T` must be valid for the lifetime `'a` as defined here...
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
help: consider adding an explicit lifetime bound
1010
|
1111
LL | impl<'a, T: 'a> Trait<'a, T> for usize {
1212
| ++++
1313

1414
error[E0309]: the parameter type `T` may not live long enough
15-
--> $DIR/regions-struct-not-wf.rs:21:16
15+
--> $DIR/regions-struct-not-wf.rs:21:5
1616
|
1717
LL | impl<'a, T> Trait<'a, T> for u32 {
1818
| -- the parameter type `T` must be valid for the lifetime `'a` as defined here...
1919
LL | type Out = RefOk<'a, T>;
20-
| ^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
20+
| ^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
2121
|
2222
note: ...that is required by this bound
2323
--> $DIR/regions-struct-not-wf.rs:16:20
@@ -30,10 +30,10 @@ LL | impl<'a, T: 'a> Trait<'a, T> for u32 {
3030
| ++++
3131

3232
error[E0491]: in type `&'a &'b T`, reference has a longer lifetime than the data it references
33-
--> $DIR/regions-struct-not-wf.rs:25:16
33+
--> $DIR/regions-struct-not-wf.rs:25:5
3434
|
3535
LL | type Out = &'a &'b T;
36-
| ^^^^^^^^^
36+
| ^^^^^^^^
3737
|
3838
note: the pointer is valid for the lifetime `'a` as defined here
3939
--> $DIR/regions-struct-not-wf.rs:24:6

tests/ui/specialization/issue-51892.stderr

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

tests/ui/wf/hir-wf-check-erase-regions.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ note: required by a bound in `std::iter::IntoIterator::IntoIter`
1111
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
1212

1313
error[E0277]: `&'a T` is not an iterator
14-
--> $DIR/hir-wf-check-erase-regions.rs:7:21
14+
--> $DIR/hir-wf-check-erase-regions.rs:7:5
1515
|
1616
LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>;
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&'a T` is not an iterator
17+
| ^^^^^^^^^^^^^ `&'a T` is not an iterator
1818
|
1919
= help: the trait `Iterator` is not implemented for `&'a T`
2020
= help: the trait `Iterator` is implemented for `&mut I`

tests/ui/wf/wf-impl-associated-type-region.stderr

Lines changed: 2 additions & 2 deletions
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:16
2+
--> $DIR/wf-impl-associated-type-region.rs:10:5
33
|
44
LL | impl<'a, T> Foo<'a> for T {
55
| -- the parameter type `T` must be valid for the lifetime `'a` as defined here...
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
help: consider adding an explicit lifetime bound
1010
|

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error[E0309]: the parameter type `T` may not live long enough
2-
--> $DIR/wf-outlives-ty-in-fn-or-trait.rs:9:16
2+
--> $DIR/wf-outlives-ty-in-fn-or-trait.rs:9:5
33
|
44
LL | impl<'a, T> Trait<'a, T> for usize {
55
| -- the parameter type `T` must be valid for the lifetime `'a` as defined here...
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
help: consider adding an explicit lifetime bound
1010
|
1111
LL | impl<'a, T: 'a> Trait<'a, T> for usize {
1212
| ++++
1313

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

tests/ui/wf/wf-trait-associated-type-region.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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:18
2+
--> $DIR/wf-trait-associated-type-region.rs:9:5
33
|
44
LL | trait SomeTrait<'a> {
55
| -- the associated type `<Self as SomeTrait<'a>>::Type1` must be valid for the lifetime `'a` as defined here...
66
LL | type Type1;
77
LL | type Type2 = &'a Self::Type1;
8-
| ^^^^^^^^^^^^^^^ ...so that the reference type `&'a <Self as SomeTrait<'a>>::Type1` does not outlive the data it points at
8+
| ^^^^^^^^^^ ...so that the reference type `&'a <Self as SomeTrait<'a>>::Type1` does not outlive the data it points at
99
|
1010
help: consider adding an explicit lifetime bound
1111
|

0 commit comments

Comments
 (0)