Skip to content

Commit 86290ef

Browse files
committed
Perform wf checking per module.
1 parent 42289ff commit 86290ef

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

compiler/rustc_middle/src/query/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,10 @@ rustc_queries! {
826826
desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
827827
}
828828

829+
query check_mod_type_wf(key: LocalDefId) -> () {
830+
desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
831+
}
832+
829833
query collect_mod_item_types(key: LocalDefId) -> () {
830834
desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
831835
}

compiler/rustc_typeck/src/check/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ pub use expectation::Expectation;
9999
pub use fn_ctxt::*;
100100
use hir::def::CtorOf;
101101
pub use inherited::{Inherited, InheritedBuilder};
102-
use wfcheck::check_well_formed;
103-
pub(crate) use wfcheck::check_wf_new;
104102

105103
use crate::astconv::AstConv;
106104
use crate::check::gather_locals::GatherLocalsVisitor;
@@ -243,6 +241,7 @@ impl<'tcx> EnclosingBreakables<'tcx> {
243241

244242
pub fn provide(providers: &mut Providers) {
245243
method::provide(providers);
244+
wfcheck::provide(providers);
246245
*providers = Providers {
247246
typeck_item_bodies,
248247
typeck_const_arg,
@@ -251,7 +250,6 @@ pub fn provide(providers: &mut Providers) {
251250
has_typeck_results,
252251
adt_destructor,
253252
used_trait_imports,
254-
check_well_formed,
255253
check_mod_item_types,
256254
region_scope_tree,
257255
..*providers

compiler/rustc_typeck/src/check/wfcheck.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_infer::infer::outlives::env::OutlivesEnvironment;
1414
use rustc_infer::infer::outlives::obligations::TypeOutlives;
1515
use rustc_infer::infer::region_constraints::GenericKind;
1616
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
17+
use rustc_middle::ty::query::Providers;
1718
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts, Subst};
1819
use rustc_middle::ty::trait_def::TraitSpecializationKind;
1920
use rustc_middle::ty::{
@@ -67,7 +68,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> {
6768
}
6869
}
6970

70-
pub(crate) fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
71+
fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
7172
let node = tcx.hir().expect_owner(def_id);
7273
match node {
7374
hir::OwnerNode::Crate(_) => {}
@@ -1858,8 +1859,8 @@ fn check_false_global_bounds(fcx: &FnCtxt<'_, '_>, mut span: Span, id: hir::HirI
18581859
fcx.select_all_obligations_or_error();
18591860
}
18601861

1861-
pub(crate) fn check_wf_new(tcx: TyCtxt<'_>) {
1862-
let items = tcx.hir_crate_items(());
1862+
fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalDefId) {
1863+
let items = tcx.hir_module_items(module);
18631864
par_for_each_in(items.items(), |item| tcx.ensure().check_well_formed(item.def_id));
18641865
par_for_each_in(items.impl_items(), |item| tcx.ensure().check_well_formed(item.def_id));
18651866
par_for_each_in(items.trait_items(), |item| tcx.ensure().check_well_formed(item.def_id));
@@ -1948,3 +1949,7 @@ fn error_392(
19481949
err.span_label(span, "unused parameter");
19491950
err
19501951
}
1952+
1953+
pub fn provide(providers: &mut Providers) {
1954+
*providers = Providers { check_mod_type_wf, check_well_formed, ..*providers };
1955+
}

compiler/rustc_typeck/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
525525
}
526526

527527
tcx.sess.track_errors(|| {
528-
tcx.sess.time("wf_checking", || check::check_wf_new(tcx));
528+
tcx.sess.time("wf_checking", || {
529+
tcx.hir().par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
530+
});
529531
})?;
530532

531533
// NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync.

src/test/ui/issues/issue-20413.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
trait Foo {
2-
fn answer(self);
2+
fn answer(self);
33
}
44

55
struct NoData<T>;
@@ -13,11 +13,11 @@ impl<T> Foo for T where NoData<T>: Foo {
1313
}
1414

1515
trait Bar {
16-
fn answer(self);
16+
fn answer(self);
1717
}
1818

1919
trait Baz {
20-
fn answer(self);
20+
fn answer(self);
2121
}
2222

2323
struct AlmostNoData<T>(Option<T>);

0 commit comments

Comments
 (0)