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() {

0 commit comments

Comments
 (0)