diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-05-10 12:18:55 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-06-21 23:56:17 +0200 |
| commit | 86290effd511d9cd8b6339704a85495552c66c90 (patch) | |
| tree | f4dc8add8d8ea6e1dd4f3f1d1c5ccf8673ce0598 | |
| parent | 42289ff931334f5f82cec0b3e0252ce326ca165c (diff) | |
| download | rust-86290effd511d9cd8b6339704a85495552c66c90.tar.gz rust-86290effd511d9cd8b6339704a85495552c66c90.zip | |
Perform wf checking per module.
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/check/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/check/wfcheck.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/lib.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-20413.rs | 6 |
5 files changed, 19 insertions, 10 deletions
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index c2ff95eca70..7a5a39919bf 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -826,6 +826,10 @@ rustc_queries! { 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) -> () { desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) } } diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index 5d43a7421a1..0ede9ef7756 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -99,8 +99,6 @@ pub use expectation::Expectation; pub use fn_ctxt::*; use hir::def::CtorOf; pub use inherited::{Inherited, InheritedBuilder}; -use wfcheck::check_well_formed; -pub(crate) use wfcheck::check_wf_new; use crate::astconv::AstConv; use crate::check::gather_locals::GatherLocalsVisitor; @@ -243,6 +241,7 @@ impl<'tcx> EnclosingBreakables<'tcx> { pub fn provide(providers: &mut Providers) { method::provide(providers); + wfcheck::provide(providers); *providers = Providers { typeck_item_bodies, typeck_const_arg, @@ -251,7 +250,6 @@ pub fn provide(providers: &mut Providers) { has_typeck_results, adt_destructor, used_trait_imports, - check_well_formed, check_mod_item_types, region_scope_tree, ..*providers diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 197abe817a0..8676db61bf8 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -14,6 +14,7 @@ use rustc_infer::infer::outlives::env::OutlivesEnvironment; use rustc_infer::infer::outlives::obligations::TypeOutlives; use rustc_infer::infer::region_constraints::GenericKind; 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::trait_def::TraitSpecializationKind; 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); match node { 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(); } -pub(crate) fn check_wf_new(tcx: TyCtxt<'_>) { - let items = tcx.hir_crate_items(()); +fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalDefId) { + 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.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)); @@ -1948,3 +1949,7 @@ fn error_392( err.span_label(span, "unused parameter"); err } + +pub fn provide(providers: &mut Providers) { + *providers = Providers { check_mod_type_wf, check_well_formed, ..*providers }; +} diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index 95c8d15c93d..94eb24514c2 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -525,7 +525,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { } 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. diff --git a/src/test/ui/issues/issue-20413.rs b/src/test/ui/issues/issue-20413.rs index 01a3b7913bb..138a235e675 100644 --- a/src/test/ui/issues/issue-20413.rs +++ b/src/test/ui/issues/issue-20413.rs @@ -1,5 +1,5 @@ trait Foo { - fn answer(self); + fn answer(self); } struct NoData<T>; @@ -13,11 +13,11 @@ impl<T> Foo for T where NoData<T>: Foo { } trait Bar { - fn answer(self); + fn answer(self); } trait Baz { - fn answer(self); + fn answer(self); } struct AlmostNoData<T>(Option<T>); |
