Avoid looking at HIR for trait and impl items
This commit is contained in:
@@ -328,23 +328,14 @@ fn check_trait_item<'tcx>(
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let def_id = trait_item.owner_id.def_id;
|
||||
|
||||
let span = match trait_item.kind {
|
||||
hir::TraitItemKind::Type(_bounds, Some(ty)) => ty.span,
|
||||
_ => trait_item.span,
|
||||
};
|
||||
|
||||
// Check that an item definition in a subtrait is shadowing a supertrait item.
|
||||
lint_item_shadowing_supertrait_item(tcx, def_id);
|
||||
|
||||
let mut res = check_associated_item(tcx, def_id, span);
|
||||
let mut res = check_associated_item(tcx, def_id);
|
||||
|
||||
if matches!(trait_item.kind, hir::TraitItemKind::Fn(..)) {
|
||||
for &assoc_ty_def_id in tcx.associated_types_for_impl_traits_in_associated_fn(def_id) {
|
||||
res = res.and(check_associated_item(
|
||||
tcx,
|
||||
assoc_ty_def_id.expect_local(),
|
||||
tcx.def_span(assoc_ty_def_id),
|
||||
));
|
||||
res = res.and(check_associated_item(tcx, assoc_ty_def_id.expect_local()));
|
||||
}
|
||||
}
|
||||
res
|
||||
@@ -827,12 +818,7 @@ fn check_impl_item<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
impl_item: &'tcx hir::ImplItem<'tcx>,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let span = match impl_item.kind {
|
||||
// Constrain binding and overflow error spans to `<Ty>` in `type foo = <Ty>`.
|
||||
hir::ImplItemKind::Type(ty) if ty.span != DUMMY_SP => ty.span,
|
||||
_ => impl_item.span,
|
||||
};
|
||||
check_associated_item(tcx, impl_item.owner_id.def_id, span)
|
||||
check_associated_item(tcx, impl_item.owner_id.def_id)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(tcx, span))]
|
||||
fn check_associated_item(
|
||||
tcx: TyCtxt<'_>,
|
||||
item_id: LocalDefId,
|
||||
span: Span,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
#[instrument(level = "debug", skip(tcx))]
|
||||
fn check_associated_item(tcx: TyCtxt<'_>, item_id: LocalDefId) -> Result<(), ErrorGuaranteed> {
|
||||
let loc = Some(WellFormedLoc::Ty(item_id));
|
||||
enter_wf_checking_ctxt(tcx, item_id, |wfcx| {
|
||||
let item = tcx.associated_item(item_id);
|
||||
@@ -982,6 +964,8 @@ fn check_associated_item(
|
||||
}
|
||||
};
|
||||
|
||||
let span = tcx.def_span(item_id);
|
||||
|
||||
match item.kind {
|
||||
ty::AssocKind::Const { .. } => {
|
||||
let ty = tcx.type_of(item.def_id).instantiate_identity();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error: overflow evaluating associated type `Carrier<'b>::Focus<i32>`
|
||||
--> $DIR/issue-111879-0.rs:9:25
|
||||
--> $DIR/issue-111879-0.rs:9:5
|
||||
|
|
||||
LL | pub type Focus<T> = &'a mut for<'b> fn(Carrier<'b>::Focus<i32>);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error: overflow evaluating associated type `T::This`
|
||||
--> $DIR/normalization-overflow.rs:9:17
|
||||
--> $DIR/normalization-overflow.rs:9:5
|
||||
|
|
||||
LL | type This = Self::This;
|
||||
| ^^^^^^^^^^
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
error[E0309]: the parameter type `T` may not live long enough
|
||||
--> $DIR/regionck-1.rs:9:30
|
||||
--> $DIR/regionck-1.rs:9:5
|
||||
|
|
||||
LL | type NoTyOutliv<'a, T> = &'a T;
|
||||
| -- ^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
|
||||
| |
|
||||
| the parameter type `T` must be valid for the lifetime `'a` as defined here...
|
||||
| ^^^^^^^^^^^^^^^^--^^^^
|
||||
| | |
|
||||
| | the parameter type `T` must be valid for the lifetime `'a` as defined here...
|
||||
| ...so that the reference type `&'a T` does not outlive the data it points at
|
||||
|
|
||||
help: consider adding an explicit lifetime bound
|
||||
|
|
||||
@@ -12,10 +13,10 @@ LL | type NoTyOutliv<'a, T: 'a> = &'a T;
|
||||
| ++++
|
||||
|
||||
error[E0491]: in type `&'a &'b ()`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regionck-1.rs:10:31
|
||||
--> $DIR/regionck-1.rs:10:5
|
||||
|
|
||||
LL | type NoReOutliv<'a, 'b> = &'a &'b ();
|
||||
| ^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime `'a` as defined here
|
||||
--> $DIR/regionck-1.rs:10:21
|
||||
|
||||
@@ -7,7 +7,7 @@ LL | | const VALUE: bool = false;
|
||||
... |
|
||||
LL | | <IsCopy<T>>::VALUE
|
||||
LL | | } as usize] = [];
|
||||
| |_____________________^
|
||||
| |_______________^
|
||||
|
|
||||
help: try adding a `where` bound
|
||||
|
|
||||
|
||||
@@ -5,12 +5,13 @@ LL | impl<'b, T, U> AsRef2 for Foo<T>
|
||||
| ^ unconstrained type parameter
|
||||
|
||||
error[E0309]: the parameter type `U` may not live long enough
|
||||
--> $DIR/issue-87735.rs:34:21
|
||||
--> $DIR/issue-87735.rs:34:3
|
||||
|
|
||||
LL | type Output<'a> = FooRef<'a, U> where Self: 'a;
|
||||
| -- ^^^^^^^^^^^^^ ...so that the type `U` will meet its required lifetime bounds...
|
||||
| |
|
||||
| the parameter type `U` must be valid for the lifetime `'a` as defined here...
|
||||
| ^^^^^^^^^^^^--^
|
||||
| | |
|
||||
| | the parameter type `U` must be valid for the lifetime `'a` as defined here...
|
||||
| ...so that the type `U` will meet its required lifetime bounds...
|
||||
|
|
||||
note: ...that is required by this bound
|
||||
--> $DIR/issue-87735.rs:23:22
|
||||
|
||||
@@ -5,12 +5,13 @@ LL | impl<'q, Q, I, F> A for TestB<Q, F>
|
||||
| ^ unconstrained type parameter
|
||||
|
||||
error[E0309]: the parameter type `F` may not live long enough
|
||||
--> $DIR/issue-88526.rs:16:18
|
||||
--> $DIR/issue-88526.rs:16:5
|
||||
|
|
||||
LL | type I<'a> = &'a F;
|
||||
| -- ^^^^^ ...so that the reference type `&'a F` does not outlive the data it points at
|
||||
| |
|
||||
| the parameter type `F` must be valid for the lifetime `'a` as defined here...
|
||||
| ^^^^^^^--^
|
||||
| | |
|
||||
| | the parameter type `F` must be valid for the lifetime `'a` as defined here...
|
||||
| ...so that the reference type `&'a F` does not outlive the data it points at
|
||||
|
|
||||
help: consider adding an explicit lifetime bound
|
||||
|
|
||||
|
||||
@@ -18,12 +18,13 @@ LL | type Item<'a> = &'a mut T where Self: 'a;
|
||||
| ++++++++++++++
|
||||
|
||||
error[E0309]: the parameter type `T` may not live long enough
|
||||
--> $DIR/issue-84931.rs:14:21
|
||||
--> $DIR/issue-84931.rs:14:5
|
||||
|
|
||||
LL | type Item<'a> = &'a mut T;
|
||||
| -- ^^^^^^^^^ ...so that the reference type `&'a mut T` does not outlive the data it points at
|
||||
| |
|
||||
| the parameter type `T` must be valid for the lifetime `'a` as defined here...
|
||||
| ^^^^^^^^^^--^
|
||||
| | |
|
||||
| | the parameter type `T` must be valid for the lifetime `'a` as defined here...
|
||||
| ...so that the reference type `&'a mut T` does not outlive the data it points at
|
||||
|
|
||||
help: consider adding an explicit lifetime bound
|
||||
|
|
||||
|
||||
@@ -2,7 +2,7 @@ error: unconstrained generic constant
|
||||
--> $DIR/evaluatable-bounds.rs:14:5
|
||||
|
|
||||
LL | const ARRAY: [i32; Self::LEN];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: try adding a `where` bound
|
||||
|
|
||||
|
||||
@@ -53,10 +53,10 @@ LL | Ctx<()>: for<'a> BufferUdpStateContext<&'a ()>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `EthernetWorker`
|
||||
|
||||
error[E0277]: the trait bound `for<'a> &'a (): BufferMut` is not satisfied
|
||||
--> $DIR/issue-89118.rs:22:20
|
||||
--> $DIR/issue-89118.rs:22:5
|
||||
|
|
||||
LL | type Handler = Ctx<C::Dispatcher>;
|
||||
| ^^^^^^^^^^^^^^^^^^ the trait `for<'a> BufferMut` is not implemented for `&'a ()`
|
||||
| ^^^^^^^^^^^^ the trait `for<'a> BufferMut` is not implemented for `&'a ()`
|
||||
|
|
||||
help: this trait has no implementations, consider adding one
|
||||
--> $DIR/issue-89118.rs:1:1
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error[E0491]: in type `&'a &'b ()`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/impl-header-unnormalized-types.rs:15:18
|
||||
--> $DIR/impl-header-unnormalized-types.rs:15:5
|
||||
|
|
||||
LL | type Assoc = &'a &'b ();
|
||||
| ^^^^^^^^^^
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error[E0478]: lifetime bound not satisfied
|
||||
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:19:16
|
||||
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:19:5
|
||||
|
|
||||
LL | type Bar = BarImpl<'a, 'b, T>;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: lifetime parameter instantiated with the lifetime `'a` as defined here
|
||||
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:14:6
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error[E0491]: in type `&'a Foo<'b>`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regions-outlives-nominal-type-region-rev.rs:17:20
|
||||
--> $DIR/regions-outlives-nominal-type-region-rev.rs:17:9
|
||||
|
|
||||
LL | type Out = &'a Foo<'b>;
|
||||
| ^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime `'a` as defined here
|
||||
--> $DIR/regions-outlives-nominal-type-region-rev.rs:16:10
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error[E0491]: in type `&'a Foo<'b>`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regions-outlives-nominal-type-region.rs:17:20
|
||||
--> $DIR/regions-outlives-nominal-type-region.rs:17:9
|
||||
|
|
||||
LL | type Out = &'a Foo<'b>;
|
||||
| ^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime `'a` as defined here
|
||||
--> $DIR/regions-outlives-nominal-type-region.rs:16:10
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error[E0491]: in type `&'a Foo<&'b i32>`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regions-outlives-nominal-type-type-rev.rs:17:20
|
||||
--> $DIR/regions-outlives-nominal-type-type-rev.rs:17:9
|
||||
|
|
||||
LL | type Out = &'a Foo<&'b i32>;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime `'a` as defined here
|
||||
--> $DIR/regions-outlives-nominal-type-type-rev.rs:16:10
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error[E0491]: in type `&'a Foo<&'b i32>`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regions-outlives-nominal-type-type.rs:17:20
|
||||
--> $DIR/regions-outlives-nominal-type-type.rs:17:9
|
||||
|
|
||||
LL | type Out = &'a Foo<&'b i32>;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime `'a` as defined here
|
||||
--> $DIR/regions-outlives-nominal-type-type.rs:16:10
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
error[E0309]: the parameter type `T` may not live long enough
|
||||
--> $DIR/regions-struct-not-wf.rs:13:16
|
||||
--> $DIR/regions-struct-not-wf.rs:13:5
|
||||
|
|
||||
LL | impl<'a, T> Trait<'a, T> for usize {
|
||||
| -- the parameter type `T` must be valid for the lifetime `'a` as defined here...
|
||||
LL | type Out = &'a T;
|
||||
| ^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
|
||||
| ^^^^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
|
||||
|
|
||||
help: consider adding an explicit lifetime bound
|
||||
|
|
||||
@@ -12,12 +12,12 @@ LL | impl<'a, T: 'a> Trait<'a, T> for usize {
|
||||
| ++++
|
||||
|
||||
error[E0309]: the parameter type `T` may not live long enough
|
||||
--> $DIR/regions-struct-not-wf.rs:21:16
|
||||
--> $DIR/regions-struct-not-wf.rs:21:5
|
||||
|
|
||||
LL | impl<'a, T> Trait<'a, T> for u32 {
|
||||
| -- the parameter type `T` must be valid for the lifetime `'a` as defined here...
|
||||
LL | type Out = RefOk<'a, T>;
|
||||
| ^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
|
||||
| ^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
|
||||
|
|
||||
note: ...that is required by this bound
|
||||
--> $DIR/regions-struct-not-wf.rs:16:20
|
||||
@@ -30,10 +30,10 @@ LL | impl<'a, T: 'a> Trait<'a, T> for u32 {
|
||||
| ++++
|
||||
|
||||
error[E0491]: in type `&'a &'b T`, reference has a longer lifetime than the data it references
|
||||
--> $DIR/regions-struct-not-wf.rs:25:16
|
||||
--> $DIR/regions-struct-not-wf.rs:25:5
|
||||
|
|
||||
LL | type Out = &'a &'b T;
|
||||
| ^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
note: the pointer is valid for the lifetime `'a` as defined here
|
||||
--> $DIR/regions-struct-not-wf.rs:24:6
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
error: unconstrained generic constant
|
||||
--> $DIR/issue-51892.rs:14:17
|
||||
--> $DIR/issue-51892.rs:14:5
|
||||
|
|
||||
LL | type Type = [u8; std::mem::size_of::<<T as Trait>::Type>()];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: try adding a `where` bound
|
||||
|
|
||||
|
||||
@@ -11,10 +11,10 @@ note: required by a bound in `std::iter::IntoIterator::IntoIter`
|
||||
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
||||
|
||||
error[E0277]: `&'a T` is not an iterator
|
||||
--> $DIR/hir-wf-check-erase-regions.rs:7:21
|
||||
--> $DIR/hir-wf-check-erase-regions.rs:7:5
|
||||
|
|
||||
LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&'a T` is not an iterator
|
||||
| ^^^^^^^^^^^^^ `&'a T` is not an iterator
|
||||
|
|
||||
= help: the trait `Iterator` is not implemented for `&'a T`
|
||||
= help: the trait `Iterator` is implemented for `&mut I`
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
error[E0309]: the parameter type `T` may not live long enough
|
||||
--> $DIR/wf-impl-associated-type-region.rs:10:16
|
||||
--> $DIR/wf-impl-associated-type-region.rs:10:5
|
||||
|
|
||||
LL | impl<'a, T> Foo<'a> for T {
|
||||
| -- the parameter type `T` must be valid for the lifetime `'a` as defined here...
|
||||
LL | type Bar = &'a T;
|
||||
| ^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
|
||||
| ^^^^^^^^ ...so that the reference type `&'a T` does not outlive the data it points at
|
||||
|
|
||||
help: consider adding an explicit lifetime bound
|
||||
|
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
error[E0309]: the parameter type `T` may not live long enough
|
||||
--> $DIR/wf-outlives-ty-in-fn-or-trait.rs:9:16
|
||||
--> $DIR/wf-outlives-ty-in-fn-or-trait.rs:9:5
|
||||
|
|
||||
LL | impl<'a, T> Trait<'a, T> for usize {
|
||||
| -- the parameter type `T` must be valid for the lifetime `'a` as defined here...
|
||||
LL | type Out = &'a fn(T);
|
||||
| ^^^^^^^^^ ...so that the reference type `&'a fn(T)` does not outlive the data it points at
|
||||
| ^^^^^^^^ ...so that the reference type `&'a fn(T)` does not outlive the data it points at
|
||||
|
|
||||
help: consider adding an explicit lifetime bound
|
||||
|
|
||||
@@ -12,12 +12,12 @@ LL | impl<'a, T: 'a> Trait<'a, T> for usize {
|
||||
| ++++
|
||||
|
||||
error[E0309]: the parameter type `T` may not live long enough
|
||||
--> $DIR/wf-outlives-ty-in-fn-or-trait.rs:19:16
|
||||
--> $DIR/wf-outlives-ty-in-fn-or-trait.rs:19:5
|
||||
|
|
||||
LL | impl<'a, T> Trait<'a, T> for u32 {
|
||||
| -- the parameter type `T` must be valid for the lifetime `'a` as defined here...
|
||||
LL | type Out = &'a dyn Baz<T>;
|
||||
| ^^^^^^^^^^^^^^ ...so that the reference type `&'a (dyn Baz<T> + 'a)` does not outlive the data it points at
|
||||
| ^^^^^^^^ ...so that the reference type `&'a (dyn Baz<T> + 'a)` does not outlive the data it points at
|
||||
|
|
||||
help: consider adding an explicit lifetime bound
|
||||
|
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
error[E0309]: the associated type `<Self as SomeTrait<'a>>::Type1` may not live long enough
|
||||
--> $DIR/wf-trait-associated-type-region.rs:9:18
|
||||
--> $DIR/wf-trait-associated-type-region.rs:9:5
|
||||
|
|
||||
LL | trait SomeTrait<'a> {
|
||||
| -- the associated type `<Self as SomeTrait<'a>>::Type1` must be valid for the lifetime `'a` as defined here...
|
||||
LL | type Type1;
|
||||
LL | type Type2 = &'a Self::Type1;
|
||||
| ^^^^^^^^^^^^^^^ ...so that the reference type `&'a <Self as SomeTrait<'a>>::Type1` does not outlive the data it points at
|
||||
| ^^^^^^^^^^ ...so that the reference type `&'a <Self as SomeTrait<'a>>::Type1` does not outlive the data it points at
|
||||
|
|
||||
help: consider adding an explicit lifetime bound
|
||||
|
|
||||
|
||||
Reference in New Issue
Block a user