Skip to content

Commit 9b5d57d

Browse files
committed
Unconditionally run check_item_type on all items
1 parent cca072c commit 9b5d57d

File tree

64 files changed

+593
-392
lines changed

Some content is hidden

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

64 files changed

+593
-392
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,10 +881,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
881881
hir::ForeignItemKind::Fn(sig, _, _) => {
882882
require_c_abi_if_c_variadic(tcx, sig.decl, abi, item.span);
883883
}
884-
hir::ForeignItemKind::Static(..) => {
885-
check_static_inhabited(tcx, def_id);
886-
check_static_linkage(tcx, def_id);
887-
}
888884
_ => {}
889885
}
890886
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,15 @@ where
185185
}
186186

187187
fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGuaranteed> {
188+
crate::check::check::check_item_type(tcx, def_id);
188189
let node = tcx.hir_node_by_def_id(def_id);
189190
let mut res = match node {
190191
hir::Node::Crate(_) => bug!("check_well_formed cannot be applied to the crate root"),
191192
hir::Node::Item(item) => check_item(tcx, item),
192193
hir::Node::TraitItem(item) => check_trait_item(tcx, item),
193194
hir::Node::ImplItem(item) => check_impl_item(tcx, item),
194195
hir::Node::ForeignItem(item) => check_foreign_item(tcx, item),
195-
hir::Node::ConstBlock(_) | hir::Node::Expr(_) | hir::Node::OpaqueTy(_) => {
196-
Ok(crate::check::check::check_item_type(tcx, def_id))
197-
}
196+
hir::Node::ConstBlock(_) | hir::Node::Expr(_) | hir::Node::OpaqueTy(_) => Ok(()),
198197
_ => unreachable!("{node:?}"),
199198
};
200199

@@ -228,7 +227,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
228227
);
229228
crate::collect::lower_item(tcx, item.item_id());
230229

231-
let res = match item.kind {
230+
match item.kind {
232231
// Right now we check that every default trait implementation
233232
// has an implementation of itself. Basically, a case like:
234233
//
@@ -332,11 +331,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
332331
res
333332
}
334333
_ => Ok(()),
335-
};
336-
337-
crate::check::check::check_item_type(tcx, def_id);
338-
339-
res
334+
}
340335
}
341336

342337
fn check_foreign_item<'tcx>(

tests/incremental/issue-54242.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl Tr for str {
1414
type Arr = [u8; 8];
1515
#[cfg(cfail)]
1616
type Arr = [u8; Self::C];
17-
//[cfail]~^ ERROR cycle detected when evaluating type-level constant
17+
//[cfail]~^ ERROR cycle detected when caching mir
1818
}
1919

2020
fn main() {}

tests/ui/associated-types/impl-wf-cycle-4.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
error[E0391]: cycle detected when computing normalized predicates of `<impl at $DIR/impl-wf-cycle-4.rs:5:1: 7:26>`
1+
error[E0391]: cycle detected when computing whether `<impl at $DIR/impl-wf-cycle-4.rs:5:1: 7:26>` has a guaranteed unsized self type
22
--> $DIR/impl-wf-cycle-4.rs:5:1
33
|
44
LL | / impl<T> Filter for T
55
LL | | where
66
LL | | T: Fn(Self::ToMatch),
77
| |_________________________^
88
|
9-
note: ...which requires computing whether `<impl at $DIR/impl-wf-cycle-4.rs:5:1: 7:26>` has a guaranteed unsized self type...
9+
note: ...which requires computing normalized predicates of `<impl at $DIR/impl-wf-cycle-4.rs:5:1: 7:26>`...
1010
--> $DIR/impl-wf-cycle-4.rs:5:1
1111
|
1212
LL | / impl<T> Filter for T
1313
LL | | where
1414
LL | | T: Fn(Self::ToMatch),
1515
| |_________________________^
16-
= note: ...which again requires computing normalized predicates of `<impl at $DIR/impl-wf-cycle-4.rs:5:1: 7:26>`, completing the cycle
16+
= note: ...which again requires computing whether `<impl at $DIR/impl-wf-cycle-4.rs:5:1: 7:26>` has a guaranteed unsized self type, completing the cycle
1717
note: cycle used when checking that `<impl at $DIR/impl-wf-cycle-4.rs:5:1: 7:26>` is well-formed
1818
--> $DIR/impl-wf-cycle-4.rs:5:1
1919
|

