Skip to content

Commit 3cd5671

Browse files
committed
Reorder check_item_type diagnostics so they occur next to the corresponding check_well_formed diagnostics
1 parent b4e16c3 commit 3cd5671

33 files changed

+331
-245
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_attr as attr;
88
use rustc_errors::{ErrorGuaranteed, MultiSpan};
99
use rustc_hir as hir;
1010
use rustc_hir::def::{CtorKind, DefKind};
11-
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
11+
use rustc_hir::def_id::{DefId, LocalDefId};
1212
use rustc_hir::Node;
1313
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
1414
use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
@@ -443,7 +443,7 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
443443
}
444444
}
445445

446-
fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
446+
pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
447447
let _indenter = indenter();
448448
match tcx.def_kind(def_id) {
449449
DefKind::Static(..) => {
@@ -1309,16 +1309,6 @@ pub(super) fn check_type_params_are_used<'tcx>(
13091309
}
13101310
}
13111311

1312-
pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
1313-
let module = tcx.hir_module_items(module_def_id);
1314-
for id in module.items() {
1315-
check_item_type(tcx, id.owner_id.def_id);
1316-
}
1317-
if module_def_id == LocalModDefId::CRATE_DEF_ID {
1318-
super::entry::check_for_entry_fn(tcx);
1319-
}
1320-
}
1321-
13221312
fn async_opaque_type_cycle_error(tcx: TyCtxt<'_>, span: Span) -> ErrorGuaranteed {
13231313
struct_span_err!(tcx.sess, span, E0733, "recursion in an `async fn` requires boxing")
13241314
.span_label(span, "recursive `async fn`")

compiler/rustc_hir_analysis/src/check/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::ops::Not;
1414
use super::check_function_signature;
1515
use crate::errors;
1616

17-
pub(crate) fn check_for_entry_fn(tcx: TyCtxt<'_>) {
17+
pub(crate) fn check_for_entry_fn(tcx: TyCtxt<'_>, (): ()) {
1818
match tcx.entry_fn(()) {
1919
Some((def_id, EntryFnType::Main { .. })) => check_main_fn_ty(tcx, def_id),
2020
Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id),

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub use check::check_abi;
7575

7676
use std::num::NonZeroU32;
7777

78-
use check::check_mod_item_types;
78+
use entry::check_for_entry_fn;
7979
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
8080
use rustc_errors::{pluralize, struct_span_err, Diagnostic, DiagnosticBuilder};
8181
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -110,7 +110,7 @@ pub fn provide(providers: &mut Providers) {
110110
wfcheck::provide(providers);
111111
*providers = Providers {
112112
adt_destructor,
113-
check_mod_item_types,
113+
check_for_entry_fn,
114114
region_scope_tree,
115115
collect_return_position_impl_trait_in_trait_tys,
116116
compare_impl_const: compare_impl_item::compare_impl_const_raw,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
171171
item.name = ? tcx.def_path_str(def_id)
172172
);
173173

174-
match item.kind {
174+
let res = match item.kind {
175175
// Right now we check that every default trait implementation
176176
// has an implementation of itself. Basically, a case like:
177177
//
@@ -268,7 +268,11 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
268268
}
269269
}
270270
_ => Ok(()),
271-
}
271+
};
272+
273+
crate::check::check::check_item_type(tcx, def_id);
274+
275+
res
272276
}
273277

274278
fn check_foreign_item(tcx: TyCtxt<'_>, item: &hir::ForeignItem<'_>) -> Result<(), ErrorGuaranteed> {

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
206206
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
207207
});
208208

209-
// NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync.
210-
tcx.sess.time("item_types_checking", || {
211-
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module))
212-
});
209+
tcx.sess.time("entry_fn_checks", || tcx.ensure().check_for_entry_fn(()));
213210

214-
// HACK: `check_mod_type_wf` may spuriously emit errors due to `delay_span_bug`, even if those errors
215-
// only actually get emitted in `check_mod_item_types`.
211+
// HACK: `check_for_entry_fn` wants to report its errors even if `check_mod_type_wf` has errored.
216212
errs?;
217213

