@@ -75,6 +75,7 @@ mod expr;
7575mod fn_ctxt;
7676mod gather_locals;
7777mod generator_interior;
78+ mod inherited;
7879pub mod intrinsic;
7980pub mod method;
8081mod op;
@@ -86,6 +87,7 @@ mod wfcheck;
8687pub mod writeback;
8788
8889pub use fn_ctxt:: FnCtxt ;
90+ pub use inherited:: { Inherited , InheritedBuilder } ;
8991
9092use crate :: astconv:: AstConv ;
9193use crate :: check:: gather_locals:: GatherLocalsVisitor ;
@@ -94,16 +96,15 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
9496use rustc_errors:: { pluralize, struct_span_err, Applicability } ;
9597use rustc_hir as hir;
9698use rustc_hir:: def:: Res ;
97- use rustc_hir:: def_id:: { CrateNum , DefId , DefIdMap , LocalDefId , LOCAL_CRATE } ;
99+ use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId , LOCAL_CRATE } ;
98100use rustc_hir:: intravisit:: Visitor ;
99101use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
100102use rustc_hir:: lang_items:: LangItem ;
101103use rustc_hir:: { HirIdMap , ItemKind , Node } ;
102104use rustc_index:: bit_set:: BitSet ;
103105use rustc_index:: vec:: Idx ;
104- use rustc_infer:: infer;
105106use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
106- use rustc_infer:: infer:: { InferCtxt , InferOk , RegionVariableOrigin , TyCtxtInferExt } ;
107+ use rustc_infer:: infer:: RegionVariableOrigin ;
107108use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder } ;
108109use rustc_middle:: ty:: query:: Providers ;
109110use rustc_middle:: ty:: subst:: GenericArgKind ;
@@ -119,20 +120,17 @@ use rustc_span::symbol::{kw, sym, Ident};
119120use rustc_span:: { self , BytePos , MultiSpan , Span } ;
120121use rustc_target:: abi:: VariantIdx ;
121122use rustc_target:: spec:: abi:: Abi ;
122- use rustc_trait_selection:: infer:: InferCtxtExt as _;
123- use rustc_trait_selection:: opaque_types:: OpaqueTypeDecl ;
124123use rustc_trait_selection:: traits:: error_reporting:: recursive_type_with_infinite_size_error;
125124use rustc_trait_selection:: traits:: error_reporting:: suggestions:: ReturnsVisitor ;
126- use rustc_trait_selection:: traits:: { self , ObligationCauseCode , TraitEngine , TraitEngineExt } ;
125+ use rustc_trait_selection:: traits:: { self , ObligationCauseCode } ;
127126
128127use std:: cell:: { Ref , RefCell , RefMut } ;
129128use std:: cmp;
130- use std:: ops:: { self , Deref } ;
129+ use std:: ops:: { self } ;
131130
132131use crate :: require_c_abi_if_c_variadic;
133132use crate :: util:: common:: indenter;
134133
135- use self :: callee:: DeferredCallResolution ;
136134use self :: coercion:: { CoerceMany , DynamicCoerceMany } ;
137135use self :: compare_method:: { compare_const_impl, compare_impl_method, compare_ty_impl} ;
138136pub use self :: Expectation :: * ;
@@ -155,64 +153,6 @@ pub struct LocalTy<'tcx> {
155153 revealed_ty : Ty < ' tcx > ,
156154}
157155
158- /// Closures defined within the function. For example:
159- ///
160- /// fn foo() {
161- /// bar(move|| { ... })
162- /// }
163- ///
164- /// Here, the function `foo()` and the closure passed to
165- /// `bar()` will each have their own `FnCtxt`, but they will
166- /// share the inherited fields.
167- pub struct Inherited < ' a , ' tcx > {
168- infcx : InferCtxt < ' a , ' tcx > ,
169-
170- typeck_results : MaybeInProgressTables < ' a , ' tcx > ,
171-
172- locals : RefCell < HirIdMap < LocalTy < ' tcx > > > ,
173-
174- fulfillment_cx : RefCell < Box < dyn TraitEngine < ' tcx > > > ,
175-
176- // Some additional `Sized` obligations badly affect type inference.
177- // These obligations are added in a later stage of typeck.
178- deferred_sized_obligations : RefCell < Vec < ( Ty < ' tcx > , Span , traits:: ObligationCauseCode < ' tcx > ) > > ,
179-
180- // When we process a call like `c()` where `c` is a closure type,
181- // we may not have decided yet whether `c` is a `Fn`, `FnMut`, or
182- // `FnOnce` closure. In that case, we defer full resolution of the
183- // call until upvar inference can kick in and make the
184- // decision. We keep these deferred resolutions grouped by the
185- // def-id of the closure, so that once we decide, we can easily go
186- // back and process them.
187- deferred_call_resolutions : RefCell < DefIdMap < Vec < DeferredCallResolution < ' tcx > > > > ,
188-
189- deferred_cast_checks : RefCell < Vec < cast:: CastCheck < ' tcx > > > ,
190-
191- deferred_generator_interiors : RefCell < Vec < ( hir:: BodyId , Ty < ' tcx > , hir:: GeneratorKind ) > > ,
192-
193- // Opaque types found in explicit return types and their
194- // associated fresh inference variable. Writeback resolves these
195- // variables to get the concrete type, which can be used to
196- // 'de-opaque' OpaqueTypeDecl, after typeck is done with all functions.
197- opaque_types : RefCell < DefIdMap < OpaqueTypeDecl < ' tcx > > > ,
198-
199- /// A map from inference variables created from opaque
200- /// type instantiations (`ty::Infer`) to the actual opaque
201- /// type (`ty::Opaque`). Used during fallback to map unconstrained
202- /// opaque type inference variables to their corresponding
203- /// opaque type.
204- opaque_types_vars : RefCell < FxHashMap < Ty < ' tcx > , Ty < ' tcx > > > ,
205-
206- body_id : Option < hir:: BodyId > ,
207- }
208-
209- impl < ' a , ' tcx > Deref for Inherited < ' a , ' tcx > {
210- type Target = InferCtxt < ' a , ' tcx > ;
211- fn deref ( & self ) -> & Self :: Target {
212- & self . infcx
213- }
214- }
215-
216156/// When type-checking an expression, we propagate downward
217157/// whatever type hint we are able in the form of an `Expectation`.
218158#[ derive( Copy , Clone , Debug ) ]
@@ -489,95 +429,6 @@ impl<'tcx> EnclosingBreakables<'tcx> {
489429 }
490430}
491431
492- /// Helper type of a temporary returned by `Inherited::build(...)`.
493- /// Necessary because we can't write the following bound:
494- /// `F: for<'b, 'tcx> where 'tcx FnOnce(Inherited<'b, 'tcx>)`.
495- pub struct InheritedBuilder < ' tcx > {
496- infcx : infer:: InferCtxtBuilder < ' tcx > ,
497- def_id : LocalDefId ,
498- }
499-
500- impl Inherited < ' _ , ' tcx > {
501- pub fn build ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> InheritedBuilder < ' tcx > {
502- let hir_owner = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) . owner ;
503-
504- InheritedBuilder {
505- infcx : tcx. infer_ctxt ( ) . with_fresh_in_progress_typeck_results ( hir_owner) ,
506- def_id,
507- }
508- }
509- }
510-
511- impl < ' tcx > InheritedBuilder < ' tcx > {
512- pub fn enter < F , R > ( & mut self , f : F ) -> R
513- where
514- F : for < ' a > FnOnce ( Inherited < ' a , ' tcx > ) -> R ,
515- {
516- let def_id = self . def_id ;
517- self . infcx . enter ( |infcx| f ( Inherited :: new ( infcx, def_id) ) )
518- }
519- }
520-
521- impl Inherited < ' a , ' tcx > {
522- fn new ( infcx : InferCtxt < ' a , ' tcx > , def_id : LocalDefId ) -> Self {
523- let tcx = infcx. tcx ;
524- let item_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
525- let body_id = tcx. hir ( ) . maybe_body_owned_by ( item_id) ;
526-
527- Inherited {
528- typeck_results : MaybeInProgressTables {
529- maybe_typeck_results : infcx. in_progress_typeck_results ,
530- } ,
531- infcx,
532- fulfillment_cx : RefCell :: new ( TraitEngine :: new ( tcx) ) ,
533- locals : RefCell :: new ( Default :: default ( ) ) ,
534- deferred_sized_obligations : RefCell :: new ( Vec :: new ( ) ) ,
535- deferred_call_resolutions : RefCell :: new ( Default :: default ( ) ) ,
536- deferred_cast_checks : RefCell :: new ( Vec :: new ( ) ) ,
537- deferred_generator_interiors : RefCell :: new ( Vec :: new ( ) ) ,
538- opaque_types : RefCell :: new ( Default :: default ( ) ) ,
539- opaque_types_vars : RefCell :: new ( Default :: default ( ) ) ,
540- body_id,
541- }
542- }
543-
544- fn register_predicate ( & self , obligation : traits:: PredicateObligation < ' tcx > ) {
545- debug ! ( "register_predicate({:?})" , obligation) ;
546- if obligation. has_escaping_bound_vars ( ) {
547- span_bug ! ( obligation. cause. span, "escaping bound vars in predicate {:?}" , obligation) ;
548- }
549- self . fulfillment_cx . borrow_mut ( ) . register_predicate_obligation ( self , obligation) ;
550- }
551-
552- fn register_predicates < I > ( & self , obligations : I )
553- where
554- I : IntoIterator < Item = traits:: PredicateObligation < ' tcx > > ,
555- {
556- for obligation in obligations {
557- self . register_predicate ( obligation) ;
558- }
559- }
560-
561- fn register_infer_ok_obligations < T > ( & self , infer_ok : InferOk < ' tcx , T > ) -> T {
562- self . register_predicates ( infer_ok. obligations ) ;
563- infer_ok. value
564- }
565-
566- fn normalize_associated_types_in < T > (
567- & self ,
568- span : Span ,
569- body_id : hir:: HirId ,
570- param_env : ty:: ParamEnv < ' tcx > ,
571- value : & T ,
572- ) -> T
573- where
574- T : TypeFoldable < ' tcx > ,
575- {
576- let ok = self . partially_normalize_associated_types_in ( span, body_id, param_env, value) ;
577- self . register_infer_ok_obligations ( ok)
578- }
579- }
580-
581432pub fn check_wf_new ( tcx : TyCtxt < ' _ > ) {
582433 let visit = wfcheck:: CheckTypeWellFormedVisitor :: new ( tcx) ;
583434 tcx. hir ( ) . krate ( ) . par_visit_all_item_likes ( & visit) ;
0 commit comments