tests/ui/associated-types/issue-38821.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ LL | impl<T: NotNull> IntoNullable for T {
7171
| ------- ^^^^^^^^^^^^ ^
7272
| |
7373
| unsatisfied trait bound introduced here
74-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
75-
help: consider further restricting the associated type
76-
|
77-
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
78-
| +++++++++++++++++++++++++++++++++++++++
7974

8075
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
8176
--> $DIR/issue-38821.rs:23:10
@@ -90,6 +85,7 @@ LL | impl<T: NotNull> IntoNullable for T {
9085
| ------- ^^^^^^^^^^^^ ^
9186
| |
9287
| unsatisfied trait bound introduced here
88+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9389

9490
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
9591
--> $DIR/issue-38821.rs:23:10
@@ -105,6 +101,10 @@ LL | impl<T: NotNull> IntoNullable for T {
105101
| |
106102
| unsatisfied trait bound introduced here
107103
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
104+
help: consider further restricting the associated type
105+
|
106+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
107+
| +++++++++++++++++++++++++++++++++++++++
108108

109109
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
110110
--> $DIR/issue-38821.rs:23:17
@@ -174,11 +174,6 @@ LL | impl<T: NotNull> IntoNullable for T {
174174
| ------- ^^^^^^^^^^^^ ^
175175
| |
176176
| unsatisfied trait bound introduced here
177-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
178-
help: consider further restricting the associated type
179-
|
180-
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
181-
| +++++++++++++++++++++++++++++++++++++++
182177

183178
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
184179
--> $DIR/issue-38821.rs:23:23
@@ -193,6 +188,7 @@ LL | impl<T: NotNull> IntoNullable for T {
193188
| ------- ^^^^^^^^^^^^ ^
194189
| |
195190
| unsatisfied trait bound introduced here
191+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
196192

197193
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
198194
--> $DIR/issue-38821.rs:23:23
@@ -208,6 +204,10 @@ LL | impl<T: NotNull> IntoNullable for T {
208204
| |
209205
| unsatisfied trait bound introduced here
210206
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
207+
help: consider further restricting the associated type
208+
|
209+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
210+
| +++++++++++++++++++++++++++++++++++++++
211211

212212
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
213213
--> $DIR/issue-38821.rs:23:10

tests/ui/async-await/async-fn/impl-header.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ LL | impl async Fn<()> for F {}
2222
|
2323
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
2424

25+
error[E0046]: not all trait items implemented, missing: `call`
26+
--> $DIR/impl-header.rs:5:1
27+
|
28+
LL | impl async Fn<()> for F {}
29+
| ^^^^^^^^^^^^^^^^^^^^^^^ missing `call` in implementation
30+
|
31+
= help: implement the missing item: `fn call(&self, _: ()) -> <Self as FnOnce<()>>::Output { todo!() }`
32+
2533
error[E0277]: expected a `FnMut()` closure, found `F`
2634
--> $DIR/impl-header.rs:5:23
2735
|
@@ -33,14 +41,6 @@ LL | impl async Fn<()> for F {}
3341
note: required by a bound in `Fn`
3442
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
3543

36-
error[E0046]: not all trait items implemented, missing: `call`
37-
--> $DIR/impl-header.rs:5:1
38-
|
39-
LL | impl async Fn<()> for F {}
40-
| ^^^^^^^^^^^^^^^^^^^^^^^ missing `call` in implementation
41-
|
42-
= help: implement the missing item: `fn call(&self, _: ()) -> <Self as FnOnce<()>>::Output { todo!() }`
43-
4444
error: aborting due to 5 previous errors
4545

4646
Some errors have detailed explanations: E0046, E0183, E0277, E0658.

tests/ui/coherence/coherence-impl-trait-for-trait-dyn-compatible.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error[E0046]: not all trait items implemented, missing: `eq`
2+
--> $DIR/coherence-impl-trait-for-trait-dyn-compatible.rs:7:1
3+
|
4+
LL | trait DynIncompatible { fn eq(&self, other: Self); }
5+
| -------------------------- `eq` from trait
6+
LL | impl DynIncompatible for dyn DynIncompatible { }
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `eq` in implementation
8+
19
error[E0038]: the trait `DynIncompatible` is not dyn compatible
210
--> $DIR/coherence-impl-trait-for-trait-dyn-compatible.rs:7:26
311
|
@@ -14,14 +22,6 @@ LL | trait DynIncompatible { fn eq(&self, other: Self); }
1422
| this trait is not dyn compatible...
1523
= help: consider moving `eq` to another trait
1624

17-
error[E0046]: not all trait items implemented, missing: `eq`
18-
--> $DIR/coherence-impl-trait-for-trait-dyn-compatible.rs:7:1
19-
|
20-
LL | trait DynIncompatible { fn eq(&self, other: Self); }
21-
| -------------------------- `eq` from trait
22-
LL | impl DynIncompatible for dyn DynIncompatible { }
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `eq` in implementation
24-
2525
error: aborting due to 2 previous errors
2626

2727
Some errors have detailed explanations: E0038, E0046.

tests/ui/coherence/fuzzing/best-obligation-ICE.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
error[E0046]: not all trait items implemented, missing: `Assoc`
2+
--> $DIR/best-obligation-ICE.rs:10:1
3+
|
4+
LL | type Assoc;
5+
| ---------- `Assoc` from trait
6+
...
7+
LL | impl<T> Trait for W<W<W<T>>> {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Assoc` in implementation
9+
110
error[E0277]: the trait bound `W<W<T>>: Trait` is not satisfied
211
--> $DIR/best-obligation-ICE.rs:10:19
312
|
@@ -46,15 +55,6 @@ help: consider restricting type parameter `T` with trait `Trait`
4655
LL | impl<T: Trait> Trait for W<W<W<T>>> {}
4756
| +++++++
4857

49-
error[E0046]: not all trait items implemented, missing: `Assoc`
50-
--> $DIR/best-obligation-ICE.rs:10:1
51-
|
52-
LL | type Assoc;
53-
| ---------- `Assoc` from trait
54-
...
55-
LL | impl<T> Trait for W<W<W<T>>> {}
56-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Assoc` in implementation
57-
5858
error[E0119]: conflicting implementations of trait `NoOverlap` for type `W<W<W<W<_>>>>`
5959
--> $DIR/best-obligation-ICE.rs:18:1
6060
|

tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
struct Foo;
66
impl<'a, const NUM: usize> std::ops::Add<&'a Foo> for Foo
77
//~^ ERROR the const parameter `NUM` is not constrained by the impl trait, self type, or predicates
8+
//~| ERROR missing: `Output`, `add`
89
where
910
[(); 1 + 0]: Sized,
1011
{

tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.stderr

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0407]: method `unimplemented` is not a member of trait `std::ops::Add`
2-
--> $DIR/post-analysis-user-facing-param-env.rs:11:5
2+
--> $DIR/post-analysis-user-facing-param-env.rs:12:5
33
|
44
LL | / fn unimplemented(self, _: &Foo) -> Self::Output {
55
LL | |
@@ -17,6 +17,19 @@ LL | #![feature(generic_const_exprs)]
1717
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
1818
= note: `#[warn(incomplete_features)]` on by default
1919

20+
error[E0046]: not all trait items implemented, missing: `Output`, `add`
21+
--> $DIR/post-analysis-user-facing-param-env.rs:6:1
22+
|
23+
LL | / impl<'a, const NUM: usize> std::ops::Add<&'a Foo> for Foo
24+
LL | |
25+
LL | |
26+
LL | | where
27+
LL | | [(); 1 + 0]: Sized,
28+
| |_______________________^ missing `Output`, `add` in implementation
29+
|
30+
= help: implement the missing item: `type Output = /* Type */;`
31+
= help: implement the missing item: `fn add(self, _: &'a Foo) -> <Self as Add<&'a Foo>>::Output { todo!() }`
32+
2033
error[E0207]: the const parameter `NUM` is not constrained by the impl trait, self type, or predicates
2134
--> $DIR/post-analysis-user-facing-param-env.rs:6:10
2235
|
@@ -27,7 +40,7 @@ LL | impl<'a, const NUM: usize> std::ops::Add<&'a Foo> for Foo
2740
= note: proving the result of expressions other than the parameter are unique is not supported
2841

2942
error[E0284]: type annotations needed
30-
--> $DIR/post-analysis-user-facing-param-env.rs:11:40
43+
--> $DIR/post-analysis-user-facing-param-env.rs:12:40
3144
|
3245
LL | fn unimplemented(self, _: &Foo) -> Self::Output {
3346
| ^^^^^^^^^^^^ cannot infer the value of const parameter `NUM`
@@ -40,7 +53,7 @@ LL | impl<'a, const NUM: usize> std::ops::Add<&'a Foo> for Foo
4053
| |
4154
| unsatisfied trait bound introduced here
4255

43-
error: aborting due to 3 previous errors; 1 warning emitted
56+
error: aborting due to 4 previous errors; 1 warning emitted
4457

45-
Some errors have detailed explanations: E0207, E0284, E0407.
46-
For more information about an error, try `rustc --explain E0207`.
58+
Some errors have detailed explanations: E0046, E0207, E0284, E0407.
59+
For more information about an error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)