218214
if tcx.features().rustc_attrs {

compiler/rustc_middle/src/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,8 @@ rustc_queries! {
935935
desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
936936
}
937937

938-
query check_mod_item_types(key: LocalModDefId) -> () {
939-
desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
938+
query check_for_entry_fn(key: ()) -> () {
939+
desc { |_tcx| "checking entry functions" }
940940
}
941941

942942
query check_mod_privacy(key: LocalModDefId) -> () {

tests/ui/associated-types/associated-types-no-suitable-supertrait.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
error[E0277]: the trait bound `(T, U): Get` is not satisfied
2+
--> $DIR/associated-types-no-suitable-supertrait.rs:22:5
3+
|
4+
LL | fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `(T, U)`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/associated-types-no-suitable-supertrait.rs:12:1
9+
|
10+
LL | trait Get {
11+
| ^^^^^^^^^
12+
113
error[E0277]: the trait bound `(T, U): Get` is not satisfied
214
--> $DIR/associated-types-no-suitable-supertrait.rs:22:40
315
|
@@ -21,18 +33,6 @@ help: consider further restricting `Self`
2133
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
2234
| +++++++++++++++
2335

24-
error[E0277]: the trait bound `(T, U): Get` is not satisfied
25-
--> $DIR/associated-types-no-suitable-supertrait.rs:22:5
26-
|
27-
LL | fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
28-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `(T, U)`
29-
|
30-
help: this trait has no implementations, consider adding one
31-
--> $DIR/associated-types-no-suitable-supertrait.rs:12:1
32-
|
33-
LL | trait Get {
34-
| ^^^^^^^^^
35-
3636
error: aborting due to 3 previous errors
3737

3838
For more information about this error, try `rustc --explain E0277`.

tests/ui/associated-types/defaults-cyclic-fail-1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ impl Tr for u32 {
2424
// ...but not in an impl that redefines one of the types.
2525
impl Tr for bool {
2626
type A = Box<Self::B>;
27-
//~^ ERROR overflow evaluating the requirement `<bool as Tr>::B == _`
27+
//~^ ERROR overflow evaluating the requirement `<bool as Tr>::A == _`
2828
}
2929
// (the error is shown twice for some reason)
3030

3131
impl Tr for usize {
3232
type B = &'static Self::A;
33-
//~^ ERROR overflow evaluating the requirement `<usize as Tr>::A == _`
33+
//~^ ERROR overflow evaluating the requirement `<usize as Tr>::B == _`
3434
}
3535

3636
fn main() {

tests/ui/associated-types/defaults-cyclic-fail-1.stderr

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

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

tests/ui/associated-types/defaults-cyclic-fail-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ impl Tr for u32 {
2525

2626
impl Tr for bool {
2727
type A = Box<Self::B>;
28-
//~^ ERROR overflow evaluating the requirement `<bool as Tr>::B == _`
28+
//~^ ERROR overflow evaluating the requirement `<bool as Tr>::A == _`
2929
}
3030
// (the error is shown twice for some reason)
3131

3232
impl Tr for usize {
3333
type B = &'static Self::A;
34-
//~^ ERROR overflow evaluating the requirement `<usize as Tr>::A == _`
34+
//~^ ERROR overflow evaluating the requirement `<usize as Tr>::B == _`
3535
}
3636

3737
fn main() {

tests/ui/associated-types/defaults-cyclic-fail-2.stderr

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

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

tests/ui/async-await/issue-66312.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-66312.rs:9:8
3+
|
4+
LL | if x.is_some() {
5+
| ^^^^^^^^^^^ expected `bool`, found `()`
6+
17
error[E0307]: invalid `self` parameter type: T
28
--> $DIR/issue-66312.rs:4:22
39
|
@@ -7,12 +13,6 @@ LL | fn is_some(self: T);
713
= note: type of `self` must be `Self` or a type that dereferences to it
814
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
915

10-
error[E0308]: mismatched types
11-
--> $DIR/issue-66312.rs:9:8
12-
|
13-
LL | if x.is_some() {
14-
| ^^^^^^^^^^^ expected `bool`, found `()`
15-
1616
error: aborting due to 2 previous errors
1717

1818
Some errors have detailed explanations: E0307, E0308.

tests/ui/const-generics/issues/issue-83765.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
trait TensorDimension {
55
const DIM: usize;
66
//~^ ERROR cycle detected when resolving instance
7+
//~| ERROR cycle detected when resolving instance
78
// FIXME Given the current state of the compiler its expected that we cycle here,
89
// but the cycle is still wrong.
910
const ISSCALAR: bool = Self::DIM == 0;
@@ -79,6 +80,7 @@ impl<'a, R, T: Broadcastable, F: Fn(T::Element) -> R, const DIM: usize> TensorSi
7980
for BMap<'a, R, T, F, DIM>
8081
{
8182
fn size(&self) -> [usize; DIM] {
83+
//~^ ERROR: method not compatible with trait
8284
self.reference.size()
8385
}
8486
}
@@ -88,6 +90,7 @@ impl<'a, R, T: Broadcastable, F: Fn(T::Element) -> R, const DIM: usize> Broadcas
8890
{
8991
type Element = R;
9092
fn bget(&self, index: [usize; DIM]) -> Option<Self::Element> {
93+
//~^ ERROR: method not compatible with trait
9194
self.reference.bget(index).map(&self.closure)
9295
}
9396
}

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,44 @@ LL | trait TensorDimension {
1717
| ^^^^^^^^^^^^^^^^^^^^^
1818
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
1919

20-
error: aborting due to previous error
20+
error[E0391]: cycle detected when resolving instance `<LazyUpdim<'_, T, <T as TensorDimension>::DIM, DIM> as TensorDimension>::DIM`
21+
--> $DIR/issue-83765.rs:5:5
22+
|
23+
LL | const DIM: usize;
24+
| ^^^^^^^^^^^^^^^^
25+
|
26+
note: ...which requires computing candidate for `<LazyUpdim<'_, T, <T as TensorDimension>::DIM, DIM> as TensorDimension>`...
27+
--> $DIR/issue-83765.rs:4:1
28+
|
29+
LL | trait TensorDimension {
30+
| ^^^^^^^^^^^^^^^^^^^^^
31+
= note: ...which again requires resolving instance `<LazyUpdim<'_, T, <T as TensorDimension>::DIM, DIM> as TensorDimension>::DIM`, completing the cycle
32+
note: cycle used when checking that `<impl at $DIR/issue-83765.rs:56:1: 56:97>` is well-formed
33+
--> $DIR/issue-83765.rs:56:1
34+
|
35+
LL | impl<'a, T: Broadcastable, const DIM: usize> Broadcastable for LazyUpdim<'a, T, { T::DIM }, DIM> {
36+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
38+
39+
error[E0308]: method not compatible with trait
40+
--> $DIR/issue-83765.rs:82:5
41+
|
42+
LL | fn size(&self) -> [usize; DIM] {
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
44+
|
45+
= note: expected constant `Self::DIM`
46+
found constant `DIM`
47+
48+
error[E0308]: method not compatible with trait
49+
--> $DIR/issue-83765.rs:92:5
50+
|
51+
LL | fn bget(&self, index: [usize; DIM]) -> Option<Self::Element> {
52+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
53+
|
54+
= note: expected constant `Self::DIM`
55+
found constant `DIM`
56+
57+
error: aborting due to 4 previous errors
2158

22-
For more information about this error, try `rustc --explain E0391`.
59+
Some errors have detailed explanations: E0308, E0391.
60+
For more information about an error, try `rustc --explain E0308`.

tests/ui/consts/const-unsized.stderr

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,23 @@ LL | const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync));
66
|
77
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
88

9-
error[E0277]: the size for values of type `str` cannot be known at compilation time
10-
--> $DIR/const-unsized.rs:7:18
11-
|
12-
LL | const CONST_FOO: str = *"foo";
13-
| ^^^ doesn't have a size known at compile-time
14-
|
15-
= help: the trait `Sized` is not implemented for `str`
16-
179
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
18-
--> $DIR/const-unsized.rs:11:18
10+
--> $DIR/const-unsized.rs:3:35
1911
|
20-
LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync));
21-
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
12+
LL | const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync));
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
2214
|
2315
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
16+
= note: constant expressions must have a statically known size
2417

2518
error[E0277]: the size for values of type `str` cannot be known at compilation time
26-
--> $DIR/const-unsized.rs:15:20
19+
--> $DIR/const-unsized.rs:7:18
2720
|
28-
LL | static STATIC_BAR: str = *"bar";
29-
| ^^^ doesn't have a size known at compile-time
21+
LL | const CONST_FOO: str = *"foo";
22+
| ^^^ doesn't have a size known at compile-time
3023
|
3124
= help: the trait `Sized` is not implemented for `str`
3225

33-
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
34-
--> $DIR/const-unsized.rs:3:35
35-
|
36-
LL | const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync));
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
38-
|
39-
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
40-
= note: constant expressions must have a statically known size
41-
4226
error[E0277]: the size for values of type `str` cannot be known at compilation time
4327
--> $DIR/const-unsized.rs:7:24
4428
|
@@ -48,6 +32,14 @@ LL | const CONST_FOO: str = *"foo";
4832
= help: the trait `Sized` is not implemented for `str`
4933
= note: constant expressions must have a statically known size
5034

35+
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
36+
--> $DIR/const-unsized.rs:11:18
37+
|
38+
LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync));
39+
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
40+
|
41+
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
42+
5143
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
5244
--> $DIR/const-unsized.rs:11:37
5345
|
@@ -57,6 +49,14 @@ LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync));
5749
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
5850
= note: constant expressions must have a statically known size
5951

52+
error[E0277]: the size for values of type `str` cannot be known at compilation time
53+
--> $DIR/const-unsized.rs:15:20
54+
|
55+
LL | static STATIC_BAR: str = *"bar";
56+
| ^^^ doesn't have a size known at compile-time
57+
|
58+
= help: the trait `Sized` is not implemented for `str`
59+
6060
error[E0277]: the size for values of type `str` cannot be known at compilation time
6161
--> $DIR/const-unsized.rs:15:26
6262
|

tests/ui/consts/issue-39974.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/issue-39974.rs:5:19
3-
|
4-
LL | f: [[f64; 2]; LENGTH],
5-
| ^^^^^^ expected `usize`, found `f64`
6-
71
error[E0308]: mismatched types
82
--> $DIR/issue-39974.rs:1:21
93
|
@@ -13,6 +7,12 @@ LL | const LENGTH: f64 = 2;
137
| expected `f64`, found integer
148
| help: use a float literal: `2.0`
159

10+
error[E0308]: mismatched types
11+
--> $DIR/issue-39974.rs:5:19
12+
|
13+
LL | f: [[f64; 2]; LENGTH],
14+
| ^^^^^^ expected `usize`, found `f64`
15+
1616
error: aborting due to 2 previous errors
1717

1818
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)