1
Fork 0

Perform wf checking per module.

This commit is contained in:
Camille GILLOT 2021-05-10 12:18:55 +02:00
parent 42289ff931
commit 86290effd5
5 changed files with 19 additions and 10 deletions

View file

@ -826,6 +826,10 @@ rustc_queries! {
desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) } desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
} }
query check_mod_type_wf(key: LocalDefId) -> () {
desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
}
query collect_mod_item_types(key: LocalDefId) -> () { query collect_mod_item_types(key: LocalDefId) -> () {
desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) } desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
} }

View file

@ -99,8 +99,6 @@ pub use expectation::Expectation;
pub use fn_ctxt::*; pub use fn_ctxt::*;
use hir::def::CtorOf; use hir::def::CtorOf;
pub use inherited::{Inherited, InheritedBuilder}; pub use inherited::{Inherited, InheritedBuilder};
use wfcheck::check_well_formed;
pub(crate) use wfcheck::check_wf_new;
use crate::astconv::AstConv; use crate::astconv::AstConv;
use crate::check::gather_locals::GatherLocalsVisitor; use crate::check::gather_locals::GatherLocalsVisitor;
@ -243,6 +241,7 @@ impl<'tcx> EnclosingBreakables<'tcx> {
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {
method::provide(providers); method::provide(providers);
wfcheck::provide(providers);
*providers = Providers { *providers = Providers {
typeck_item_bodies, typeck_item_bodies,
typeck_const_arg, typeck_const_arg,
@ -251,7 +250,6 @@ pub fn provide(providers: &mut Providers) {
has_typeck_results, has_typeck_results,
adt_destructor, adt_destructor,
used_trait_imports, used_trait_imports,
check_well_formed,
check_mod_item_types, check_mod_item_types,
region_scope_tree, region_scope_tree,
..*providers ..*providers

View file

@ -14,6 +14,7 @@ use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_infer::infer::outlives::obligations::TypeOutlives; use rustc_infer::infer::outlives::obligations::TypeOutlives;
use rustc_infer::infer::region_constraints::GenericKind; use rustc_infer::infer::region_constraints::GenericKind;
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt}; use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts, Subst}; use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts, Subst};
use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::trait_def::TraitSpecializationKind;
use rustc_middle::ty::{ use rustc_middle::ty::{
@ -67,7 +68,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> {
} }
} }
pub(crate) fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let node = tcx.hir().expect_owner(def_id); let node = tcx.hir().expect_owner(def_id);
match node { match node {
hir::OwnerNode::Crate(_) => {} hir::OwnerNode::Crate(_) => {}
@ -1858,8 +1859,8 @@ fn check_false_global_bounds(fcx: &FnCtxt<'_, '_>, mut span: Span, id: hir::HirI
fcx.select_all_obligations_or_error(); fcx.select_all_obligations_or_error();
} }
pub(crate) fn check_wf_new(tcx: TyCtxt<'_>) { fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalDefId) {
let items = tcx.hir_crate_items(()); let items = tcx.hir_module_items(module);
par_for_each_in(items.items(), |item| tcx.ensure().check_well_formed(item.def_id)); par_for_each_in(items.items(), |item| tcx.ensure().check_well_formed(item.def_id));
par_for_each_in(items.impl_items(), |item| tcx.ensure().check_well_formed(item.def_id)); par_for_each_in(items.impl_items(), |item| tcx.ensure().check_well_formed(item.def_id));
par_for_each_in(items.trait_items(), |item| tcx.ensure().check_well_formed(item.def_id)); par_for_each_in(items.trait_items(), |item| tcx.ensure().check_well_formed(item.def_id));
@ -1948,3 +1949,7 @@ fn error_392(
err.span_label(span, "unused parameter"); err.span_label(span, "unused parameter");
err err
} }
pub fn provide(providers: &mut Providers) {
*providers = Providers { check_mod_type_wf, check_well_formed, ..*providers };
}

View file

@ -525,7 +525,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
} }
tcx.sess.track_errors(|| { tcx.sess.track_errors(|| {
tcx.sess.time("wf_checking", || check::check_wf_new(tcx)); tcx.sess.time("wf_checking", || {
tcx.hir().par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
});
})?; })?;
// NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync. // NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync.

View file

@ -1,5 +1,5 @@
trait Foo { trait Foo {
fn answer(self); fn answer(self);
} }
struct NoData<T>; struct NoData<T>;
@ -13,11 +13,11 @@ impl<T> Foo for T where NoData<T>: Foo {
} }
trait Bar { trait Bar {
fn answer(self); fn answer(self);
} }
trait Baz { trait Baz {
fn answer(self); fn answer(self);
} }
struct AlmostNoData<T>(Option<T>); struct AlmostNoData<T>(Option<T>);