@@ -82,22 +82,21 @@ mod pat;
8282mod place_op;
8383mod regionck;
8484mod upvar;
85- mod util;
8685mod wfcheck;
8786pub mod writeback;
8887
8988pub use fn_ctxt:: FnCtxt ;
9089
9190use crate :: astconv:: AstConv ;
9291use crate :: check:: gather_locals:: GatherLocalsVisitor ;
93- use crate :: check:: util:: MaybeInProgressTables ;
9492use rustc_attr as attr;
9593use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
9694use rustc_errors:: { pluralize, struct_span_err, Applicability } ;
9795use rustc_hir as hir;
9896use rustc_hir:: def:: Res ;
99- use rustc_hir:: def_id:: { DefId , DefIdMap , LocalDefId , LOCAL_CRATE } ;
97+ use rustc_hir:: def_id:: { CrateNum , DefId , DefIdMap , LocalDefId , LOCAL_CRATE } ;
10098use rustc_hir:: intravisit:: Visitor ;
99+ use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
101100use rustc_hir:: lang_items:: LangItem ;
102101use rustc_hir:: { HirIdMap , ItemKind , Node } ;
103102use rustc_index:: bit_set:: BitSet ;
@@ -126,7 +125,7 @@ use rustc_trait_selection::traits::error_reporting::recursive_type_with_infinite
126125use rustc_trait_selection:: traits:: error_reporting:: suggestions:: ReturnsVisitor ;
127126use rustc_trait_selection:: traits:: { self , ObligationCauseCode , TraitEngine , TraitEngineExt } ;
128127
129- use std:: cell:: RefCell ;
128+ use std:: cell:: { Ref , RefCell , RefMut } ;
130129use std:: cmp;
131130use std:: ops:: { self , Deref } ;
132131
@@ -586,10 +585,6 @@ pub fn check_wf_new(tcx: TyCtxt<'_>) {
586585
587586pub fn provide ( providers : & mut Providers ) {
588587 method:: provide ( providers) ;
589- use util:: {
590- check_impl_item_well_formed, check_item_well_formed, check_mod_item_types,
591- check_trait_item_well_formed, typeck_item_bodies,
592- } ;
593588 * providers = Providers {
594589 typeck_item_bodies,
595590 typeck_const_arg,
@@ -2720,6 +2715,67 @@ fn check_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, generics: &ty::Generics,
27202715 }
27212716}
27222717
2718+ /// A wrapper for `InferCtxt`'s `in_progress_typeck_results` field.
2719+ #[ derive( Copy , Clone ) ]
2720+ struct MaybeInProgressTables < ' a , ' tcx > {
2721+ maybe_typeck_results : Option < & ' a RefCell < ty:: TypeckResults < ' tcx > > > ,
2722+ }
2723+
2724+ impl < ' a , ' tcx > MaybeInProgressTables < ' a , ' tcx > {
2725+ fn borrow ( self ) -> Ref < ' a , ty:: TypeckResults < ' tcx > > {
2726+ match self . maybe_typeck_results {
2727+ Some ( typeck_results) => typeck_results. borrow ( ) ,
2728+ None => bug ! (
2729+ "MaybeInProgressTables: inh/fcx.typeck_results.borrow() with no typeck results"
2730+ ) ,
2731+ }
2732+ }
2733+
2734+ fn borrow_mut ( self ) -> RefMut < ' a , ty:: TypeckResults < ' tcx > > {
2735+ match self . maybe_typeck_results {
2736+ Some ( typeck_results) => typeck_results. borrow_mut ( ) ,
2737+ None => bug ! (
2738+ "MaybeInProgressTables: inh/fcx.typeck_results.borrow_mut() with no typeck results"
2739+ ) ,
2740+ }
2741+ }
2742+ }
2743+
2744+ struct CheckItemTypesVisitor < ' tcx > {
2745+ tcx : TyCtxt < ' tcx > ,
2746+ }
2747+
2748+ impl ItemLikeVisitor < ' tcx > for CheckItemTypesVisitor < ' tcx > {
2749+ fn visit_item ( & mut self , i : & ' tcx hir:: Item < ' tcx > ) {
2750+ check_item_type ( self . tcx , i) ;
2751+ }
2752+ fn visit_trait_item ( & mut self , _: & ' tcx hir:: TraitItem < ' tcx > ) { }
2753+ fn visit_impl_item ( & mut self , _: & ' tcx hir:: ImplItem < ' tcx > ) { }
2754+ }
2755+
2756+ fn check_mod_item_types ( tcx : TyCtxt < ' _ > , module_def_id : LocalDefId ) {
2757+ tcx. hir ( ) . visit_item_likes_in_module ( module_def_id, & mut CheckItemTypesVisitor { tcx } ) ;
2758+ }
2759+
2760+ fn check_item_well_formed ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
2761+ wfcheck:: check_item_well_formed ( tcx, def_id) ;
2762+ }
2763+
2764+ fn check_trait_item_well_formed ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
2765+ wfcheck:: check_trait_item ( tcx, def_id) ;
2766+ }
2767+
2768+ fn check_impl_item_well_formed ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
2769+ wfcheck:: check_impl_item ( tcx, def_id) ;
2770+ }
2771+
2772+ fn typeck_item_bodies ( tcx : TyCtxt < ' _ > , crate_num : CrateNum ) {
2773+ debug_assert ! ( crate_num == LOCAL_CRATE ) ;
2774+ tcx. par_body_owners ( |body_owner_def_id| {
2775+ tcx. ensure ( ) . typeck ( body_owner_def_id) ;
2776+ } ) ;
2777+ }
2778+
27232779fn fatally_break_rust ( sess : & Session ) {
27242780 let handler = sess. diagnostic ( ) ;
27252781 handler. span_bug_no_panic (
0 commit comments