@@ -82,22 +82,21 @@ mod pat;
82
82
mod place_op;
83
83
mod regionck;
84
84
mod upvar;
85
- mod util;
86
85
mod wfcheck;
87
86
pub mod writeback;
88
87
89
88
pub use fn_ctxt:: FnCtxt ;
90
89
91
90
use crate :: astconv:: AstConv ;
92
91
use crate :: check:: gather_locals:: GatherLocalsVisitor ;
93
- use crate :: check:: util:: MaybeInProgressTables ;
94
92
use rustc_attr as attr;
95
93
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
96
94
use rustc_errors:: { pluralize, struct_span_err, Applicability } ;
97
95
use rustc_hir as hir;
98
96
use 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 } ;
100
98
use rustc_hir:: intravisit:: Visitor ;
99
+ use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
101
100
use rustc_hir:: lang_items:: LangItem ;
102
101
use rustc_hir:: { HirIdMap , ItemKind , Node } ;
103
102
use rustc_index:: bit_set:: BitSet ;
@@ -126,7 +125,7 @@ use rustc_trait_selection::traits::error_reporting::recursive_type_with_infinite
126
125
use rustc_trait_selection:: traits:: error_reporting:: suggestions:: ReturnsVisitor ;
127
126
use rustc_trait_selection:: traits:: { self , ObligationCauseCode , TraitEngine , TraitEngineExt } ;
128
127
129
- use std:: cell:: RefCell ;
128
+ use std:: cell:: { Ref , RefCell , RefMut } ;
130
129
use std:: cmp;
131
130
use std:: ops:: { self , Deref } ;
132
131
@@ -586,10 +585,6 @@ pub fn check_wf_new(tcx: TyCtxt<'_>) {
586
585
587
586
pub fn provide ( providers : & mut Providers ) {
588
587
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
- } ;
593
588
* providers = Providers {
594
589
typeck_item_bodies,
595
590
typeck_const_arg,
@@ -2720,6 +2715,67 @@ fn check_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, generics: &ty::Generics,
2720
2715
}
2721
2716
}
2722
2717
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
+
2723
2779
fn fatally_break_rust ( sess : & Session ) {
2724
2780
let handler = sess. diagnostic ( ) ;
2725
2781
handler. span_bug_no_panic (
0 commit comments